Repository navigation
@tanstack/ai-cloudflare@0.3.0
Minor Changes
-
#1721
4069e0e- AddcloudflareBindingFetch({ binding, vendor, gateway }). It sends the requests of the Anthropic and OpenAI text adapters (createAnthropicChat,createOpenaiChat) through the Workers AI binding (env.AI.run) to the AI Gatewayanthropic/...andopenai/...models, so a Worker can use Claude and GPT with no provider key.vendor: 'anthropic'carries Anthropic Messages requests, andvendor: 'openai'carries OpenAI Responses requests.- The request body goes to
env.AI.run('<vendor>/<model>', body). Headers such asanthropic-betago along asextraHeaders, and the SDK's auth and transport headers are dropped. - A Cloudflare error body is rewrapped so the SDK reports its message.
-
#1739
a0150c2- Text adapters now set one stable code onRUN_ERRORwhen the input does not fit in the model's context window:code: 'context_overflow'.@tanstack/aiexports it asCONTEXT_OVERFLOW_CODE. The provider's own text stays inmessage.if (chunk.type === 'RUN_ERROR' && chunk.code === CONTEXT_OVERFLOW_CODE) { // shorten the messages, then call chat() again }
These adapters set it: OpenAI and the other OpenAI-compatible adapters (from
code: 'context_length_exceeded'), Anthropic, Gemini, Bedrock (Converse, Chat Completions, and Responses), OpenRouter, Grok, Cloudflare Workers AI, and BytePlus.Changes to code that reads the old values:
- OpenAI-compatible adapters gave
code: 'context_length_exceeded'. They now give'context_overflow'.rawEventstill has the provider's code. - Anthropic, Grok, OpenRouter, and BytePlus gave the HTTP status or a general bad-request code for this error. Gemini and Bedrock Converse gave no code.
- The Anthropic adapter now sends
RUN_ERRORwith this code when the model stops withstop_reason: 'model_context_window_exceeded'. Before, it sentRUN_FINISHEDwithfinishReason: 'stop', so a cut-off answer looked complete.
- OpenAI-compatible adapters gave
-
#1692
7532b2b- Set reasoning withchat({ reasoning }).- The adapter sends
reasoning_effort, andnullforoff. - The reasoning data is in
utils/models.ts, keyed by model id.CloudflareModelReasoningByNameandCLOUDFLARE_MODEL_REASONINGcome from it. chat_template_kwargsstays inmodelOptions. It picks the output format, not the effort.
Breaking:
reasoning_effortis no longer inmodelOptions.// Before chat({ adapter: cloudflareText('@cf/zai-org/glm-5.3'), messages, modelOptions: { reasoning_effort: 'low' }, }) // After chat({ adapter: cloudflareText('@cf/zai-org/glm-5.3'), messages, reasoning: 'low', })
- The adapter sends
Patch Changes
- Updated dependencies [
1bfcee3,b881627,412b0fe,a0150c2,20954cc,b881627,fac0555,6774e80,5bd27f2,c20f7b0,cef1911,51f72fb,6f1e559,eb4eea0,cef1911,7532b2b,7532b2b,1bfcee3,78edeb2,44e3a0a,7532b2b,ce99a17,7a5c0d6,b881627]:- @tanstack/ai@0.69.0
- @tanstack/openai-base@0.14.0
- @tanstack/ai-utils@0.4.2