anthropics / anthropics/anthropic-sdk-typescript
[Vertex] anthropic-beta header forwarded to countTokens fallback fails on lagging model backends
- Vorherrschende Sprache
- TypeScript
- Sterne
- 2.1k
- Forks
- 403
- Ø Merge
- 1 T. 21 Std.
- Gemergte PRs (30 T.)
- 8
Beschreibung
## Summary
When using the Vertex AI backend, `client.messages.countTokens(...)` (and the fallback path used when the dedicated count-tokens API returns null) forwards `anthropic-beta` headers to the underlying model. Vertex's per-model Anthropic backends roll out new beta values on different schedules — most notably the Haiku tier lags — so calls that include any newly-introduced beta value are rejected with HTTP 400 by whichever model hasn't received that beta yet.
This causes recurring breakage in downstream consumers (Claude Code being the most visible — see anthropics/claude-code#11154, open since November 2025 with the same root cause re-triggering every time a new beta is introduced).
## Reproduction
```bash
TOKEN=$(gcloud auth print-access-token)
PROJECT=
curl -s -X POST \
"https://aiplatform.googleapis.com/v1/projects/$PROJECT/locations/global/publishers/anthropic/models/claude-haiku-4-5@20251001:rawPredict" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-H "anthropic-beta: effort-2025-11-24" \
-d '{"anthropic_version":"vertex-2023-10-16","max_tokens":20,"messages":[{"role":"user","content":"hi"}]}'
```
Returns:
```json
{"type":"error","error":{"type":"invalid_request_error","message":"Unexpected value(s) `effort-2025-11-24` for the `anthropic-beta` header. ..."},"request_id":"req_vrtx_..."}
```
The same call against `claude-opus-4-7@default` or `claude-sonnet-4-6@default` succeeds. Past offending values include `structured-outputs-2025-12-15`, `tool-search-tool-2025-10-19`, `context-1m-2025-08-07`, `redact-thinking-2026-02-12`, `web-search-2025-03-05`.
## Suggested fix
Strip (or make opt-in) `anthropic-beta` headers on count-tokens calls in the Vertex backend, since token counting doesn't need beta-gated capabilities. This matches what was suggested in claude-code#11154 and would structurally end the recurrence rather than chasing per-beta Vertex rollouts.
## Environment
- `@anthropic-ai/vertex-sdk` 0.16.0
- Region: `global`
- Affected model tier: Haiku 4.5 (consistently lags); other models intermittently
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.