You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(kimi): forward prompt_cache_key on the Kimi Coding Plan presets (#597)
* feat(kimi): forward prompt_cache_key on the Kimi Coding Plan presets
Kimi's Chat Completions API documents prompt_cache_key as required for
Kimi Code Plan cache hits (a stable session/task id, unchanged across
exit and resume). Opt the canonical `kimi` OAuth and `kimi-code`
API-key presets into the existing openai-chat forwarding flag so the
caller-supplied key reaches https://api.kimi.com/coding/v1.
The adapter never invents a key: it forwards what the internal request
already carries (Codex's session key on /v1/responses, or the
session-scoped key the Claude /v1/messages inbound derives), an absent
field stays absent, and an explicit provider-level
`promptCacheKey: false` still opts out. All other OpenAI-compatible
presets remain deny-by-default because strict backends reject the
OpenAI-specific field.
Also persist the flag through providerConfigSeed /
enrichProviderFromRegistry like the sibling scalars
(parallelToolCalls, modelSuffixBracketStrip): key-pool 429 rotation
rebuilds the provider from the persisted config rather than the routed
one, so without seeding the retried request would silently drop the
key on exactly the quota-sensitive turns that need affinity most.
Evidence: https://platform.kimi.com/docs/api/chat
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Preserve Kimi prompt cache key on failover
* fix(server): inherit routed provider config across 429 key rotation
Generalize the promptCacheKey preservation from the previous commit: the
narrow registry backfill in rotateProviderTransportOn429 covered only that
one scalar, while every OTHER registry backfill routedProviderConfig merges
at request time was still lost when the four 429-failover sites in
src/server/responses/core.ts assigned the persisted-config snapshot to
route.provider wholesale. Concretely: kimi-code's noTemperatureModels /
modelReasoningEfforts / modelSuffixBracketStrip merges, NVIDIA NIM's
parallelToolCalls: false, and a registry-pinned baseUrl all silently
reverted on the rotated retry and later continuations in the turn.
rotateProviderTransportOn429 now takes the request's routed provider and
swaps ONLY the API key onto it before re-applying transport metadata,
mirroring the OAuth-401 replay path (which already spreads route.provider).
The registry lookup becomes unnecessary and is removed. Other failover
paths were audited and are sound: Codex multi-account retry strips runtime
fields off route.provider, and the Anthropic account pool spreads
route.provider directly.
Regression coverage: the existing Kimi unit test keeps asserting the wire
body on both attempts; a new unit test proves arbitrary registry-backfilled
fields survive rotation; a new e2e test on the kimi-code preset asserts
prompt_cache_key is present on BOTH the initial attempt and the
post-rotation retry (verified to fail against the pre-fix behavior).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs-site/src/content/docs/guides/providers.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,6 +90,13 @@ ocx logout <provider>
90
90
|`cursor`|`cursor`|`https://api2.cursor.sh`| Experimental PKCE login, live HTTP/2 transport, and account-filtered model discovery. |
91
91
|`github-copilot`|`openai-chat`|`https://api.githubcopilot.com`| Experimental. GitHub device flow + `copilot_internal` exchange (VS Code OAuth client). Requires an active Copilot subscription; not an official third-party API. |
92
92
93
+
For the canonical Kimi Coding Plan presets (`kimi` account login and `kimi-code` API key),
94
+
opencodex forwards only a caller-supplied stable `prompt_cache_key` to the Chat Completions request;
95
+
it never generates one. Kimi documents a stable session/task key as required to improve Code Plan
96
+
cache hit rates, while requests without a key remain keyless. If an opted-in upstream rejects the
97
+
field, opencodex does not strip it and retry or mutate saved configuration. Other providers remain
98
+
deny-by-default.
99
+
93
100
You can also start OAuth from the [web dashboard](/guides/web-dashboard/).
Copy file name to clipboardExpand all lines: docs-site/src/content/docs/ru/guides/providers.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,6 +93,13 @@ ocx logout <provider>
93
93
|`cursor`|`cursor`|`https://api2.cursor.sh`| Экспериментальный PKCE-вход, живой транспорт HTTP/2 и обнаружение моделей с фильтрацией по аккаунту. |
94
94
|`github-copilot`|`openai-chat`|`https://api.githubcopilot.com`| Экспериментально. Device flow GitHub + обмен `copilot_internal` (OAuth-клиент VS Code). Требуется активная подписка Copilot; это не официальный сторонний API. |
95
95
96
+
Для канонических пресетов Kimi Coding Plan (вход через аккаунт `kimi` и API-ключ `kimi-code`)
97
+
opencodex передаёт в запрос Chat Completions только стабильный `prompt_cache_key`, предоставленный
98
+
вызывающей стороной, и никогда не создаёт его сам. Документация Kimi требует стабильный ключ
99
+
сессии/задачи для повышения доли попаданий в кэш Code Plan; запрос без ключа остаётся без ключа.
100
+
Если включённый провайдер отклоняет поле, opencodex не удаляет его для повторной попытки и не
101
+
изменяет сохранённую конфигурацию. Для остальных провайдеров действует deny-by-default.
102
+
96
103
OAuth можно запустить и из [веб-дашборда](/ru/guides/web-dashboard/).
0 commit comments