Skip to content

@tanstack/ai-cloudflare@0.3.0

Choose a tag to compare

@github-actions github-actions released this 13 Oct 17:47
· 149 commits to main since this release
Immutable release. Only release title and notes can be modified.
293aea9

Minor Changes

  • #1721 4069e0e - Add cloudflareBindingFetch({ 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 Gateway anthropic/... and openai/... models, so a Worker can use Claude and GPT with no provider key.

    • vendor: 'anthropic' carries Anthropic Messages requests, and vendor: 'openai' carries OpenAI Responses requests.
    • The request body goes to env.AI.run('<vendor>/<model>', body). Headers such as anthropic-beta go along as extraHeaders, 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 on RUN_ERROR when the input does not fit in the model's context window: code: 'context_overflow'. @tanstack/ai exports it as CONTEXT_OVERFLOW_CODE. The provider's own text stays in message.

    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'. rawEvent still 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_ERROR with this code when the model stops with stop_reason: 'model_context_window_exceeded'. Before, it sent RUN_FINISHED with finishReason: 'stop', so a cut-off answer looked complete.
  • #1692 7532b2b - Set reasoning with chat({ reasoning }).

    • The adapter sends reasoning_effort, and null for off.
    • The reasoning data is in utils/models.ts, keyed by model id. CloudflareModelReasoningByName and CLOUDFLARE_MODEL_REASONING come from it.
    • chat_template_kwargs stays in modelOptions. It picks the output format, not the effort.

    Breaking: reasoning_effort is no longer in modelOptions.

    // 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',
    })

Patch Changes