Repository navigation
Conversation
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
3 of 6 tasks
BrianHung
marked this pull request as ready for review
July 2, 2026 23:25
33 of 34 tasks
Member
|
Added by #21410, thank you though! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
xAI's Responses API accepts a
prompt_cache_keyfield; requests sharing the same key are routed to the same server, increasing prompt cache hits (xAI docs). The xAI documentation already showsproviderOptions: { xai: { promptCacheKey } }in its AI SDK example, but the option does not exist in@ai-sdk/xaiand is silently dropped.Summary
Adds a
promptCacheKeyprovider option to the xAI Responses API language model, sent asprompt_cache_keyin 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_keyin the request body, the API accepted it, and repeated calls with the same key reported cached tokens inusage.input_tokens_details.Checklist
pnpm changesetin the project root)