Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai): make chat({ stream: false }) actually non-streaming on the wire #561

Closedtombeckenhamwants to merge 1 commit intomain from557-chat-stream-false-still-streams-on-the-wire-uses-runstreamingtext-+-streamtotextopened View on GitHub

tombeckenhamcommented

Closes #557.

Summary

  • Adds optional TextAdapter.chatNonStreaming() returning Promise<NonStreamingChatResult> ({ content, reasoning?, toolCalls?, finishReason?, usage? }). When implemented, chat({ stream: false }) routes through it for a true wire-level non-streaming request; when omitted, the legacy stream-then-concatenate fallback applies — out-of-tree adapters keep working unchanged.
  • Implements chatNonStreaming() on all in-tree adapters: openai-base chat-completions + responses (covers openai, grok, groq), openrouter (chat-completions + responses), anthropic, gemini, ollama.
  • Rewires runNonStreamingText as a wire-level non-streaming agent loop: call adapter → execute returned tool calls server-side → append results → repeat until finishReason !== 'tool_calls' or agentLoopStrategy halts. Approval-required and pure client-side tools throw an explicit error directing callers to streaming, since they can't round-trip through Promise<string>.

Why

Previously chat({ stream: false }) invoked runStreamingText() and concatenated the SSE response via streamToText. The wire request still carried Accept: text/event-stream and "stream": true in the body — only the SDK return type changed (Promise<string> instead of AsyncIterable<StreamChunk>). On reasoning models with long pre-content thinking phases (Grok 4.3 via OpenRouter was the original repro), proxies with sub-30s socket-idle timeouts could cut off the stream mid-flight even though a real non-streaming POST would complete fine.

Test plan

  • Unit: 5 new tests covering wire-level dispatch, multi-turn tool loop, agentLoopStrategy cap, approval-tool error, and out-of-tree fallback. Existing 757 tests still pass (762 total).
  • E2E: rewired api.chat.ts so feature === 'one-shot-text' actually calls chat({ stream: false }). The existing one-shot-text.spec.ts now runs end-to-end against the new path across all 8 providers (openai, anthropic, gemini, ollama, groq, grok, openrouter, openrouter-responses). Updated the aimock fixture to include systemFingerprint: null so OpenRouter SDK's strict zod validation accepts the response. Full e2e suite (190 tests) passes.
  • pnpm test:lib, pnpm test:types, pnpm test:eslint, pnpm build: all clean.

Notes

  • Marked draft per author's request — wants more review before merging.
  • Middleware is intentionally not invoked on the non-streaming path, mirroring the silence of the existing adapter.structuredOutput call inside runAgenticStructuredOutput.
  • The Promise<string> return value remains content-only — reasoning is captured on the internal NonStreamingChatResult for future surfaces but is not part of the public contract.

🤖 Generated with Claude Code

    1. 🚀 Changeset Version Preview

      9 package(s) bumped directly, 25 bumped as dependents.

      🟥 Major bumps

      PackageVersionReason
      @tanstack/ai-anthropic0.8.7 → 1.0.0Changeset
      @tanstack/ai-gemini0.10.4 → 1.0.0Changeset
      @tanstack/ai-grok0.8.0 → 1.0.0Changeset
      @tanstack/ai-groq0.2.0 → 1.0.0Changeset
      @tanstack/ai-ollama0.6.14 → 1.0.0Changeset
      @tanstack/ai-openai0.9.0 → 1.0.0Changeset
      @tanstack/ai-openrouter0.9.0 → 1.0.0Changeset
      @tanstack/openai-base0.3.0 → 1.0.0Changeset
      @tanstack/ai-code-mode0.1.11 → 1.0.0Dependent
      @tanstack/ai-code-mode-skills0.1.11 → 1.0.0Dependent
      @tanstack/ai-elevenlabs0.2.4 → 1.0.0Dependent
      @tanstack/ai-event-client0.3.1 → 1.0.0Dependent
      @tanstack/ai-fal0.7.4 → 1.0.0Dependent
      @tanstack/ai-isolate-node0.1.11 → 1.0.0Dependent
      @tanstack/ai-isolate-quickjs0.1.11 → 1.0.0Dependent
      @tanstack/ai-preact0.6.23 → 1.0.0Dependent
      @tanstack/ai-react0.9.0 → 1.0.0Dependent
      @tanstack/ai-react-ui0.6.4 → 1.0.0Dependent
      @tanstack/ai-solid0.8.0 → 1.0.0Dependent
      @tanstack/ai-solid-ui0.6.4 → 1.0.0Dependent
      @tanstack/ai-svelte0.8.0 → 1.0.0Dependent
      @tanstack/ai-vue0.8.0 → 1.0.0Dependent

      🟨 Minor bumps

      PackageVersionReason
      @tanstack/ai0.17.0 → 0.18.0Changeset

      🟩 Patch bumps

      PackageVersionReason
      @tanstack/ai-client0.9.2 → 0.9.3Dependent
      @tanstack/ai-code-mode-models-eval0.0.16 → 0.0.17Dependent
      @tanstack/ai-devtools-core0.3.28 → 0.3.29Dependent
      @tanstack/ai-isolate-cloudflare0.2.2 → 0.2.3Dependent
      @tanstack/ai-vue-ui0.1.34 → 0.1.35Dependent
      @tanstack/preact-ai-devtools0.1.32 → 0.1.33Dependent
      @tanstack/react-ai-devtools0.2.32 → 0.2.33Dependent
      @tanstack/solid-ai-devtools0.2.32 → 0.2.33Dependent
      ts-svelte-chat0.1.42 → 0.1.43Dependent
      ts-vue-chat0.1.42 → 0.1.43Dependent
      vanilla-chat0.0.38 → 0.0.39Dependent
    2. View your CI Pipeline Execution ↗ for commit 02e47658eb363d66c72c548128f28343ca77fa24

      CommandStatusDurationResult
      nx run-many --targets=build --exclude=examples/**✅ Succeeded1m 52sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-05-15 00:13:45 UTC

    3. Open in StackBlitz

      @tanstack/ai

      npm i https://pkg.pr.new/@tanstack/ai@561

      @tanstack/ai-anthropic

      npm i https://pkg.pr.new/@tanstack/ai-anthropic@561

      @tanstack/ai-client

      npm i https://pkg.pr.new/@tanstack/ai-client@561

      @tanstack/ai-code-mode

      npm i https://pkg.pr.new/@tanstack/ai-code-mode@561

      @tanstack/ai-code-mode-skills

      npm i https://pkg.pr.new/@tanstack/ai-code-mode-skills@561

      @tanstack/ai-devtools-core

      npm i https://pkg.pr.new/@tanstack/ai-devtools-core@561

      @tanstack/ai-elevenlabs

      npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@561

      @tanstack/ai-event-client

      npm i https://pkg.pr.new/@tanstack/ai-event-client@561

      @tanstack/ai-fal

      npm i https://pkg.pr.new/@tanstack/ai-fal@561

      @tanstack/ai-gemini

      npm i https://pkg.pr.new/@tanstack/ai-gemini@561

      @tanstack/ai-grok

      npm i https://pkg.pr.new/@tanstack/ai-grok@561

      @tanstack/ai-groq

      npm i https://pkg.pr.new/@tanstack/ai-groq@561

      @tanstack/ai-isolate-cloudflare

      npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@561

      @tanstack/ai-isolate-node

      npm i https://pkg.pr.new/@tanstack/ai-isolate-node@561

      @tanstack/ai-isolate-quickjs

      npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@561

      @tanstack/ai-ollama

      npm i https://pkg.pr.new/@tanstack/ai-ollama@561

      @tanstack/ai-openai

      npm i https://pkg.pr.new/@tanstack/ai-openai@561

      @tanstack/ai-openrouter

      npm i https://pkg.pr.new/@tanstack/ai-openrouter@561

      @tanstack/ai-preact

      npm i https://pkg.pr.new/@tanstack/ai-preact@561

      @tanstack/ai-react

      npm i https://pkg.pr.new/@tanstack/ai-react@561

      @tanstack/ai-react-ui

      npm i https://pkg.pr.new/@tanstack/ai-react-ui@561

      @tanstack/ai-solid

      npm i https://pkg.pr.new/@tanstack/ai-solid@561

      @tanstack/ai-solid-ui

      npm i https://pkg.pr.new/@tanstack/ai-solid-ui@561

      @tanstack/ai-svelte

      npm i https://pkg.pr.new/@tanstack/ai-svelte@561

      @tanstack/ai-utils

      npm i https://pkg.pr.new/@tanstack/ai-utils@561

      @tanstack/ai-vue

      npm i https://pkg.pr.new/@tanstack/ai-vue@561

      @tanstack/ai-vue-ui

      npm i https://pkg.pr.new/@tanstack/ai-vue-ui@561

      @tanstack/openai-base

      npm i https://pkg.pr.new/@tanstack/openai-base@561

      @tanstack/preact-ai-devtools

      npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@561

      @tanstack/react-ai-devtools

      npm i https://pkg.pr.new/@tanstack/react-ai-devtools@561

      @tanstack/solid-ai-devtools

      npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@561

      commit: 02e4765

    4. I've looked into this a lot more. There are a tonne of restrictions when running non-streaming ai calls - particularly with anthropic. Given the amount of duplication we'd have to introduce to properly make non-streaming on the wire work, I don't think this is worth it @AlemTuzlak and @jherr . I'm closing this one as a not planned

    5. tombeckenham closed this

Sign in to join this conversation.