Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

README.md

157 lines6.4 KB

1<div align="center">
2 <img src="./media/header_ai.png" >
3</div>
4​
5<br />
6​
7<div align="center">
8<a href="https://npmjs.com/package/@tanstack/ai" target="\_parent">
9 <img alt="" src="https://img.shields.io/npm/dm/@tanstack/ai.svg" />
10</a>
11<a href="https://github.com/TanStack/ai" target="\_parent">
12 <img alt="" src="https://img.shields.io/github/stars/TanStack/ai.svg?style=social&label=Star" alt="GitHub stars" />
13</a>
14<a href="https://bundlephobia.com/result?p=@tanstack/ai@latest" target="\_parent">
15 <img alt="" src="https://badgen.net/bundlephobia/minzip/@tanstack/ai@latest" />
16</a>
17</div>
18​
19<div align="center">
20<a href="#badge">
21 <img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
22</a>
23 <a href="#badge">
24 <img src="https://img.shields.io/github/v/release/tanstack/ai" alt="Release"/>
25 </a>
26<a href="https://twitter.com/tan_stack">
27 <img src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social" alt="Follow @TanStack"/>
28</a>
29</div>
30​
31<div align="center">
33### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/)
34</div>
35​
36# TanStack AI
37​
38A powerful, type-safe AI SDK for building AI-powered applications.
39​
40- Provider-agnostic adapters (OpenAI, Anthropic, Gemini, Ollama, etc.)
41- **Tree-shakeable adapters** - Import only what you need for smaller bundles
42- **Multimodal content support** - Send images, audio, video, and documents
43- **Image generation** - Generate images with OpenAI DALL-E/GPT-Image and Gemini Imagen
44- Chat completion, streaming, and agent loop strategies
45- Headless chat state management with adapters (SSE, HTTP stream, custom)
46- Isomorphic type-safe tools with server/client execution
47- **Enhanced integration with TanStack Start** - Share implementations between AI tools and server functions
48​
49### <a href="https://tanstack.com/ai">Read the docs →</b></a>
50​
51## Tree-Shakeable Adapters
52​
53Import only the functionality you need for smaller bundle sizes:
54​
55```typescript
56// Only chat functionality - no summarization code bundled
57import { openaiText } from '@tanstack/ai-openai/adapters'
58import { generate } from '@tanstack/ai'
59​
60const textAdapter = openaiText()
61​
62const result = generate({
63 adapter: textAdapter,
64 model: 'gpt-4o',
65 messages: [{ role: 'user', content: [{ type: 'text', content: 'Hello!' }] }],
66})
67​
68for await (const chunk of result) {
69 console.log(chunk)
71```
72​
73Available adapters: `openaiText`, `openaiEmbed`, `openaiSummarize`, `anthropicText`, `geminiText`, `ollamaText`, and more.
74​
75## Bonus: TanStack Start Integration
76​
77TanStack AI works with **any** framework (Next.js, Express, Remix, etc.).
78​
79**With TanStack Start**, you get a bonus: share implementations between AI tools and server functions with `createServerFnTool`:
80​
81```typescript
82import { createServerFnTool } from '@tanstack/ai-react'
83​
84// Define once, get AI tool AND server function (TanStack Start only)
85const getProducts = createServerFnTool({
86 name: 'getProducts',
87 inputSchema: z.object({ query: z.string() }),
88 execute: async ({ query }) => db.products.search(query),
89})
90​
91// Use in AI chat
92chat({ tools: [getProducts.server] })
93​
94// Call directly from components (no API endpoint needed!)
95const products = await getProducts.serverFn({ query: 'laptop' })
96```
97​
98No duplicate logic, full type safety, automatic validation. The `serverFn` feature requires TanStack Start. See [docs](https://tanstack.com/ai) for details.
99​
100## Get Involved
101​
102- We welcome issues and pull requests!
103- Participate in [GitHub discussions](https://github.com/TanStack/ai/discussions)
104- Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ)
105- See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions
106​
107## Partners
108​
109<table align="center">
110 <tr>
111 <td>
112 <a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS" >
113 <picture>
114 <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-CMcuvjEy.svg" height="40" />
115 <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" />
116 <img src="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" alt="CodeRabbit" />
117 </picture>
118 </a>
119 </td>
120 <td>
121 <a href="https://www.cloudflare.com?utm_source=tanstack">
122 <picture>
123 <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-DQDB7UaL.svg" height="60" />
124 <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" />
125 <img src="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" alt="Cloudflare" />
126 </picture>
127 </a>
128 </td>
129 </tr>
130</table>
131​
132<div align="center">
133<img src="./media/partner_logo.svg" alt="AI & you?" height="65">
134<p>
135We're looking for TanStack AI Partners to join our mission! Partner with us to push the boundaries of TanStack AI and build amazing things together.
136</p>
137<a href="mailto:partners@tanstack.com?subject=TanStack AI Partnership"><b>LET'S CHAT</b></a>
138</div>
139​
140## Explore the TanStack Ecosystem
141​
142- <a href="https://github.com/tanstack/config"><b>TanStack Config</b></a> – Tooling for JS/TS packages
143- <a href="https://github.com/tanstack/db"><b>TanStack DB</b></a> – Reactive sync client store
144- <a href="https://github.com/tanstack/devtools"><b>TanStack Devtools</b></a> – Unified devtools panel
145- <a href="https://github.com/tanstack/form"><b>TanStack Form</b></a> – Type‑safe form state
146- <a href="https://github.com/tanstack/pacer"><b>TanStack Pacer</b></a> – Debouncing, throttling, batching
147- <a href="https://github.com/tanstack/query"><b>TanStack Query</b></a> – Async state & caching
148- <a href="https://github.com/tanstack/ranger"><b>TanStack Ranger</b></a> – Range & slider primitives
149- <a href="https://github.com/tanstack/router"><b>TanStack Router</b></a> – Type‑safe routing, caching & URL state
150- <a href="https://github.com/tanstack/router"><b>TanStack Start</b></a> – Full‑stack SSR & streaming
151- <a href="https://github.com/tanstack/store"><b>TanStack Store</b></a> – Reactive data store
152- <a href="https://github.com/tanstack/table"><b>TanStack Table</b></a> – Headless datagrids
153- <a href="https://github.com/tanstack/virtual"><b>TanStack Virtual</b></a> – Virtualized rendering
154​
155… and more at <a href="https://tanstack.com"><b>TanStack.com »</b></a>
156​
157<!-- USE THE FORCE LUKE -->