tanstack-ai

Implements provider-agnostic AI streaming, tool calling, and structured output with TanStack AI.

Updated Feb 27, 2026
One-click install
npx skills add https://github.com/firstaxel/neon --skill tanstack-ai-firstaxel
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: tanstack-ai
Source: https://github.com/firstaxel/neon/tree/main/.agents/skills/tanstack-ai
Command: npx skills add https://github.com/firstaxel/neon --skill tanstack-ai-firstaxel

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building AI features across multiple LLM providers requires rewriting integration code for each vendor's API, handling streaming inconsistently, and losing type safety on structured responses. This Skill provides a unified, type-safe SDK layer for text generation, tool calling, and multimodal content across OpenAI, Anthropic, Gemini, and Ollama. ## Core Features & Use Cases - Provider-Agnostic Generation: Use a single generate() API with tree-shakeable adapters for OpenAI, Anthropic, Gemini, and Ollama, with runtime adapter switching. - Streaming & Structured Output: Stream responses with async iteration and enforce Zod-schema-typed structured output, including partial JSON parsing during streaming. - Tool Calling & Agentic Loops: Define tools with approval workflows and bounded agent loops via maxIterations. - Framework Hooks: Build chat and completion UIs with useChat/useCompletion for React, createChat for Solid, or a framework-agnostic vanilla client. - Use Case: Build a TanStack Start chat endpoint that streams GPT-4o responses through a server function, keeps API keys server-side, and renders the conversation with useChat in a React component. ## Quick Start Ask the AI to create a streaming chat endpoint using @tanstack/ai with the OpenAI adapter and wire it to a React useChat component.

Frequently Asked Questions about tanstack-ai

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stream AI responses with TanStack AI?▼

Call generate() with an adapter and messages, then iterate the result with for await to process each chunk. You can also use createReplayStream to serve chunks as Server-Sent Events from an endpoint.

How do I switch between OpenAI and Anthropic providers?▼

Import the matching adapter such as openaiText or anthropicText and pass it to generate(). Because the API is provider-agnostic, you can select the adapter at runtime based on an environment variable without changing other code.

Does TanStack AI support structured output with Zod?▼

Yes, convert a Zod schema with convertZodToJsonSchema and pass it as the schema option to generate(). The result is typed as z.infer of your schema, and parsePartialJson handles incomplete JSON during streaming.

Can I use TanStack AI without React?▼

Yes, use @tanstack/ai-client for a framework-agnostic vanilla client with subscribe, send, and clear methods, or @tanstack/ai-solid for Solid.js. PHP and Python packages are also available.

How do I prevent runaway agent loops with tool calling?▼

Set the maxIterations option on generate() to cap agent loop iterations. For destructive tools, set requiresApproval: true and handle confirmation through ToolCallManager's onApprovalRequired callback.

Why should API keys not be used in client-side TanStack AI code?▼

Client-side code exposes keys to anyone inspecting the browser bundle. The recommended pattern is calling generate() inside a TanStack Start server function so credentials stay on the server.