GeezerVison is showing github.com — provider: v2 always sends prompt_cache_key to OpenAI-compatible providers; setCacheKey option ignored · Issue #45113 · anomalyco/opencode
provider: v2 always sends prompt_cache_key to OpenAI-compatible providers; setCacheKey option ignored #45113DescriptionSummary
opencode v2 (beta) unconditionally sends prompt_cache_key in Chat Completions requests to all OpenAI-compatible providers. Gateways that strictly validate request fields (e.g. third-party relay/relay-style APIs) reject the request with HTTP 400 (未知请求字段:prompt_cache_key / unknown request field), making every session fail. Additionally, the documented setCacheKey provider option ("Enable promptCacheKey for this provider (default false)") has no runtime effect in v2 — it appears only in the config schema, so there is no way to opt out.
opencode 1.x does not have this problem: it only sets promptCacheKey for specific provider packages (@ai-sdk/deepinfra, @ai-sdk/cerebras, @ai-sdk/openai, @ai-sdk/azure, @ai-sdk/xai, @ai-sdk/mistral, venice-ai-sdk-provider), or when setCacheKey: true is explicitly set. Providers using @ai-sdk/openai-compatible are not affected.
Environment
- opencode version:
opencode2 v0.0.0-beta-18230 (broken) vs opencode 1.18.23 (works)
- OS: Linux 6.18.33.2-microsoft-standard-WSL2 (x64)
- Terminal: tmux (TERM=xterm-256color)
- Shell: zsh
- Install/channel: npm
@opencode-ai/cli (beta)
- Active plugins: [email protected]
Reproduction
- Configure a custom provider in
~/.config/opencode/opencode.jsonc using "npm": "@ai-sdk/openai-compatible" pointing at an OpenAI-compatible gateway that strictly validates fields (in my case a third-party relay service).
- Set
"setCacheKey": false in the provider's options.
- Start any session with one of its models.
The gateway receives a request body containing "prompt_cache_key": "<session-id>" and responds:
HTTP 400
{"code":"UNKNOWN_FIELD","message":"未知请求字段:prompt_cache_key","data":{"field":"prompt_cache_key"}}
Minimal curl proof that the field itself triggers the rejection against this gateway:
# rejected
curl https://<gateway>/v1/chat/completions -d '{"model":"...","messages":[{"role":"user","content":"hi"}],"max_tokens":5,"prompt_cache_key":"test"}'
# → {"code":"UNKNOWN_FIELD","message":"未知请求字段:prompt_cache_key"}
# works
curl https://<gateway>/v1/chat/completions -d '{"model":"...","messages":[{"role":"user","content":"hi"}],"max_tokens":5}'
# → normal completion
Source analysis on the v2 branch:
- The key is attached unconditionally to every session request —
packages/core/src/session/model-request.ts:331:
// TODO: Persist cache lineage so nested forks reuse the root session's cache key.
promptCacheKey: promptCacheKey(session.fork?.sessionID ?? session.id),
- Every OpenAI-chat-compatible route (including custom
openai-compatible providers) lowers it to the wire field — packages/ai/src/protocols/openai-chat.ts:702:
...(cacheKey ? { prompt_cache_key: cacheKey } : {}),
- The only opt-out is
request.cache === "none" — packages/ai/src/protocols/shared.ts:32. Nothing in core ever sets it; only tests do. Notably openai-chat.ts already special-cases non-standard providers for store ("Non-standard providers omit store entirely", line ~701) but not for prompt_cache_key.
setCacheKey has zero consumers on the v2 branch: it appears only in the v1 compat schema (packages/core/src/v1/config/provider.ts:93) and in docs (config.mdx). The per-provider gating logic that v1 had was lost during the request-construction refactors (refactor(core): share session model requests #42680, refactor(core): fold single-consumer request modules into model-request #43958).
Expected Behavior
setCacheKey: false in provider options should suppress prompt_cache_key (the option is still documented in the schema), or be removed from the schema if intentionally dropped. Minimal fix: honor the provider option at model-request.ts:331 by omitting promptCacheKey (or mapping to cache: "none").
- Ideally,
prompt_cache_key should not be sent to generic openai-compatible providers by default (matching v1 behavior), since it is an OpenAI-specific extension that many compatible gateways reject.
Actual Behavior
Every request to the provider fails with HTTP 400 UNKNOWN_FIELD: prompt_cache_key. No configuration can disable it in v2, so affected providers are completely unusable.
Log excerpt:
level=ERROR message="Failed to drain Session"
cause="AI.Error: RequestExecutor.execute: Provider request failed with HTTP 400: 未知请求字段:prompt_cache_key"
Additional Context
Reacted by piknockyou Reacted by ajian Activitymax88578smith commented on Sep 3, 2026 piknockyou commented on Sep 11, 2026 Yes. Nvidia NIM doesn't work now, right? simplestringdev commented on Sep 11, 2026 Confirming this also reproduces against NVIDIA's own official OpenAI-compatible endpoint (https://integrate.api.nvidia.com/v1), not just third-party relays — so this isn't limited to strict/unusual gateways, it breaks against a major vendor's first-party API.
Setup:
"provider": {
"nvidia": {
"npm": "@ai-sdk/openai-compatible",
"env": ["NVIDIA_API_KEY"],
"options": {
"baseURL": "https://integrate.api.nvidia.com/v1",
"setCacheKey": false
}
}
}
opencode run fails immediately:
Error: Validation: Unsupported parameter(s): `prompt_cache_key`
Direct curl against the same endpoint with prompt_cache_key omitted works fine, confirming the field itself is the problem, same as OP's analysis. setCacheKey: false (and removing the option entirely) had no effect either way — consistent with the "zero consumers on v2" finding above.
Version: opencode2 v0.0.0-beta-19425, Linux x64.
Workaround for now: using the built-in opencode/nemotron-3-ultra-free (OpenCode Zen) model instead of a custom NVIDIA provider, since Zen models aren't affected. rekram1-node commented on Oct 5, 2026 FunStudio commented on Nov 1, 2026
9. #49121 (#49121)
Any version 2.0.4 or later has fix.
this bug reappears on version opencode-desktop-win-x64.exe 2.2.5
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|