Describe the Bug
streamCloudflareAnthropicAi in @flue/runtime's dist/cloudflare/workers-ai-provider.mjs always sets:
thinkingEnabled: Boolean(options?.reasoning)
That sends Anthropic's older budget-based thinking.type.enabled shape. Some models need Anthropic's newer adaptive-thinking API instead (thinking.type.adaptive plus output_config.effort), and for those, this fails every time.
claude-sonnet-5 is one of them. It's registered in @earendil-works/pi-ai's model catalog (dist/providers/data/anthropic.json) with "compat":{"forceAdaptiveThinking":true}. The other two code paths in the same file, the direct Anthropic API path and streamCloudflareResponsesAi/applyResponsesReasoning, both check that flag correctly. Only the Cloudflare AI Gateway path for Anthropic models skips it.
Here's what actually comes back, calling useModel('cloudflare/anthropic/claude-sonnet-5') through the Cloudflare env.AI binding:
Cloudflare AI binding request failed with 400 Bad Request: {"success":false,"result":[],"messages":[],"error":[{"code":7003,"message":"Model execution failed (User Input Error): \"thinking.type.enabled\" is not supported for this model. Use \"thinking.type.adaptive\" and \"output_config.effort\" to control thinking behavior."}] ...}
Expected Behavior
streamCloudflareAnthropicAi should check compat.forceAdaptiveThinking the same way the other two paths in this file already do, and send thinking.type.adaptive plus output_config.effort for models that need it.
Steps to Reproduce
- In a Cloudflare-target Flue app with an
ai binding in wrangler.jsonc, define an agent:
'use agent';
import { useModel } from '@flue/runtime';
export function Extract() {
useModel('cloudflare/anthropic/claude-sonnet-5');
return 'Say hello.';
}
- Dispatch it against a deployed Worker with Workers AI Billing on the AI Gateway set to Unified billing, so a 402 billing error isn't muddying the picture.
- Watch it 400 with the error above. It never completes.
Workaround
Turning off thinking entirely dodges the bad payload, at the cost of losing extended thinking for this model:
useModel('cloudflare/anthropic/claude-sonnet-5', { thinkingLevel: 'off' });
Describe the Bug
streamCloudflareAnthropicAiin@flue/runtime'sdist/cloudflare/workers-ai-provider.mjsalways sets:That sends Anthropic's older budget-based
thinking.type.enabledshape. Some models need Anthropic's newer adaptive-thinking API instead (thinking.type.adaptiveplusoutput_config.effort), and for those, this fails every time.claude-sonnet-5is one of them. It's registered in@earendil-works/pi-ai's model catalog (dist/providers/data/anthropic.json) with"compat":{"forceAdaptiveThinking":true}. The other two code paths in the same file, the direct Anthropic API path andstreamCloudflareResponsesAi/applyResponsesReasoning, both check that flag correctly. Only the Cloudflare AI Gateway path for Anthropic models skips it.Here's what actually comes back, calling
useModel('cloudflare/anthropic/claude-sonnet-5')through the Cloudflareenv.AIbinding:Expected Behavior
streamCloudflareAnthropicAishould checkcompat.forceAdaptiveThinkingthe same way the other two paths in this file already do, and sendthinking.type.adaptiveplusoutput_config.effortfor models that need it.Steps to Reproduce
aibinding inwrangler.jsonc, define an agent:Workaround
Turning off thinking entirely dodges the bad payload, at the cost of losing extended thinking for this model: