Skip to content

V1→V2 migration silently drops prompt caching for OpenAI-compatible Claude endpoints #65400

In review

Description

@ned9

Description

A V1 config that served Claude through an OpenAI-compatible endpoint got cache_control breakpoints. On V2 the same config sends none, so every turn bills as uncached input, with no warning.

migrate-v1 says supported V1 behaviour that stops working in V2 is a compatibility bug, and lists the intentional breaks under Accepted but unsupported fields. Prompt caching isn't among them.

The removal was deliberate: V1 placed markers whenever the model id contained claude (transform.ts); V2 only marks routes in RESPECTS_INLINE_HINTS, which excludes openai-compatible-chat (cache-policy.ts). compatibility.cacheFormat is the documented opt-in (#54945), but migrate.ts never infers it, though it already rewrites the adjacent setCacheKey → supportsPromptCacheKey.

Expected: the migration infers cacheFormat: "anthropic" for models that matched the V1 heuristic, or warns that caching was dropped. migrate-v1 currently documents setCacheKey and the cache-cost rename, not cacheFormat.

OpenCode version

1.19.6 (opencode-ai) → 2.3.2 (@opencode/cli). The opt-in landed in 2.0.28.

Steps to reproduce

{
  "provider": {
    "gateway": {
      "npm": "@ai-sdk/openai-compatible",
      "options": { "baseURL": "http://127.0.0.1:8787/v1" },
      "models": { "claude-sonnet-5-5": { "id": "claude-sonnet-5-5" } }
    }
  }
}

Point baseURL at a proxy that logs request bodies, then run opencode run hi -m gateway/claude-sonnet-5-5:

  • 1.19.6: cache_control on /messages/0, /messages/1, /messages/2
  • 2.3.2: no cache_control anywhere

Adding "compatibility": { "cacheFormat": "anthropic" } doesn't fix it in the V1 provider block — that schema has no compatibility field, so the key is dropped silently. It only works after rewriting the block to the V2 providers shape.

Operating System

macOS 15 (arm64)

Activity

  1. added
    area/providers
    type/bug
    version/v2
    on Nov 21, 2026
  2. opencodejr commented on Nov 21, 2026

    @opencodejr
    Contributor

    Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.

    Thanks for the detailed report. I reproduced this on 2.3.2 and it still happens on the latest dev (ba5bbef).

    I ran the released CLI against a local mock OpenAI-compatible server that only logs request bodies and sends back a short reply. The mock stood in for your proxy; what's being checked is what OpenCode sends. Then I ran opencode run hi -m gateway/claude-sonnet-5-5 with your config and counted cache_control in the logged requests:

    • 1.19.6, your V1 provider block: 5 markers
    • 2.3.2 and dev, your V1 provider block: 0
    • 2.3.2 and dev, same block with compatibility.cacheFormat: "anthropic" added: still 0, so the key is dropped silently
    • 2.3.2 and dev, block rewritten to the V2 providers shape with cacheFormat: 6

    So the opt-in itself works, but migrating a V1 config loses caching without a warning. The script below reproduces it.

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Reproduces #65400: a V1-style `provider` block for Claude via @ai-sdk/openai-compatible
    # sends no cache_control on V2. A mock OpenAI-compatible server logs request bodies.
    # Usage: ./repro.sh [opencode command...]   (default: opencode)
    set -u
    OC=("${@:-opencode}")
    WORK=$(mktemp -d /tmp/opencode/repro65400.XXXX)
    LOG="$WORK/bodies.jsonl"
    cat > "$WORK/server.ts" <<'TS'
    const log = process.env.LOG!
    Bun.serve({ port: 8787, async fetch(req) {
      const body = await req.text()
      await Bun.write(Bun.file(log), (await Bun.file(log).exists() ? await Bun.file(log).text() : "") + body + "\n")
      const chunk = (d: any) => `data: ${JSON.stringify(d)}\n\n`
      const base = { id: "x", object: "chat.completion.chunk", created: 0, model: "claude-sonnet-5-5" }
      const sse = chunk({ ...base, choices: [{ index: 0, delta: { role: "assistant", content: "hello" }, finish_reason: null }] })
        + chunk({ ...base, choices: [{ index: 0, delta: {}, finish_reason: "stop" }], usage: { prompt_tokens: 10, completion_tokens: 1, total_tokens: 11 } })
        + "data: [DONE]\n\n"
      return new Response(sse, { headers: { "content-type": "text/event-stream" } })
    }})
    TS
    LOG="$LOG" bun "$WORK/server.ts" & SRV=$!
    trap 'kill $SRV 2>/dev/null' EXIT
    sleep 1
    mkdir -p "$WORK/project" && cd "$WORK/project" && git init -q
    run() { # $1 = label, config in opencode.json
      : > "$LOG"
      OPENCODE_CONFIG_DIR="$WORK/cfg" XDG_CONFIG_HOME="$WORK/xdg" XDG_DATA_HOME="$WORK/data" \
        timeout 90 "${OC[@]}" run hi -m gateway/claude-sonnet-5-5 > "$WORK/out.txt" 2>&1
      echo "== $1: exit $? ; output: $(tail -c 300 "$WORK/out.txt" | tr '\n' ' ')"
      echo "   requests: $(grep -c . "$LOG"), cache_control occurrences: $(grep -o cache_control "$LOG" | wc -l)"
    }
    cat > opencode.json <<'J'
    { "provider": { "gateway": { "npm": "@ai-sdk/openai-compatible",
        "options": { "baseURL": "http://127.0.0.1:8787/v1", "apiKey": "x" },
        "models": { "claude-sonnet-5-5": { "id": "claude-sonnet-5-5" } } } } }
    J
    run "V1 provider block"
    cat > opencode.json <<'J'
    { "provider": { "gateway": { "npm": "@ai-sdk/openai-compatible",
        "options": { "baseURL": "http://127.0.0.1:8787/v1", "apiKey": "x" },
        "compatibility": { "cacheFormat": "anthropic" },
        "models": { "claude-sonnet-5-5": { "id": "claude-sonnet-5-5" } } } } }
    J
    run "V1 provider block + compatibility.cacheFormat"
    cat > opencode.json <<'J'
    { "providers": { "gateway": { "package": "aisdk:@ai-sdk/openai-compatible",
        "settings": { "baseURL": "http://127.0.0.1:8787/v1", "apiKey": "x" },
        "compatibility": { "cacheFormat": "anthropic" },
        "models": { "claude-sonnet-5-5": { "id": "claude-sonnet-5-5" } } } } }
    J
    run "V2 providers block + compatibility.cacheFormat (control)"

    Run it: bash repro.sh

  3. added
    status/repro-simulated
    on Nov 21, 2026
  4. DZH166 commented on Nov 21, 2026

    @DZH166

    Confirmed — the migration keeps setCacheKey but never carries over the V1 claude-id cache heuristic, so an OpenAI-compatible Claude provider loses its cache markers and every turn bills as uncached input. Preparing a PR that infers compatibility.cacheFormat: "anthropic" for those models during migration.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/providersplatform/macosstatus/repro-simulatedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions