Anthropic provider in AI-SDK overwrites anthropic-beta headers. #3139

Closed
opened 2026-02-16 17:38:49 -05:00 by yindo · 7 comments
Owner

Originally created by @joachim-isaksson on GitHub (Nov 26, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

When passing in beta headers, the AI SDK version ("@ai-sdk/anthropic": "2.0.45" currently) ignores and overwrites them before actually sending them to Anthropic.

This seems to be fixed in @ai-sdk/anthropic@2.0.49 "Retain user-supplied betas." so a rollup of the version should solve it.

OpenCode version

v1.0.115

Steps to reproduce

Add "headers": {"anthropic-beta": "context-1m-2025-08-07,interleaved-thinking-2025-05-14"}" to the model config, the header is never sent.

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @joachim-isaksson on GitHub (Nov 26, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description When passing in beta headers, the AI SDK version ("@ai-sdk/anthropic": "2.0.45" currently) ignores and overwrites them before actually sending them to Anthropic. This seems to be fixed in [@ai-sdk/anthropic@2.0.49](https://github.com/vercel/ai/releases/tag/%40ai-sdk%2Fanthropic%402.0.49) "Retain user-supplied betas." so a rollup of the version _should_ solve it. ### OpenCode version v1.0.115 ### Steps to reproduce Add "headers": {"anthropic-beta": "context-1m-2025-08-07,interleaved-thinking-2025-05-14"}" to the model config, the header is never sent. ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the bug label 2026-02-16 17:38:49 -05:00
yindo closed this issue 2026-02-16 17:38:49 -05:00
Author
Owner

@joachim-isaksson commented on GitHub (Nov 26, 2025):

I'd add a PR, but my knowledge in dependency management in typescript is most likely just enough to break things.

@joachim-isaksson commented on GitHub (Nov 26, 2025): I'd add a PR, but my knowledge in dependency management in typescript is most likely just enough to break things.
Author
Owner

@crayment commented on GitHub (Nov 26, 2025):

I'm also adding that beta header and noticing issues where my sessions all blow up right around the 200k token limit, so something isn't working right.
From my config:

"provider": {
    "anthropic": {
      "options": {
        "headers": {
          "anthropic-beta": "context-1m-2025-08-07,claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14"
        }
      },
      "models": {
        "claude-sonnet-4-5": {
          "limit": {
            "context": 1000000,
            "output": 8192
          }
        },
        "claude-sonnet-4-5-20250929": {
          "limit": {
            "context": 1000000,
            "output": 64000
          }
        }
      }
    }
  },
@crayment commented on GitHub (Nov 26, 2025): I'm also adding that beta header and noticing issues where my sessions all blow up right around the 200k token limit, so something isn't working right. From my config: ```json "provider": { "anthropic": { "options": { "headers": { "anthropic-beta": "context-1m-2025-08-07,claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14" } }, "models": { "claude-sonnet-4-5": { "limit": { "context": 1000000, "output": 8192 } }, "claude-sonnet-4-5-20250929": { "limit": { "context": 1000000, "output": 64000 } } } } }, ```
Author
Owner

@rekram1-node commented on GitHub (Nov 26, 2025):

what plans are you on, you need tier 4 or custom usage limits for anthropic to use this I thought

@rekram1-node commented on GitHub (Nov 26, 2025): what plans are you on, you need tier 4 or custom usage limits for anthropic to use this I thought
Author
Owner

@joachim-isaksson commented on GitHub (Nov 27, 2025):

To eliminate plans from the bug report, let's use pdf beta instead, pdfs-2024-09-25;

 "claude-sonnet-4-5": {
    "options": {
      "thinking": {
        "type": "enabled",
        "budgetTokens": 65536
      }
    },
    "headers": {
      "anthropic-beta": "pdfs-2024-09-25",
      "test-header": "2"
    }
  },

Using the model, this is the (keys redacted) actual header that goes to anthropic;

Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
anthropic-beta: oauth-2025-04-20,claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14
anthropic-version: 2023-06-01
authorization: Bearer ****
Connection: keep-alive
Content-Length: 138229
content-type: application/json
Host: api.anthropic.com
test-header: 2
user-agent: ai-sdk/anthropic/2.0.45 ai-sdk/provider-utils/3.0.17 runtime/bun/1.3.3

Note that the test-header goes through just fine, while the anthropic-beta header is wholesale replaced by the AI SDK.

The version I linked above should instead merge the AI SDK provided anthropic-beta headers with the user provided ones and happily send pdfs-2024-09-25 along too.

@joachim-isaksson commented on GitHub (Nov 27, 2025): To eliminate plans from the bug report, let's use pdf beta instead, **pdfs-2024-09-25**; ``` "claude-sonnet-4-5": { "options": { "thinking": { "type": "enabled", "budgetTokens": 65536 } }, "headers": { "anthropic-beta": "pdfs-2024-09-25", "test-header": "2" } }, ``` Using the model, this is the (keys redacted) actual header that goes to anthropic; ``` Accept: */* Accept-Encoding: gzip, deflate, br, zstd anthropic-beta: oauth-2025-04-20,claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14 anthropic-version: 2023-06-01 authorization: Bearer **** Connection: keep-alive Content-Length: 138229 content-type: application/json Host: api.anthropic.com test-header: 2 user-agent: ai-sdk/anthropic/2.0.45 ai-sdk/provider-utils/3.0.17 runtime/bun/1.3.3 ``` Note that the test-header goes through just fine, while the anthropic-beta header is wholesale replaced by the AI SDK. The version I linked above should instead merge the AI SDK provided anthropic-beta headers with the user provided ones and happily send pdfs-2024-09-25 along too.
Author
Owner

@crayment commented on GitHub (Nov 27, 2025):

My issue was I needed to login via API key - NOT via the "Claude Pro/Max" option.

@crayment commented on GitHub (Nov 27, 2025): My issue was I needed to login via API key - NOT via the "Claude Pro/Max" option.
Author
Owner

@joachim-isaksson commented on GitHub (Nov 30, 2025):

The dependency mentioned above has been updated, but the header is hard coded as shown below in opencode-anhtropic-auth so it's still locked down.

"anthropic-beta":
    "oauth-2025-04-20,claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",

Made a stab at a PR to fix it; (https://github.com/sst/opencode-anthropic-auth/pull/4); which allows the beta headers to finally work.

@joachim-isaksson commented on GitHub (Nov 30, 2025): The dependency mentioned above has been updated, but the header is hard coded as shown below in opencode-anhtropic-auth so it's still locked down. ``` "anthropic-beta": "oauth-2025-04-20,claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14", ``` Made a stab at a PR to fix it; (https://github.com/sst/opencode-anthropic-auth/pull/4); which allows the beta headers to finally work.
Author
Owner

@rekram1-node commented on GitHub (Nov 30, 2025):

fixed in next release thanks to @joachim-isaksson

fix in opencode: https://github.com/sst/opencode/commit/0308b2ff9832587a87d2a3d8a4daba89710e670e

@rekram1-node commented on GitHub (Nov 30, 2025): fixed in next release thanks to @joachim-isaksson fix in opencode: https://github.com/sst/opencode/commit/0308b2ff9832587a87d2a3d8a4daba89710e670e
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3139