Support Claude Opus 4.7 via adaptive thinking provider options

Closed
SI
1mo ago
+202-13

Summary

Fixes the "thinking.type.enabled is not supported for this model" error users hit when selecting Claude Opus 4.7. Opus 4.7 rejects the old thinking config (`type: "enabled"` + `budgetTokens`) with a 400 error and requires the new `type: "adaptive"` shape. Adaptive is also preferred (but not required) on Opus 4.6 and Sonnet 4.6, while older Anthropic models (Sonnet 4.5, Opus 4.5, Haiku 3.x) only support the legacy shape.

Why this wasn't a one-line flip

A simple `enabled` → `adaptive` swap would break every Anthropic model below 4.6 that's still in the model list. The fix needs to be model-aware.

Changes

  • New helper: `getAnthropicProviderOptions(modelId)` returns the correct `AnthropicProviderOptions` shape per model. Allowlist-driven for explicitness. Legacy config is the safe default for unknown or non-Anthropic IDs.
  • SDK upgrade: `@ai-sdk/anthropic` `3.0.13` → `^3.0.70`. Required because the installed SDK's Zod schema only accepted `"enabled" | "disabled"` — `adaptive` was added in 3.0.37.
  • Wired into `getGeneralAgent.ts` replacing the hardcoded anthropic providerOptions.

Model compatibility matrix (from Anthropic docs)

Model`type: "enabled"``type: "adaptive"`
Opus 4.7❌ 400 error✅ only supported mode
Opus 4.6⚠️ deprecated✅ preferred
Sonnet 4.6⚠️ deprecated✅ preferred
Sonnet 4.5, Opus 4.5, Haiku 3.x, etc.✅ required❌ not supported

Due diligence — why this upgrade is low-risk

  • Zero breaking changes across the `3.0.14 → 3.0.70` span (reviewed every changelog entry — all patch-level additions, no majors)
  • SDK stays on v6 track — no `ai` package upgrade needed (4.0.0-beta.x is for the v7 pre-release and is not yet fully published anyway)
  • Single caller of `@ai-sdk/anthropic` in the codebase (`getGeneralAgent.ts`)
  • `AnthropicProviderOptions` type export preserved (aliased to `AnthropicLanguageModelOptions` after 3.0.42's type normalization; verified)

Verification

  • ✅ All 1906 existing tests pass post-upgrade
  • ✅ 9 new unit tests for `getAnthropicProviderOptions` (3 adaptive models + 2 legacy models + 2 defensive + 2 branch shape checks)
  • ✅ 3 new integration tests on `getGeneralAgent` proving wiring per model
  • ✅ `pnpm lint:check` clean

Test plan

  • Merge to test and deploy
  • In chat app, select "Claude Opus 4.7" and send a message → should stream a response (no 400 error)
  • Select "Claude Sonnet 4.6" → should stream successfully (adaptive branch)
  • Select "Claude Sonnet 4.5" → should stream successfully (legacy branch, backwards compat)
  • Select "GPT-5.4 Mini" → should stream successfully (default model, no Anthropic options apply)

Follow-ups (not in this PR)

  • Consider exposing `effort` as a user-configurable setting (currently hardcoded to `medium`)
  • On Opus 4.7, `thinking.display` defaults to `"omitted"` upstream; we explicitly set `"summarized"` to preserve the reasoning UI. If thinking blocks don't render correctly in chat, that's the knob to investigate.

Made with Cursor


Summary by cubic

Support Claude Opus 4.7 with model-aware Anthropic thinking options. Enables adaptive mode where required and keeps legacy settings for older models to prevent 400s.

  • New Features

    • Added getAnthropicProviderOptions(modelId) to return the right AnthropicProviderOptions per model.
      • Adaptive for anthropic/claude-opus-4.7, anthropic/claude-opus-4.6, anthropic/claude-sonnet-4.6 with display: "summarized" and effort: "medium".
      • Legacy enabled with budgetTokens: 12000 for older, unknown, and non-Anthropic models.
    • Wired into getGeneralAgent to set providerOptions.anthropic.
    • Added tests for both adaptive and legacy branches.
  • Dependencies

    • Bump @ai-sdk/anthropic from ^3.0.13 to ^3.0.70 to support type: "adaptive".

Summary by CodeRabbit

  • Improvements
    • Configured adaptive thinking for newer Claude models (Opus 4.7, 4.6, and Sonnet 4.6) with summarized output and medium effort level.
    • Maintained legacy thinking configuration for other models.