Skip to content

feat(anthropic): migrate to Anthropic SDK 1.x - #189697

Open
roboclaw-bot wants to merge 2 commits into
mainfrom
openclaw/mig-anthropic-sdk-1x
Open

roboclaw-bot wants to merge 2 commits into
mainfrom
openclaw/mig-anthropic-sdk-1x

Conversation

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Upgrade the Anthropic and Vertex SDKs to their eligible 1.x releases without silently changing authentication, request versions, or supported sampling behavior.

User Impact

No intended user-visible change. API keys remain in X-Api-Key; OAuth/setup-token, Copilot, Foundry bearer and Mantle credentials remain bearer-authenticated; Vertex retains Google authentication. Custom temperature on older Claude models, streaming, tool calls, caching, thinking, refusals and error handling retain their existing contracts. Missing credentials still fail before network access.

Why This Change Was Made

  • @anthropic-ai/sdk 0.137.0 → 1.3.0 across root, AI package, Mantle and the existing shared pin; @anthropic-ai/vertex-sdk 0.22.0 → 1.1.0. The existing Vertex-specific Google auth 11.3.1 override follows the upgraded parent. No new override policy or release-age exception.
  • SDK 1.x defaults to API version 2026-10-21 and bearer API keys. Use its documented custom-header support to preserve the existing 2023-06-01 API and X-Api-Key contract, matching OpenClaw's fetch transport. Credential layers now merge case-insensitively so caller overrides replace rather than duplicate credentials.
  • Vertex SDK 1.x copies the version header into anthropic_version and strips the header. Explicitly retain vertex-2023-10-16; Mantle retains 2023-06-01.
  • SDK request types no longer contain temperature. The request builder explicitly models the supported pinned-version field, without a cast.

Upstream research and holds

Audit instant: 2026-10-31T16:54:00Z; inclusive cutoff: 2026-10-24T16:54:00Z. These are the newest qualifying releases: SDK 1.3.0 published October 23 at 23:31:47.897Z; Vertex 1.1.0 at 13:13:08.611Z. Registry integrity matches the generated lock. Application lock audit: 1,749 package identities before/after, only these two replacements, no other dependency-edge changes or downgrades after normalizing the intended upgrade.

Authoritative sources: SDK changelog, Vertex changelog, API migration guide.

Upstream highlights: 1.0 changes API version/authentication and role-specific message types; 1.1–1.3 add administrative endpoints and message threads, repair tool-runner behavior, and adjust endpoint query handling. Published tarball comparison confirms the SSE parser and error classes are unchanged; OpenClaw's messages.create(...).asResponse() / Stream.rawEvents() path remains supported.

Hold: adopting API version 2026-10-21. It rejects sampling parameters even on models that previously supported them, with no equivalent replacement, and Bedrock supports it only for Claude 4.7+. Adopting it would remove supported behavior and needs a separate product decision. This PR upgrades the SDKs using their supported explicit-version/header APIs instead.

Unchanged: desktop runtime pruning still names SDK 0.132.1, already stale before this migration; its owner's re-audit is outside this change.

Evidence

Candidate: c21aae8f1971b0ef916237d204153995e9b36bef (base 1df551011c87ddab2b6e6edb316682cd8a9de1f2).

  • Native pnpm install --lockfile-only and pnpm install --frozen-lockfile: passed. No hand-edited lockfile.
  • Real-provider wire regressions: replacing only the provider with base code while retaining SDK 1.3 produced 4 failing / 1 passing tests (version/auth contract failures); restoring the migration passed. The added missing-key regression also passes.
  • Focused AI provider, transport/error parity, SSE and lazy-import tests: 85 passed, plus the final missing-key regression (86 unique). Final affected fixture rerun: 6 wire tests and 11 Mantle tests passed.
  • Complete Anthropic Vertex + Bedrock Mantle consumer tests: 100 passed across 11 files. The Vertex wire test uses the real SDK and Google OAuth client with synthetic credentials, verifies endpoint rewriting, body version, bearer header and sampling. Mantle wire proof uses the real SDK.
  • Caching, context-management, thinking binding and Anthropic transport siblings: 133 passed; prompt-prefix stability: 14 passed. 333 unique passing tests total, not counting reruns twice.
  • Core/extension production and package/extension test typechecks: passed, including final changed sources.
  • AI package runtime + declaration build: passed. Both touched provider packages compile to JavaScript; package-boundary typechecks passed. An exploratory declaration emit that included the unchanged Vertex test-support file reported TS2883; the production runtime emit and package-boundary checks pass.
  • Standalone oxlint and pinned-Bun analyzer: passed on touched core/extension files, with the repository's CI parity comparison enabled. Final oxfmt/Bun format parity, git diff --check, and test-line ratchet passed. No lint/test suppressions or new unsafe casts.
  • Independent autoreview / Codex gpt-6.1-sol, P0–P2: full migration with complete relevant source context and final repair delta both scoped-clean, no actionable findings. Review did not execute tests; execution evidence is listed separately. Simplification removed cast-based test scaffolding in favor of real typed clients/streams.

Timing: final AI batch 52s wrapper wall / 36s Vitest; extension batch 678s / 626s (91% transform); sibling/prefix batches 764s wrapper. Individual new wire tests are subsecond; CI timing remains pending. Earlier overloaded-host attempts timed out during declaration preparation and test transformation, before assertions; completed recovery checks above replace those incomplete attempts without weakening gates.

Remaining evidence limits: no authenticated live Anthropic, Vertex or Mantle call and no real-model Gateway E2E was run—task environment exposes none of their credentials. Wire/consumer proofs use synthetic external I/O. Hosted CI and required repository/security review remain pending; no merge or auto-merge requested.

Requested and guided by @steipete.

Work sessions

Worked on by

roboclaw-bot and others added 2 commits October 31, 2026 19:21
Move @anthropic-ai/sdk 0.137.0 -> 1.3.0 and @anthropic-ai/vertex-sdk
0.22.0 -> 1.1.0 (newest releases at or before the 2026-10-24 cutoff).

SDK 1.x defaults to API version 2026-10-21, sends API keys as bearer
tokens, and its Vertex client copies the header version into the body.
Keep the wire contract OpenClaw already sends from its fetch transport:
anthropic-version 2023-06-01 (vertex-2023-10-16 on Vertex), API keys in
X-Api-Key with Authorization nulled, and OAuth/Copilot/Foundry/Mantle on
bearer auth. 2026-10-21 rejects temperature for Claude models that still
accept it and is unavailable for pre-4.7 models on Bedrock, so adopting
it stays a separate product change.

Co-authored-by: steipete <[email protected]>
Worked on by:
- @steipete

Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: ed351993-c71c-4bc1-9971-746b48ecf441
@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Dependency graph changes

This maintainer PR changes the dependency graph.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: dc33c66b65cb843edf73e6d6efd3eaba847d340b
  • Maintainer: @roboclaw-bot
  • Repository role: maintain

These dependency graph changes were made:

  • pnpm-lock.yaml
  • pnpm-workspace.yaml
  • extensions/amazon-bedrock-mantle/package.json
  • extensions/anthropic-vertex/package.json
  • package.json
  • packages/ai/package.json

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 31, 2026
@clawsweeper

clawsweeper Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Upgrade the Anthropic and Vertex SDKs to 1.x while preserving authentication, API versions, and supported sampling.

Example: Claude Sonnet 4.6 receives temperature 0.2 through the Anthropic provider.

  • Before: SDK 0.137.0 sends API version 2023-06-01 with X-Api-Key authentication.
  • After: SDK 1.3.0 explicitly retains those headers and temperature 0.2.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused, source-supported compatibility work with useful reported regressions; evidence remains limited to in-process SDK exercises.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its supplied evidence exercises real SDK request construction with synthetic credentials and responses, without a shipped-entry-point live run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Maintenance · Worth it: Yes · Fix scope: Complete
User problem: A routine SDK major upgrade would otherwise change authentication and reject previously supported sampling requests.
Reason: The maintainer-authored direction qualifies maintained dependencies while deliberately preserving existing user behavior.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored migration open. It preserves existing provider contracts, remains absent from main, and introduces no actionable defect found in this review; the current-head CI gate passes.

Priority: P2
Reviewed head: dc33c66b65cb843edf73e6d6efd3eaba847d340b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No authenticated Anthropic, Vertex, or Mantle Gateway turn is supplied; the reported wire regressions use synthetic external I/O.
Agent review details

How this fits together

The AI package converts conversation and generation options into Anthropic requests; provider plugins supply Mantle or Google credentials, and streamed responses become assistant events.

flowchart LR
  A[Conversation and options] --> B[Shared Anthropic request builder]
  B --> C[Anthropic SDK provider]
  B --> D[Fetch transport]
  E[Vertex and Mantle adapters] --> C
  C --> F[Provider endpoint]
  D --> F
  F --> G[Assistant stream events]
Loading

Technical review

Best possible solution:

Retain the focused SDK migration with explicit wire compatibility in the existing provider owners.

Do we have a high-confidence way to reproduce the issue?

This is a dependency migration; source inspection confirms the upstream default changes, and the PR reports red/green wire regressions without claiming a current-main incident.

Is this the best way to solve the issue?

The patch uses existing request and header owners to preserve compatibility, and the simplification review found no unnecessary production machinery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7fa562d7281b.

Provenance checked

  • SDK dependency pins changes intended behavior with a stated reason (70134e4: The previous dependency refresh retained 0.x because 1.x required coordinated authentication and request compatibility work.)
  • Anthropic client preparation and header precedence keeps the original intent (21c4d54: Client preparation was consolidated into its request owner; the migration keeps that placement and reuses the existing case-insensitive header merger.)
  • Runtime header deletion markers keeps the original intent (e0e2082: Null markers must survive until final header merging rather than becoming literal wire values.)
  • Supported sampling and thinking request fields keeps the original intent (673a44e: Request shaping preserves model-specific sampling and thinking contracts; the explicit temperature field retains behavior absent from the new SDK types.)
  • Vertex Google authentication keeps the original intent (dbcf7ab: Provider-local GoogleAuth and proxy-aware fetch avoid the failing node-fetch import while preserving proxy routing.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 21c4d54 adds packages/ai/src/providers/anthropic.ts:222 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 21c4d54c72d4; files: packages/ai/src/providers/anthropic.ts)
  • Vincent Koc: Raw commit 066700b adds src/shared/anthropic-auth-headers.ts:9 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 066700bdd0e4; files: src/shared/anthropic-auth-headers.ts)
  • Ian Alloway: Raw commit dbcf7ab adds extensions/anthropic-vertex/stream-runtime.ts:32 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: dbcf7abda1e0; files: extensions/anthropic-vertex/stream-runtime.ts)

PR surface

Source +31, Tests +200, Config 0, Other +2. Total +233 across 16 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 6 45 14 +31
Tests 4 205 5 +200
Docs 0 0 0 0
Config 5 6 6 0
Generated 0 0 0 0
Other 1 25 23 +2
Total 16 281 48 +233

Review metrics

Metric Value Why it matters
Production versus test TypeScript Production +45/-14; tests +205/-5 The growth protects distinct SDK authentication, version, sampling, and provider-adapter contracts without adding production scaffolding.

Labels

Label changes:

  • add P2: A bounded dependency migration preserves existing provider behavior without an established urgent user-facing failure.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A bounded dependency migration preserves existing provider behavior without an established urgent user-facing failure.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 31, 2026, 3:38 PM ET / 19:38 UTC.

This branch has not been deployed

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

Labels

clawsweeper:intake:feature Preliminary submission classification; full source review pending. dependencies-changed PR changes dependency-related files extensions: amazon-bedrock-mantle extensions: anthropic-vertex size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant