kimi-code icon indicating copy to clipboard operation
kimi-code copied to clipboard

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

Open B143KC47 opened this issue 4 months ago • 3 comments

Related Issue

Resolve #2166

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) reject the unknown parameter with 400 Unsupported parameter(s): prompt_cache_key, which makes custom openai / openai_responses providers unusable.

What changed

The field is now only sent when the effective base URL targets the official OpenAI API (api.openai.com or a regional variant like eu.api.openai.com, or no base URL, which the client defaults there):

  • v1 engine: toKosongProviderConfig gates prompt_cache_key in both the openai and openai_responses branches on a new isOfficialOpenAIBaseUrl helper. The kimi branch is intentionally untouched — Kimi endpoints support the field.
  • v2 engine (kimi web / experimental print mode): the same gate on the bare fallback in the OpenAI chat-completions and Responses bases. Vendors that support the field keep encoding it through their cacheKey trait hook (e.g. Kimi), which is unaffected.

This restores pre-0.29.0 behavior for custom endpoints while preserving #1970's cache-affinity intent for the official API. Trade-off, stated explicitly: OpenAI-compatible gateways on custom base URLs that do accept prompt_cache_key lose cache affinity again — exactly the pre-0.29.0 behavior; a per-provider opt-in flag could cover them as a follow-up if wanted.

Tests: runtime-provider.test.ts gains custom-endpoint (omitted) and official-endpoint (kept) cases for both provider types; composition.test.ts gains the same probes on the v2 wire. All four fail without the fix.

Checklist

  • [x] I have read the CONTRIBUTING document.
  • [x] I have linked a related issue, or explained the problem above.
  • [x] I have added tests that prove my feature works.
  • [x] Ran gen-changesets skill, or this PR needs no changeset.
  • [x] Ran gen-docs skill, or this PR needs no doc update.

B143KC47 avatar Jul 26 '26 09:07 B143KC47

🦋 Changeset detected

Latest commit: 8e8f60155b24ad2293120b25958d49e296c62434

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

changeset-bot[bot] avatar Jul 26 '26 09:07 changeset-bot[bot]

@codex review — the comment-convention findings are addressed in 0f89f116 (commentary moved into the module headers).

B143KC47 avatar Jul 26 '26 10:07 B143KC47

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 0f89f116de

ℹ️ 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".

I would love to see this merged. I can't use Azure without it.

TaylorTWBrown avatar Sep 06 '26 17:09 TaylorTWBrown