Skip to content

feat(web): resolve Anthropic thinking config from model capabilities#1294

Merged
brendan-kellam merged 4 commits into
mainfrom
brendan/anthropic-thinking-capabilities
Jun 10, 2026
Merged

feat(web): resolve Anthropic thinking config from model capabilities#1294
brendan-kellam merged 4 commits into
mainfrom
brendan/anthropic-thinking-capabilities

Conversation

@brendan-kellam

@brendan-kellam brendan-kellam commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Resolves the Anthropic thinking provider option (adaptive vs. extended) by querying the Models API for the model's capabilities, instead of maintaining a hardcoded allowlist of model IDs that drifts out of date with each release.

  • Adaptive-capable models use { type: "adaptive" }; older models fall back to { type: "enabled", budgetTokens }; the option is omitted entirely if the model doesn't support thinking or the lookup fails.
  • Result is cached per (baseUrl, model) to avoid an extra request per call.
  • Adds @anthropic-ai/sdk for the typed models.retrieve call.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Changed
    • Anthropic thinking mode (adaptive vs. enabled/extended) is now resolved dynamically from the Anthropic Models API instead of relying on a hardcoded list, allowing the app to select appropriate thinking behavior per model.
    • Improved resilience: unsupported models are detected and thinking options are omitted gracefully; failures are logged and reported without disrupting user requests.

Determine adaptive vs. extended thinking by querying the Anthropic Models
API for the model's capabilities, instead of maintaining a hardcoded
allowlist of model IDs that drifts with each release. Cached per model;
falls back to omitting the thinking option when the lookup fails. Adds
@anthropic-ai/sdk for the typed models.retrieve call.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

This comment has been minimized.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a21843f6-db4d-4ee4-ba5d-1af95dababc6

📥 Commits

Reviewing files that changed from the base of the PR and between 3a30fd7 and 2c989dc.

📒 Files selected for processing (1)
  • packages/web/src/features/chat/llm.server.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/web/src/features/chat/llm.server.ts

Walkthrough

Replaces hardcoded Anthropic model-id checks with a dynamic resolver that queries the Anthropic Models API for supported "thinking" modes, adds the Anthropic SDK dependency, caches results, reports errors to Sentry, and updates the changelog.

Changes

Dynamic Anthropic Thinking Configuration

Layer / File(s) Summary
SDK dependency and error handling imports
packages/web/package.json, packages/web/src/features/chat/llm.server.ts
Anthropic SDK dependency (@anthropic-ai/sdk@^0.104.0) added; logger and Sentry imports introduced to support error reporting during capability resolution.
Provider configuration and capability resolution
packages/web/src/features/chat/llm.server.ts
Anthropic provider configuration replaced inline model-id checks with tryResolveAnthropicThinkingConfig, which normalizes baseUrl, queries the Anthropic Models API with a 10s timeout, caches results by baseUrl+modelId, maps thinking capabilities to provider options, and reports failures to Sentry with warning logs.
Changelog documentation
CHANGELOG.md
Unreleased entry documents that Anthropic thinking mode resolution is now determined via the Models API instead of a hardcoded model list.

Sequence Diagram(s)

sequenceDiagram
  participant ProviderConfig as Anthropic ProviderConfig
  participant Cache as InMemoryCache
  participant Resolver as tryResolveAnthropicThinkingConfig
  participant AnthropicClient as Anthropic SDK Client
  participant ModelsAPI as Anthropic Models API
  participant Sentry as Sentry

  ProviderConfig->>Cache: check(baseUrl+modelId)
  alt cache hit
    Cache-->>ProviderConfig: return cached thinking config
  else cache miss
    ProviderConfig->>Resolver: call(baseUrl, modelId, apiKey, authToken, headers)
    Resolver->>AnthropicClient: create client(normalized baseUrl, apiKey/auth)
    Resolver->>ModelsAPI: models.retrieve(modelId) (10s timeout)
    alt success & thinking supported
      ModelsAPI-->>Resolver: capabilities
      Resolver->>Cache: store result(baseUrl+modelId)
      Resolver-->>ProviderConfig: return thinking config (adaptive|enabled)
    else failure or unsupported
      ModelsAPI-->>Resolver: error / missing capability
      Resolver->>Sentry: captureException(error)
      Resolver->>Resolver: logger.warn(...)
      Resolver-->>ProviderConfig: return undefined
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • sourcebot-dev/sourcebot#1127: Adjusts how providerOptions.anthropic.thinking is determined for claude-opus-4-7, using model-id prefix logic.
  • sourcebot-dev/sourcebot#1249: Expands hardcoded modelId-based adaptive-thinking checks for Anthropic models; this PR replaces that pattern with Models API–driven resolution.

Suggested reviewers

  • msukkari
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: dynamically resolving Anthropic thinking configuration from model capabilities instead of a hardcoded list.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch brendan/anthropic-thinking-capabilities

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 and usage tips.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@brendan-kellam brendan-kellam requested a review from jsourcebot June 9, 2026 22:53

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/web/src/features/chat/llm.server.ts`:
- Around line 378-381: The cache only stores truthy thinking-config results so
models that return "no thinking support" repeatedly call
client.models.retrieve(...); modify the logic around
anthropicThinkingConfigCache and cacheKey to always set a cache entry (including
explicit negative/empty markers) after retrieving from
client.models.retrieve(modelId) so unsupported models are cached too, and
read/write that marker from anthropicThinkingConfigCache.get/set to avoid
repeated API calls.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 44402c0b-5cfd-4b09-b0b9-68eb3455e1a9

📥 Commits

Reviewing files that changed from the base of the PR and between 147aa95 and be45a27.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • CHANGELOG.md
  • packages/web/package.json
  • packages/web/src/features/chat/llm.server.ts

Comment thread packages/web/src/features/chat/llm.server.ts
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

License Audit

⚠️ Status: PASS

Metric Count
Total packages 2136
Resolved (non-standard) 20
Unresolved 0
Strong copyleft 0
Weak copyleft 39

Weak Copyleft Packages (informational)

Package Version License
@img/sharp-libvips-darwin-arm64 1.0.4 LGPL-3.0-or-later
@img/sharp-libvips-darwin-arm64 1.2.4 LGPL-3.0-or-later
@img/sharp-libvips-darwin-x64 1.0.4 LGPL-3.0-or-later
@img/sharp-libvips-darwin-x64 1.2.4 LGPL-3.0-or-later
@img/sharp-libvips-linux-arm 1.0.5 LGPL-3.0-or-later
@img/sharp-libvips-linux-arm 1.2.4 LGPL-3.0-or-later
@img/sharp-libvips-linux-arm64 1.0.4 LGPL-3.0-or-later
@img/sharp-libvips-linux-arm64 1.2.4 LGPL-3.0-or-later
@img/sharp-libvips-linux-ppc64 1.2.4 LGPL-3.0-or-later
@img/sharp-libvips-linux-riscv64 1.2.4 LGPL-3.0-or-later
@img/sharp-libvips-linux-s390x 1.0.4 LGPL-3.0-or-later
@img/sharp-libvips-linux-s390x 1.2.4 LGPL-3.0-or-later
@img/sharp-libvips-linux-x64 1.0.4 LGPL-3.0-or-later
@img/sharp-libvips-linux-x64 1.2.4 LGPL-3.0-or-later
@img/sharp-libvips-linuxmusl-arm64 1.0.4 LGPL-3.0-or-later
@img/sharp-libvips-linuxmusl-arm64 1.2.4 LGPL-3.0-or-later
@img/sharp-libvips-linuxmusl-x64 1.0.4 LGPL-3.0-or-later
@img/sharp-libvips-linuxmusl-x64 1.2.4 LGPL-3.0-or-later
@img/sharp-wasm32 0.33.5 Apache-2.0 AND LGPL-3.0-or-later AND MIT
@img/sharp-wasm32 0.34.5 Apache-2.0 AND LGPL-3.0-or-later AND MIT
@img/sharp-win32-arm64 0.34.5 Apache-2.0 AND LGPL-3.0-or-later
@img/sharp-win32-ia32 0.33.5 Apache-2.0 AND LGPL-3.0-or-later
@img/sharp-win32-ia32 0.34.5 Apache-2.0 AND LGPL-3.0-or-later
@img/sharp-win32-x64 0.33.5 Apache-2.0 AND LGPL-3.0-or-later
@img/sharp-win32-x64 0.34.5 Apache-2.0 AND LGPL-3.0-or-later
axe-core 4.10.3 MPL-2.0
dompurify 3.4.0 (MPL-2.0 OR Apache-2.0)
lightningcss 1.32.0 MPL-2.0
lightningcss-android-arm64 1.32.0 MPL-2.0
lightningcss-darwin-arm64 1.32.0 MPL-2.0
lightningcss-darwin-x64 1.32.0 MPL-2.0
lightningcss-freebsd-x64 1.32.0 MPL-2.0
lightningcss-linux-arm-gnueabihf 1.32.0 MPL-2.0
lightningcss-linux-arm64-gnu 1.32.0 MPL-2.0
lightningcss-linux-arm64-musl 1.32.0 MPL-2.0
lightningcss-linux-x64-gnu 1.32.0 MPL-2.0
lightningcss-linux-x64-musl 1.32.0 MPL-2.0
lightningcss-win32-arm64-msvc 1.32.0 MPL-2.0
lightningcss-win32-x64-msvc 1.32.0 MPL-2.0
Resolved Packages (20)
Package Version Original Resolved Source
@react-grab/cli 0.1.23 UNKNOWN MIT GitHub repo (aidenybai/react-grab LICENSE)
@react-grab/cli 0.1.29 UNKNOWN MIT GitHub repo (aidenybai/react-grab LICENSE)
@react-grab/mcp 0.1.29 UNKNOWN MIT GitHub repo (aidenybai/react-grab monorepo LICENSE)
codemirror-lang-elixir 4.0.0 UNKNOWN Apache-2.0 GitHub repo (livebook-dev/codemirror-lang-elixir LICENSE) + npm registry
element-source 0.0.3 UNKNOWN MIT npm package tarball (bundled LICENSE file, MIT)
lezer-elixir 1.1.2 UNKNOWN Apache-2.0 GitHub repo (livebook-dev/lezer-elixir LICENSE) + npm registry
map-stream 0.1.0 UNKNOWN MIT GitHub repo (dominictarr/map-stream package.json) + npm registry
memorystream 0.3.1 UNKNOWN MIT npm registry (licenses array: {type:"MIT"})
valid-url 1.0.9 UNKNOWN MIT GitHub repo (ogt/valid-url LICENSE)
pause-stream 0.0.11 ["MIT","Apache2"] (object/array) MIT OR Apache-2.0 extracted from license object/array
posthog-js 1.369.0 SEE LICENSE IN LICENSE Apache-2.0 GitHub repo (PostHog/posthog-js LICENSE file: Apache License 2.0)
@sentry/cli 2.58.5 FSL-1.1-MIT FSL-1.1-MIT npm registry (confirmed: Functional Source License 1.1, MIT future grant; non-SPDX but valid)
@sentry/cli-darwin 2.58.5 FSL-1.1-MIT FSL-1.1-MIT npm registry (confirmed: Functional Source License 1.1, MIT future grant; non-SPDX but valid)
@sentry/cli-linux-arm 2.58.5 FSL-1.1-MIT FSL-1.1-MIT npm registry (confirmed: Functional Source License 1.1, MIT future grant; non-SPDX but valid)
@sentry/cli-linux-arm64 2.58.5 FSL-1.1-MIT FSL-1.1-MIT npm registry (confirmed: Functional Source License 1.1, MIT future grant; non-SPDX but valid)
@sentry/cli-linux-i686 2.58.5 FSL-1.1-MIT FSL-1.1-MIT npm registry (confirmed: Functional Source License 1.1, MIT future grant; non-SPDX but valid)
@sentry/cli-linux-x64 2.58.5 FSL-1.1-MIT FSL-1.1-MIT npm registry (confirmed: Functional Source License 1.1, MIT future grant; non-SPDX but valid)
@sentry/cli-win32-arm64 2.58.5 FSL-1.1-MIT FSL-1.1-MIT npm registry (confirmed: Functional Source License 1.1, MIT future grant; non-SPDX but valid)
@sentry/cli-win32-i686 2.58.5 FSL-1.1-MIT FSL-1.1-MIT npm registry (confirmed: Functional Source License 1.1, MIT future grant; non-SPDX but valid)
@sentry/cli-win32-x64 2.58.5 FSL-1.1-MIT FSL-1.1-MIT npm registry (confirmed: Functional Source License 1.1, MIT future grant; non-SPDX but valid)

jsourcebot
jsourcebot previously approved these changes Jun 10, 2026
@brendan-kellam brendan-kellam merged commit 279bbb8 into main Jun 10, 2026
9 checks passed
@brendan-kellam brendan-kellam deleted the brendan/anthropic-thinking-capabilities branch June 10, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants