fix(agent-core): gate prompt_cache_key behind isOfficialOpenAIBaseUrl for third-party endpoints - #2761
Conversation
Third-party OpenAI-compatible providers (NVIDIA NIM, Azure Foundry, etc.) reject the unknown prompt_cache_key parameter with HTTP 400. Add isOfficialOpenAIBaseUrl() guard — only send prompt_cache_key when the base URL targets api.openai.com (or a *.api.openai.com variant), matching the existing fix in agent-core-v2.
🦋 Changeset detectedLatest commit: 601e041 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e430cb316b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // `metadata.user_id` above). Only sent to official OpenAI API | ||
| // endpoints — strictly-validating OpenAI-compatible third-party | ||
| // endpoints (NVIDIA, Azure Foundry, etc.) reject unknown parameters. | ||
| ...(promptCacheKey !== undefined && isOfficialOpenAIBaseUrl( |
There was a problem hiding this comment.
Add a changeset for this provider fix
This is a user-visible provider behavior change, but the commit only changes provider-manager.ts and adds no .changeset/ entry, so changeset-based release/version notes can omit the third-party endpoint fix. Add an appropriate changeset before this PR is submitted.
AGENTS.md reference: AGENTS.md:L84-L85
Useful? React with 👍 / 👎.
Problem
Since
prompt_cache_keywas introduced for session cache affinity, Kimi Code CLI sends this parameter to all OpenAI-compatible providers — not just to official OpenAI endpoints. Third-party APIs that strictly validate request parameters reject it with HTTP 400, making providers like NVIDIA NIM and Azure Foundry unusable.400 Validation: Unsupported parameter(s): prompt_cache_key400 Unrecognized request argument supplied: prompt_cache_keyBoth issues remain open because the legacy engine (
packages/agent-core) lacks the guard thatagent-core-v2already has.Root cause
packages/agent-core/src/session/provider-manager.tsunconditionally injectedprompt_cache_keyintogenerationKwargsfor everyopenaiandopenai_responsesprovider configuration, regardless of the actual target base URL:The
agent-core-v2engine already solved this viaisOfficialOpenAIBaseUrl()—prompt_cache_keyis only sent when the hostname targetsapi.openai.comor a regional*.api.openai.comvariant. Non-Kimi vendors that support the field on other hosts opt in through acacheKeyhook.Changes
packages/agent-core/src/session/provider-manager.ts(1 file, +34 / −5):isOfficialOpenAIBaseUrl()helper — same logic as the v2 implementationopenaicase: gatedprompt_cache_keybehindisOfficialOpenAIBaseUrlopenai_responsescase: same gatingkimicase: unchanged — Kimi API always acceptsprompt_cache_keygenerationKwargsis now entirely omitted whenpromptCacheKeyisundefined, instead of sendingprompt_cache_key: undefinedon the wireBehaviour after fix
prompt_cache_keysent?https://api.openai.com/v1(default)https://api.moonshot.cn/v1https://integrate.api.nvidia.com/v1https://{resource}.openai.azure.com/v1Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.