Skip to content

The Claude model cannot properly enable the caching function #11083

@tisoz

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingwindows

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions