Skip to content

@cloudflare/tanstack-ai adapter fails with "Connection error" on Gemma 4 / Qwen models when tools array is empty #577

Description

@imab001

When using chat() from @tanstack/ai with createWorkersAiChat from @cloudflare/tanstack-ai and providing no tools, the underlying stream crashes and falls back to non-streaming, which also crashes.

Root Cause:
@tanstack/ai defaults to passing tools: [] into the adapter when no tools are configured. The @cloudflare/tanstack-ai adapter maps this directly to env.AI.run(model, { tools: [] }).

Models like @cf/google/gemma-4-26b-a4b-it and @cf/qwen/qwen3-30b-a3b-fp8 run on vLLM, which strictly rejects tools: [] with an HTTP 400 error:

Value error, 'tools' must not be an empty array. Either provide at least one tool or omit the field entirely.

This causes env.AI.run to throw a connection error in streaming mode, and the fallback non-streaming request immediately throws the same error.

Proposed Fix:
In @cloudflare/tanstack-ai, the createWorkersAiBindingFetch (or adapter parsing logic) should delete the tools property if it receives an empty array before calling binding.run().

 if (inputs && Array.isArray(inputs.tools) && inputs.tools.length === 0) {
     delete inputs.tools;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions