Skip to content

The Claude model cannot properly enable the caching function #11083

Closed as not planned

Description

@tisoz

Description

"npm": "@ai-sdk/anthropic",
"name": "test-claude",
"options": {
    "baseURL": "https://code.newcli.com/claude/aws/v1",
    "apiKey": "sk-ant-oat01-Vla5Fe6Fg-G_M2zd4sgDJvvLkz7q_f2dOHDqHBdHcNmdSApijjHB4b-xxx",
    "setCacheKey": true
},

I have configured a third-party model for testing
and through testing . i found problem .
in opencode the claude request not enable metadata.userid

{
    "model": "claude-sonnet-4-5-20250929",
    "max_tokens": 64000,
    "system": [
        {
            "type": "text",
            "text": "xxx",
            "cache_control": {
                "type": "ephemeral"
            }
        }
    ],
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "hi",
                    "cache_control": {
                        "type": "ephemeral"
                    }
                }
            ]
        }
    ],
    "metadata": {
        "user_id": "user_9f76af04f457a811f11a4d4c36986076c434db17d2d71d1abc8ac06bfb344ea3_account__session_3d44c07c-405f-4ae8-b6ec-fa28c5b91c45"
    },
    "tool_choice": {
        "type": "auto"
    },
    "stream": true
}

when i take this params , cache be work .
i noticed one issue
#8138

but it's be closed , so should i can do , can we enable other params to enable cache fetures

Plugins

none

OpenCode version

1.1.40

Steps to reproduce

  1. add a provider in opencode.json
        "test-claude": {
            "npm": "@ai-sdk/anthropic",
            "name": "test-claude",
            "options": {
                "baseURL": "https://code.newcli.com/claude/aws/v1",
                "apiKey": "sk-ant-oat01-Vla5Fe6Fg-xxx",
                "setCacheKey": true
            },
            "models": {
                "claude-sonnet-4-5-20250929": {
                    "name": "claude-sonnet-4-5-20250929",
                    "thinking": true
                }
            }
        }
  1. if you need i will send you private message for the key
  2. test it in claude cli and opencode cli to compare

Screenshot and/or share link

Image

Operating System

WINDOWS 11

Terminal

terminal

Activity

  1. RicardoMonteiroSimoes commented on Jan 29, 2026

    @RicardoMonteiroSimoes

    Not sure of the format of anthropic api keys, but your first one seems rather exposing, just a small FYI

  2. tisoz commented on Jan 29, 2026

    @tisoz
    Author

    Not sure of the format of anthropic api keys, but your first one seems rather exposing, just a small FYI不清楚 Anthropic API 密钥的具体格式,但您的第一个密钥似乎有些暴露,只是提醒一下

    it's be ok , i already deal it

  3. 70akaline commented on Feb 1, 2026

    @70akaline

    could we accelerate this fix pr merge procees?

    #11276

  4. tisoz commented on Feb 1, 2026

    @tisoz
    Author

    could we accelerate this fix pr merge procees?

    #11276

    https://www.npmjs.com/package/opencode-windows-fixed-cache?activeTab=readme

    you can use it before the release

  5. Starlight0798 commented on Feb 19, 2026

    @Starlight0798

    @tisoz 佬要不试试写一个opencode插件来修吧,好像用插件就不用直接修改本体代码了,蹲一个

  6. tisoz commented on Feb 22, 2026

    @tisoz
    Author

    @tisoz 佬要不试试写一个opencode插件来修吧,好像用插件就不用直接修改本体代码了,蹲一个

    他们插件文档有点乱,各种函数没有案例和讲解,搞不动

  7. xiguadong commented on Mar 23, 2026

    @xiguadong

    @tisoz 请问下 foxcode 的 claude 现在还能在 opencode中用吗?尝试过官渠和 super/ultra,配置了多种都用不了;

  8. tisoz commented on Mar 26, 2026

    @tisoz
    Author

    @tisoz 请问下 foxcode 的 claude 现在还能在 opencode中用吗?尝试过官渠和 super/ultra,配置了多种都用不了;

    目前没有用他们家了,除了max不能在opencode中使用,其他渠道理论上都可以。

  9. gfrid commented on Apr 20, 2026

    @gfrid

    maybe its related but i used SKILLS with strands and Prompt caching and it seems not to work also, but i have not done enough test to verify for now.

  10. assigned and unassigned on Apr 26, 2026
  11. KTS-o7 commented on May 10, 2026

    @KTS-o7

    This is likely the same root cause as #25984 — when using @ai-sdk/openai-compatible (or @ai-sdk/anthropic with a custom baseURL pointing to a proxy), setCacheKey: true sends promptCacheKey as a top-level request option, which proxies like Bifrost, LiteLLM, and Databricks don't recognise. They require cache_control: { type: "ephemeral" } injected directly onto individual message content blocks.

    PR #25985 fixes this by adding a cacheStrategy: "bedrock" option for @ai-sdk/openai-compatible providers that injects cache_control on content blocks the way these proxies expect. It also auto-triggers when setCacheKey: true is set and the model ID contains bedrock/.

    Leaving this here in case it unblocks anyone still hitting this — and in hopes of nudging a maintainer review since this issue has been open a while.

  12. 776A0A commented on May 19, 2026

    @776A0A

    Why is this still unresolved?

    This is a serious cost issue for anyone using Claude through third-party Anthropic-compatible providers. Without a stable metadata.user_id, prompt caching may silently fail: cache_creation_input_tokens keeps increasing, while cache_read_input_tokens remains 0. In practice this can make usage cost more than 10x higher.

    I verified the workaround described here. A small local proxy that injects the following field into the request body fixes the problem immediately:

    {
    "metadata": {
    "user_id": "xxx"
    }
    }

    After adding a stable metadata.user_id, cache reads started working again.

    Please add an official config option to pass through or generate a stable metadata.user_id for Anthropic-compatible providers. This should not require every user to run a local proxy to avoid massive unexpected costs.

  13. KTS-o7 commented on May 19, 2026

    @KTS-o7

    It is still unresolved

  14. github-actions commented on Jul 19, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions