GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #45113

New issue
Copy link
New issue
Copy link
Closed
Closed
provider: v2 always sends prompt_cache_key to OpenAI-compatible providers; setCacheKey option ignored#45113
Copy link
Assignees
kitlangton
Labels
2.0

Description

@gnh1996
gnh1996
opened on Aug 26, 2026
Issue body actions

Summary

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

  1. 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).
  2. Set "setCacheKey": false in the provider's options.
  3. 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:

  1. 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),
  2. 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 } : {}),
  3. 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.
  4. 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

  1. 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").
  2. 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

  • Frequency: 100% reproducible with the affected provider on every v2 release I tested; 0% on opencode 1.18.23 with identical config.
  • Current workaround: none within v2 (config option is inert). Rolling back to opencode 1.x restores access.
  • Related issues: setCacheKey sends promptCacheKey (wrong) instead of cache_control on content blocks for openai-compatible Bedrock proxies (Bifrost, LiteLLM) #25984 (setCacheKey sends the wrong cache format for openai-compatible Bedrock proxies), V2 drops prompt cache affinity for OpenRouter and OpenAI Chat #42246 (V2 drops prompt cache affinity for OpenRouter/OpenAI Chat) — together these suggest the v2 request-construction rewrite lost v1's per-provider cache-key gating in both directions. Same failure class has been reported against other gateways, e.g. strict relays rejecting prompt_cache_key with HTTP 400.
  • Suggestion for other gateway vendors would be to ignore unknown fields like the official OpenAI API does, but opencode should honor its own documented opt-out regardless.
Reacted by piknockyou
Reacted by ajian

Activity

  1. github-actions
    assigned
    kitlangton
    on Aug 26, 2026
  2. opencode-agent
    added
    2.0
    on Aug 26, 2026
  3. max88578smith commented on Sep 3, 2026

    @max88578smith
    max88578smith
    on Sep 3, 2026
    More actions

    @gnh1996 strip-cache-key__plugin_v2.zip

    Same issue: This seems to help me in the meantime

    Reacted by piknockyou
  4. piknockyou commented on Sep 11, 2026

    @piknockyou
    piknockyou
    on Sep 11, 2026
    More actions

    Yes. Nvidia NIM doesn't work now, right?

  5. simplestringdev commented on Sep 11, 2026

    @simplestringdev
    simplestringdev
    on Sep 11, 2026
    More actions

    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.

    Reacted by piknockyou
  6. rekram1-node commented on Oct 5, 2026

    @rekram1-node
    rekram1-node
    on Oct 5, 2026
    Member
    More actions

    #49121 (#49121)

    Any version 2.0.4 or later has fix.

  7. rekram1-node
    closed this as completedon Oct 5, 2026
  8. FunStudio commented on Nov 1, 2026

    @FunStudio
    FunStudio
    on Nov 1, 2026
    More actions

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @kitlangton
    kitlangton

Labels

2.0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.