Skip to content

Fix 400 "thinking.type.enabled is not supported" when using a direct Anthropic API key - #4480

Merged
sejas merged 4 commits into
trunkfrom
fix-anthropic-adaptive-thinking-080614
Aug 7, 2026
Merged

Fix 400 "thinking.type.enabled is not supported" when using a direct Anthropic API key#4480
sejas merged 4 commits into
trunkfrom
fix-anthropic-adaptive-thinking-080614

Conversation

@sejas

@sejas sejas commented Aug 7, 2026

Copy link
Copy Markdown
Member

Related issues

How AI was used in this PR

Used to trace the failing request path, design the fix, and write the regression tests. All changes were reviewed and verified locally against the live Anthropic API.

Proposed Changes

Chatting with a direct Anthropic API key (/provider → Anthropic · API key) always fails:

400 "thinking.type.enabled" is not supported for this model. Use "thinking.type.adaptive" and "output_config.effort" to control thinking behavior.

Studio's hand-built model definition was missing the catalog metadata that tells the pi runtime that claude-sonnet-5 / claude-opus-5 require the adaptive thinking request shape, so it sent the legacy budget-based shape, which the API rejects.

This PR:

  • Copies the thinking metadata (compat, thinkingLevelMap) from pi-ai's bundled Anthropic catalog into Studio's model definition, so requests use thinking: { type: "adaptive" }. The values stay in sync with pi-ai upgrades, and a new test fails if a future Studio model is missing from the catalog.
  • Passes allowNetwork: false when setting the runtime API key — the implicit default triggered an awaited, unguarded network fetch of remote model catalogs on every direct-key turn (which also hung the new tests on a CI agent with slow egress). Studio hand-builds its models, so the fetch was pure latency.

No behavior change for the WordPress.com provider, apart from dropping a beta header that adaptive-thinking models don't need. Studio's conservative context-window/output limits are unchanged.

Noted for a follow-up issue: the WordPress.com proxy path never requests extended thinking at all — the custom provider forwards options that pi-ai's low-level stream ignores.

Testing Instructions

  1. npm run cli:build && node apps/cli/dist/cli/main.mjs ai
  2. /provider → "Anthropic · API key", enter a valid sk-ant-... key.
  3. Send a prompt on Sonnet 5 — expect a streamed response instead of the 400 above. Repeat on Opus 5.
  4. Regression: /provider → WordPress.com, send a prompt — still working.
Before After
Screenshot 2026-08-07 at 15 59 35 Screenshot 2026-08-07 at 16 04 33

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@sejas sejas self-assigned this Aug 7, 2026
@sejas
sejas marked this pull request as ready for review August 7, 2026 14:59
@wpmobilebot

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 2857e7f vs trunk

app-size

Metric trunk 2857e7f Diff Change
App Size (Mac) 1405.26 MB 1405.26 MB +0.00 MB ⚪ 0.0%

site-editor

Metric trunk 2857e7f Diff Change
load 1045 ms 1075 ms +30 ms ⚪ 0.0%

site-startup

Metric trunk 2857e7f Diff Change
siteCreation 7516 ms 7547 ms +31 ms ⚪ 0.0%
siteStartup 2863 ms 2875 ms +12 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@sejas

sejas commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

I'm merging this as I want to include it in the next release.

@sejas
sejas merged commit 97a5a94 into trunk Aug 7, 2026
11 of 13 checks passed
@sejas
sejas deleted the fix-anthropic-adaptive-thinking-080614 branch August 7, 2026 16:04
sejas added a commit that referenced this pull request Aug 7, 2026
…I key (1.18.0) (#4484)

Cherry-picks 97a5a94 from trunk: chatting with a direct Anthropic API key always failed with `400 "thinking.type.enabled" is not supported for this model`. See #4480 for full details.

- Copies thinking metadata (`compat`, `thinkingLevelMap`) from pi-ai's bundled catalog so requests use `thinking: { type: "adaptive" }`.
- Passes `allowNetwork: false` when setting the runtime API key, removing an unguarded per-turn network fetch.
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