Skip to content

xAI requests missing prompt cache routing identifier (x-grok-conv-id / prompt_cache_key) #35033

Description

@BrianHung

Description

xAI caches prompts automatically, but each server keeps its own cache. For a session to benefit, every request needs a stable conversation identifier so the API can route it to the server that holds the session's cache. The identifier is the x-grok-conv-id header, or the prompt_cache_key body field for the Responses API. See the xAI prompt caching docs.

opencode sends neither for xai models:

  • ProviderTransform.options sets promptCacheKey only for the openai, azure, venice, openrouter, and opencode gpt-5 providers
  • Setting it for xai would not help on its own. @ai-sdk/xai has no promptCacheKey option, and its Responses options schema removes unknown keys, so the value never reaches the request body. Verified through version 4.0.6
  • No code path sets x-grok-conv-id

As a result, xai sessions hit the cache only when load balancing happens to return them to the same server. Cached tokens are billed at a reduced rate and return faster, so every miss adds cost and latency.

Plugins

None

OpenCode version

dev (current)

Steps to reproduce

  1. Configure the xai provider with an API key and run any prompt against an xai model
  2. Capture the outgoing request, for example by pointing provider.xai.options.baseURL at a local logging proxy
  3. The /v1/responses request has no x-grok-conv-id header and no prompt_cache_key body field

Screenshot and/or share link

A request captured through a logging proxy shows both identifiers absent on xai /v1/responses requests.

Operating System

macOS (applies to all platforms)

Terminal

Any

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions