Skip to content

feat(xai): add promptCacheKey provider option to the Responses API - #16659

Closed
BrianHung wants to merge 3 commits into
vercel:mainfrom
BrianHung:brian/xai-prompt-cache-key
Closed

BrianHung wants to merge 3 commits into
vercel:mainfrom
BrianHung:brian/xai-prompt-cache-key

Conversation

@BrianHung

@BrianHung BrianHung commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Background

xAI's Responses API accepts a prompt_cache_key field; requests sharing the same key are routed to the same server, increasing prompt cache hits (xAI docs). The xAI documentation already shows providerOptions: { xai: { promptCacheKey } } in its AI SDK example, but the option does not exist in @ai-sdk/xai and is silently dropped.

Summary

Adds a promptCacheKey provider option to the xAI Responses API language model, sent as prompt_cache_key in the request body. Mirrors the existing option on @ai-sdk/openai.

Manual Verification

Ran the built package against the live API with a fetch wrapper recording outgoing requests: the option appeared as prompt_cache_key in the request body, the API accepted it, and repeated calls with the same key reported cached tokens in usage.input_tokens_details.

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

BrianHung added 2 commits July 2, 2026 16:04
xAI's Responses API accepts a prompt_cache_key field that routes requests
with the same key to the same server, maximizing prompt cache hits across
consecutive requests. Expose it as the promptCacheKey provider option,
mirroring the existing option on @ai-sdk/openai.

https://docs.x.ai/developers/advanced-api-usage/prompt-caching/maximizing-cache-hits
@BrianHung
BrianHung marked this pull request as ready for review July 2, 2026 23:25
@gr2m gr2m mentioned this pull request Nov 2, 2026
33 of 34 tasks
@n1ckoates

Copy link
Copy Markdown
Member

Added by #21410, thank you though!

@n1ckoates n1ckoates closed this Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants