cloudflare / cloudflare/ai

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

Open Beginner friendly
#577 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.2k
Forks
345
Avg merge
13h 31m
Merged PRs (30d)
1

Description

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()`.

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

Contributor guide

Open the contributing guide

Research direction

Start at createWorkersAiBindingFetch in @cloudflare/tanstack-ai and trace how chat() inputs reach binding.run(). Verify the adapter's empty-tools path for Gemma 4 and Qwen models, then confirm that calls with no tools omit the tools property and no longer produce the reported connection error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.