Skip to content

fix(ai-anthropic): send the anthropic-beta header that computerUseTool needs - #1832

Closed
AlemTuzlak wants to merge 2 commits into
mainfrom
fix/anthropic-computer-use-beta
Closed

AlemTuzlak wants to merge 2 commits into
mainfrom
fix/anthropic-computer-use-beta

Conversation

@AlemTuzlak

@AlemTuzlak AlemTuzlak commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

computerUseTool() from @tanstack/ai-anthropic/tools sends no computer use beta header, and Anthropic needs one for each of these versions. This PR adds the header that each version needs: computer-use-2025-01-24 for computer_20250124, and computer-use-2024-10-22 for computer_20241022.

🎯 Changes

  • computeAnthropicBetas adds the computer use beta of the computer tool in tools. It follows the code_execution code next to it.
  • A unit test that is the repro, and an E2E wire spec that reads the anthropic-beta header of the outgoing request.
  • A patch changeset.

Docs: no change. The docs never said which header the tool sends, and the samples now work as written.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.
  • Docs: I updated docs/ for this change, or this change is not user-facing.
  • Changeset: I added a changeset (pnpm changeset), or this PR does not change a published package.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Root cause

Issue. A chat() request with computerUseTool() has no computer use beta header. The Anthropic docs say that each earlier version needs its beta header on every request. For example, computer_20250124 needs computer-use-2025-01-24.
Cause. The adapter sends betas from computeAnthropicBetas (packages/ai-anthropic/src/adapters/text.ts). That function adds the betas of code execution, skills, files, MCP, context management, and mid-conversation tools, but none for a computer use tool.
Fix. When tools has a computer use tool, computeAnthropicBetas reads its type and adds the matching beta.

Possible alternatives

  • Users set the header with defaultHeaders. This works today. It makes every app find and keep the right header for each version, and the adapter already owns the betas of the other tools.
  • Always send computer-use-2025-01-24. Two lines shorter. It sends the wrong header for computer_20241022, which computerUseTool() also takes.

Testing

Commands run:

  1. The repro (packages/ai-anthropic/tests/computer-use-beta.test.ts, written for this PR) on a clean main worktree at 7095ebbf1. It fails:
 RUN  v4.1.10 F:/worktrees/ai/anthropic-computer-use/worktrees/bugfix-0139ca8189eb-main/packages/ai-anthropic
     × sends computer_20250124 with the computer-use-2025-01-24 beta 25ms
     × sends computer_20241022 with the computer-use-2024-10-22 beta 2ms
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯
AssertionError: expected [] to include 'computer-use-2025-01-24'
AssertionError: expected [] to include 'computer-use-2024-10-22'
 Test Files  1 failed (1)
      Tests  2 failed (2)
  1. The same command on this branch (08a7b2a75). It passes:
 RUN  v4.1.10 F:/worktrees/ai/anthropic-computer-use/worktrees/bugfix-d3ec72c1e6b8-pr/packages/ai-anthropic
 Test Files  1 passed (1)
      Tests  2 passed (2)
   Start at  18:48:06
   Duration  1.78s (transform 1.02s, setup 0ms, import 1.34s, tests 23ms, environment 0ms)
  1. Vitest with --maxWorkers=2 on computer-use-beta, text.skills, provider-tools-smoke, and tools-per-model-type-safety: 48 tests pass.
  2. test:types, test:oxlint (no new warnings), and oxfmt --check on ai-anthropic and the changed files.
  3. The E2E route type-checks with the TypeScript of testing/e2e.

Not run locally: the E2E suite, pnpm test:pr, and coverage. CI runs them.

Manual test:

  1. On main, run pnpm --dir packages/ai-anthropic exec vitest run tests/computer-use-beta.test.ts. Both tests fail: expected [] to include 'computer-use-2025-01-24'.
  2. On this branch, run the same command. Both tests pass.
  3. With a real key, send a chat() on claude-haiku-4-5 with computerUseTool({ type: 'computer_20250124', name: 'computer', display_width_px: 1024, display_height_px: 768 }). The request now has anthropic-beta: computer-use-2025-01-24.

How this PR makes testing easy: tests/computer-use-beta.test.ts runs chat() with a mocked client and reads the betas of the request. testing/e2e/tests/anthropic-computer-use-wire.spec.ts reads the real anthropic-beta header from a custom fetch.

Risk / rollback

Low. A request with a computer use tool gets one more beta header. Other requests do not change. To undo, revert this PR.

Summary by CodeRabbit

  • New Features
    • Computer-use requests now send the Anthropic beta header for the matching computer-use version, supporting both the 2024 and 2025 formats.
  • Tests
    • Added coverage verifying the beta header is sent for both versions, including an end-to-end check.

computerUseTool() went out without its anthropic-beta header, so Anthropic rejected the request. Add computer-use-2025-01-24 for computer_20250124 and computer-use-2024-10-22 for computer_20241022.
@changeset-bot

changeset-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 08a7b2a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/ai-anthropic Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@nx-cloud

nx-cloud Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 08a7b2a

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 58s View ↗
nx run-many --targets=test:coverage --projects=... ✅ Succeeded <1s View ↗
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 10s View ↗

☁️ Nx Cloud last updated this comment at 2026-10-19 17:13:10 UTC

@github-actions

Copy link
Copy Markdown
Contributor

Coverage

✅ Coverage held across 2 compared package(s).

Each package is measured twice in this job — on this PR and on its merge-base with main — and compared. A metric fails only when it is at or above 60% on the merge-base and under 60% on this PR. Other drops are listed but do not fail. Packages your PR doesn't affect are not measured and not listed.

package statements branches functions lines
ai-anthropic 92.04% (+0.04) 86.80% (+0.07) 95.61% (+0.04) 92.45% (+0.04) ok
ai-code-mode-snippets 87.13% (0.00) 75.67% (0.00) 91.11% (0.00) 88.39% (0.00) ok

@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/@tanstack/ai@1832

@tanstack/ai-acp

npm i https://pkg.pr.new/@tanstack/ai-acp@1832

@tanstack/ai-angular

npm i https://pkg.pr.new/@tanstack/ai-angular@1832

@tanstack/ai-anthropic

npm i https://pkg.pr.new/@tanstack/ai-anthropic@1832

@tanstack/ai-bedrock

npm i https://pkg.pr.new/@tanstack/ai-bedrock@1832

@tanstack/ai-byteplus

npm i https://pkg.pr.new/@tanstack/ai-byteplus@1832

@tanstack/ai-claude-code

npm i https://pkg.pr.new/@tanstack/ai-claude-code@1832

@tanstack/ai-client

npm i https://pkg.pr.new/@tanstack/ai-client@1832

@tanstack/ai-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-cloudflare@1832

@tanstack/ai-code-mode

npm i https://pkg.pr.new/@tanstack/ai-code-mode@1832

@tanstack/ai-code-mode-snippets

npm i https://pkg.pr.new/@tanstack/ai-code-mode-snippets@1832

@tanstack/ai-codex

npm i https://pkg.pr.new/@tanstack/ai-codex@1832

@tanstack/ai-cohere

npm i https://pkg.pr.new/@tanstack/ai-cohere@1832

@tanstack/ai-compaction

npm i https://pkg.pr.new/@tanstack/ai-compaction@1832

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/@tanstack/ai-devtools-core@1832

@tanstack/ai-durable-stream

npm i https://pkg.pr.new/@tanstack/ai-durable-stream@1832

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@1832

@tanstack/ai-event-client

npm i https://pkg.pr.new/@tanstack/ai-event-client@1832

@tanstack/ai-fal

npm i https://pkg.pr.new/@tanstack/ai-fal@1832

@tanstack/ai-gemini

npm i https://pkg.pr.new/@tanstack/ai-gemini@1832

@tanstack/ai-grok

npm i https://pkg.pr.new/@tanstack/ai-grok@1832

@tanstack/ai-grok-build

npm i https://pkg.pr.new/@tanstack/ai-grok-build@1832

@tanstack/ai-groq

npm i https://pkg.pr.new/@tanstack/ai-groq@1832

@tanstack/ai-isolate-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@1832

@tanstack/ai-isolate-daytona

npm i https://pkg.pr.new/@tanstack/ai-isolate-daytona@1832

@tanstack/ai-isolate-e2b

npm i https://pkg.pr.new/@tanstack/ai-isolate-e2b@1832

@tanstack/ai-isolate-node

npm i https://pkg.pr.new/@tanstack/ai-isolate-node@1832

@tanstack/ai-isolate-quickjs

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@1832

@tanstack/ai-isolate-quickjs-bun

npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs-bun@1832

@tanstack/ai-llmgateway

npm i https://pkg.pr.new/@tanstack/ai-llmgateway@1832

@tanstack/ai-lovable

npm i https://pkg.pr.new/@tanstack/ai-lovable@1832

@tanstack/ai-mcp

npm i https://pkg.pr.new/@tanstack/ai-mcp@1832

@tanstack/ai-memory

npm i https://pkg.pr.new/@tanstack/ai-memory@1832

@tanstack/ai-mistral

npm i https://pkg.pr.new/@tanstack/ai-mistral@1832

@tanstack/ai-octane

npm i https://pkg.pr.new/@tanstack/ai-octane@1832

@tanstack/ai-ollama

npm i https://pkg.pr.new/@tanstack/ai-ollama@1832

@tanstack/ai-ollaya

npm i https://pkg.pr.new/@tanstack/ai-ollaya@1832

@tanstack/ai-openai

npm i https://pkg.pr.new/@tanstack/ai-openai@1832

@tanstack/ai-opencode

npm i https://pkg.pr.new/@tanstack/ai-opencode@1832

@tanstack/ai-openrouter

npm i https://pkg.pr.new/@tanstack/ai-openrouter@1832

@tanstack/ai-perplexity

npm i https://pkg.pr.new/@tanstack/ai-perplexity@1832

@tanstack/ai-persistence

npm i https://pkg.pr.new/@tanstack/ai-persistence@1832

@tanstack/ai-preact

npm i https://pkg.pr.new/@tanstack/ai-preact@1832

@tanstack/ai-react

npm i https://pkg.pr.new/@tanstack/ai-react@1832

@tanstack/ai-react-ui

npm i https://pkg.pr.new/@tanstack/ai-react-ui@1832

@tanstack/ai-reactor

npm i https://pkg.pr.new/@tanstack/ai-reactor@1832

@tanstack/ai-remix

npm i https://pkg.pr.new/@tanstack/ai-remix@1832

@tanstack/ai-sandbox

npm i https://pkg.pr.new/@tanstack/ai-sandbox@1832

@tanstack/ai-sandbox-blaxel

npm i https://pkg.pr.new/@tanstack/ai-sandbox-blaxel@1832

@tanstack/ai-sandbox-boxd

npm i https://pkg.pr.new/@tanstack/ai-sandbox-boxd@1832

@tanstack/ai-sandbox-cloudflare

npm i https://pkg.pr.new/@tanstack/ai-sandbox-cloudflare@1832

@tanstack/ai-sandbox-daytona

npm i https://pkg.pr.new/@tanstack/ai-sandbox-daytona@1832

@tanstack/ai-sandbox-docker

npm i https://pkg.pr.new/@tanstack/ai-sandbox-docker@1832

@tanstack/ai-sandbox-e2b

npm i https://pkg.pr.new/@tanstack/ai-sandbox-e2b@1832

@tanstack/ai-sandbox-local-process

npm i https://pkg.pr.new/@tanstack/ai-sandbox-local-process@1832

@tanstack/ai-sandbox-railway

npm i https://pkg.pr.new/@tanstack/ai-sandbox-railway@1832

@tanstack/ai-sandbox-sprites

npm i https://pkg.pr.new/@tanstack/ai-sandbox-sprites@1832

@tanstack/ai-sandbox-upstash-box

npm i https://pkg.pr.new/@tanstack/ai-sandbox-upstash-box@1832

@tanstack/ai-sandbox-vercel

npm i https://pkg.pr.new/@tanstack/ai-sandbox-vercel@1832

@tanstack/ai-skills

npm i https://pkg.pr.new/@tanstack/ai-skills@1832

@tanstack/ai-solid

npm i https://pkg.pr.new/@tanstack/ai-solid@1832

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/@tanstack/ai-solid-ui@1832

@tanstack/ai-svelte

npm i https://pkg.pr.new/@tanstack/ai-svelte@1832

@tanstack/ai-typesafe

npm i https://pkg.pr.new/@tanstack/ai-typesafe@1832

@tanstack/ai-utils

npm i https://pkg.pr.new/@tanstack/ai-utils@1832

@tanstack/ai-vercel-gateway

npm i https://pkg.pr.new/@tanstack/ai-vercel-gateway@1832

@tanstack/ai-vertex

npm i https://pkg.pr.new/@tanstack/ai-vertex@1832

@tanstack/ai-vue

npm i https://pkg.pr.new/@tanstack/ai-vue@1832

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/@tanstack/ai-vue-ui@1832

@tanstack/ai-worldlabs

npm i https://pkg.pr.new/@tanstack/ai-worldlabs@1832

@tanstack/openai-base

npm i https://pkg.pr.new/@tanstack/openai-base@1832

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@1832

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/@tanstack/react-ai-devtools@1832

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@1832

@tanstack/svelte-ai-devtools

npm i https://pkg.pr.new/@tanstack/svelte-ai-devtools@1832

commit: 08a7b2a

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: TanStack/ai/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 538c5e4d-075d-4800-ba76-ad7fbc331857
📥 Commits

Reviewing files that changed from the base of the PR and between 7095ebb and 08a7b2a.

📒 Files selected for processing: 6
  • .changeset/anthropic-computer-use-beta.md
  • packages/ai-anthropic/src/adapters/text.ts
  • packages/ai-anthropic/tests/computer-use-beta.test.ts
  • testing/e2e/src/routeTree.gen.ts
  • testing/e2e/src/routes/api.anthropic-computer-use-wire.ts
  • testing/e2e/tests/anthropic-computer-use-wire.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

📝 Walkthrough

The Anthropic adapter now selects a dated anthropic-beta header for computer-use tools based on tool version. Unit tests check both supported versions. An end-to-end route captures the outgoing header and returns it for verification.

Changes: Computer-use beta selection

Layer / File(s) Summary
Select the beta by tool version
packages/ai-anthropic/src/adapters/text.ts, packages/ai-anthropic/tests/computer-use-beta.test.ts, .changeset/anthropic-computer-use-beta.md
computeAnthropicBetas adds computer-use-2024-10-22 for computer_20241022 and computer-use-2025-01-24 for other converted computer-use types. Unit tests check both values. A patch changeset describes the versioned headers.

End-to-end header verification

Layer / File(s) Summary
Capture and verify the outgoing header
testing/e2e/src/routes/api.anthropic-computer-use-wire.ts, testing/e2e/src/routeTree.gen.ts, testing/e2e/tests/anthropic-computer-use-wire.spec.ts
The POST route runs a chat with computerUseTool and captures the outgoing anthropic-beta header. The generated route tree registers the endpoint. The end-to-end test checks for computer-use-2025-01-24.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 08a7b

The change is mergeable after normal checks; no concrete issue requiring a fix before merge was established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: sending the required Anthropic beta header for computerUseTool.
Description check Passed The description follows the required template, explains the change and root cause, documents testing and risk, and confirms the changeset. It also states which tests were not run locally and why.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AlemTuzlak

Copy link
Copy Markdown
Contributor Author

Closing this PR. Its commits are now part of #1837. That PR also adds @tanstack/ai-computer-use, with drivers for Playwright and E2B. Review #1837 instead.

@AlemTuzlak AlemTuzlak closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on: maintainer The ball is in the maintainers’ court

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants