Skip to content

fix(agent-core): only send prompt_cache_key to official OpenAI endpoints - #2240

Open
creatiVision wants to merge 4 commits into
MoonshotAI:mainfrom
creatiVision:fix/latest-with-prompt-cache
Open

fix(agent-core): only send prompt_cache_key to official OpenAI endpoints#2240
creatiVision wants to merge 4 commits into
MoonshotAI:mainfrom
creatiVision:fix/latest-with-prompt-cache

Conversation

@creatiVision

Copy link
Copy Markdown

Related Issue

Tracking / backup of #2203 (original by @B143KC47).
Resolve #2166

If #2203 is merged first, this PR can be closed with no further action.

Problem

Since v0.29.0 (#1970), every OpenAI-compatible provider receives the session prompt_cache_key in the request body. Strictly-validating endpoints (e.g. NVIDIA NIM at integrate.api.nvidia.com) reject the unknown parameter with:

400 Validation: Unsupported parameter(s): `prompt_cache_key`

That makes custom openai / openai_responses providers unusable for agent sessions.

What changed

Same fix as #2203, rebased onto current main:

  • Only send prompt_cache_key when the effective base URL targets the official OpenAI API (api.openai.com or *.api.openai.com, or unset → client default).
  • v1: gate in toKosongProviderConfig for openai and openai_responses (isOfficialOpenAIBaseUrl).
  • v2: same gate on the bare cacheKeyprompt_cache_key fallback in OpenAI chat-completions and Responses bases.
  • Kimi protocol branch untouched (Kimi endpoints support the field).
  • Tests: custom endpoint omits the field; official endpoint keeps it.

Checklist

Note

This is a tracking/backup PR so the fix stays visible on the creatiVision fork if #2203 stalls. Prefer merging #2203 if it is ready; maintainers should not need both.

B143KC47 added 3 commits July 27, 2026 10:22
…dpoint

Since 0.29.0 every OpenAI-compatible provider received the session
prompt_cache_key in the request body. Strictly-validating endpoints
reject the unknown parameter with a 400, breaking custom providers.

Gate the field on the effective base URL targeting api.openai.com (or
being unset, which the client defaults there), in both the v1 provider
config resolution and the v2 OpenAI chat-completions/responses bases.
Vendors that support the field (e.g. Kimi) keep encoding it through
their own branch or cacheKey trait hook.

Fixes MoonshotAI#2166
…pt cache affinity

Data-residency endpoints (eu.api.openai.com, us.api.openai.com) are
official OpenAI hosts and accept prompt_cache_key; match any
*.api.openai.com hostname instead of the apex only.
The package convention allows comments only in the top-of-file block;
move the prompt_cache_key gating notes there.
@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d4510ec

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

@creatiVision creatiVision mentioned this pull request Jul 27, 2026
5 tasks
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.

Error with models not supporting prompt cache

2 participants