@amjadiqbal/tanstack-ai-sdk-bridge 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@amjadiqbal/tanstack-ai-sdk-bridge` are documented here.
4
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses [Semantic Versioning](https://semver.org/).
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [0.1.0] - 2026-10-23
9
+
10
+ ### Added
11
+
12
+ - `aiSdkText()`: AI SDK language models as TanStack AI text adapters, with streaming text, tool calls, reasoning, structured output, token usage and abort.
13
+ - `aiSdkEmbedding()`, `aiSdkTranscription()`, `aiSdkSpeech()`, `aiSdkImage()` and `aiSdkRerank()` for the other AI SDK model kinds.
14
+ - Support for AI SDK provider spec v2, v3 and v4 (AI SDK 5, 6 and 7 providers).
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Amjad Iqbal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,245 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="art/banner-dark.png">
4
+ <img alt="AI SDK Bridge: any Vercel AI SDK provider as a TanStack AI adapter" src="art/banner-light.png" width="100%">
5
+ </picture>
6
+ </p>
2
7
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
8
+ # TanStack AI SDK Bridge: use Vercel AI SDK providers with TanStack AI
9
+
10
+ Use any Vercel AI SDK provider (`@ai-sdk/*` and community providers) as a [TanStack AI](https://tanstack.com/ai) adapter. The bridge reads the AI SDK provider spec (v2, v3 and v4), so a provider package works with `chat()`, `embed()`, `generateTranscription()`, `generateSpeech()`, `generateImage()` and `rerank()` without a dedicated TanStack adapter. It is also the shortest path for moving an AI SDK app to TanStack AI: keep your provider setup and change the rest step by step.
11
+
12
+ Tested with: `@ai-sdk/deepseek`, `@ai-sdk/anthropic`, `@ai-sdk/openai`, `@ai-sdk/togetherai`, `@ai-sdk/cerebras`, `@ai-sdk/fireworks`, `@ai-sdk/cohere` (rerank), `ollama-ai-provider-v2` and `@ai-sdk/openai-compatible` 1.x, 2.x and 3.x (AI SDK 5, 6 and 7). See [What is tested](#what-is-tested).
13
+
14
+ [![npm](https://img.shields.io/npm/v/@amjadiqbal/tanstack-ai-sdk-bridge?style=flat-square)](https://www.npmjs.com/package/@amjadiqbal/tanstack-ai-sdk-bridge)
15
+ [![TanStack AI](https://img.shields.io/badge/TanStack%20AI-1.x-8B5CF6?style=flat-square)](https://tanstack.com/ai)
16
+ [![License](https://img.shields.io/npm/l/@amjadiqbal/tanstack-ai-sdk-bridge?style=flat-square)](LICENSE.md)
17
+
18
+ ```ts
19
+ import { chat } from '@tanstack/ai'
20
+ import { aiSdkText } from '@amjadiqbal/tanstack-ai-sdk-bridge'
21
+ import { deepseek } from '@ai-sdk/deepseek'
22
+
23
+ const stream = chat({
24
+ adapter: aiSdkText(deepseek('deepseek-chat')),
25
+ messages: [{ role: 'user', content: 'Hello!' }],
26
+ threadId: 'thread-1',
27
+ })
28
+ ```
29
+
30
+ - **Text**: streaming chat, tool calls (TanStack's agent loop runs your tools), reasoning, structured output (`outputSchema`), token usage, abort.
31
+ - **Embeddings, transcription, speech, image generation, rerank**: one adapter function each.
32
+ - **AI SDK 5, 6 and 7 providers**: provider spec v2, v3 and v4 are all read.
33
+ - **No extra runtime code from AI SDK**: only the provider package you already use, plus `@ai-sdk/provider` types. No `ai` package needed.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ npm i @amjadiqbal/tanstack-ai-sdk-bridge @tanstack/ai
39
+ ```
40
+
41
+ Then the AI SDK provider you want, for example `npm i @ai-sdk/deepseek`. Requires `@tanstack/ai` 1.x and Node 20+.
42
+
43
+ ## Usage
44
+
45
+ ### Chat with a TanStack Start (or any Fetch API) route
46
+
47
+ ```ts
48
+ // src/routes/api/chat.ts
49
+ import { createFileRoute } from '@tanstack/react-router'
50
+ import { chat, toServerSentEventsResponse } from '@tanstack/ai'
51
+ import { aiSdkText } from '@amjadiqbal/tanstack-ai-sdk-bridge'
52
+ import { createDeepSeek } from '@ai-sdk/deepseek'
53
+
54
+ const deepseek = createDeepSeek({ apiKey: process.env.DEEPSEEK_API_KEY })
55
+
56
+ export const Route = createFileRoute('/api/chat')({
57
+ server: {
58
+ handlers: {
59
+ POST: async ({ request }) => {
60
+ const { messages, threadId } = await request.json()
61
+ const stream = chat({
62
+ adapter: aiSdkText(deepseek('deepseek-chat')),
63
+ messages,
64
+ threadId,
65
+ systemPrompts: ['You are a helpful assistant.'],
66
+ modelOptions: { temperature: 0.3, maxOutputTokens: 1024 },
67
+ })
68
+ return toServerSentEventsResponse(stream)
69
+ },
70
+ },
71
+ },
72
+ })
73
+ ```
74
+
75
+ The client is plain TanStack AI; nothing from this package runs in the browser:
76
+
77
+ ```tsx
78
+ import { useChat, fetchServerSentEvents } from '@tanstack/ai-react'
79
+
80
+ const { messages, sendMessage, isLoading, stop } = useChat({
81
+ connection: fetchServerSentEvents('/api/chat'),
82
+ })
83
+ ```
84
+
85
+ ### Tools
86
+
87
+ Tools are TanStack AI tools. The bridge sends their JSON Schema to the AI SDK model and streams the calls back, and `chat()` runs them.
88
+
89
+ ```ts
90
+ import { chat, toolDefinition } from '@tanstack/ai'
91
+ import { z } from 'zod'
92
+
93
+ const getWeather = toolDefinition({
94
+ name: 'getWeather',
95
+ description: 'Get the weather for a city',
96
+ inputSchema: z.object({ city: z.string() }),
97
+ }).server(async ({ city }) => ({ city, tempC: 21 }))
98
+
99
+ chat({ adapter: aiSdkText(deepseek('deepseek-chat')), messages, threadId, tools: [getWeather] })
100
+ ```
101
+
102
+ ### Structured output
103
+
104
+ ```ts
105
+ const product = await chat({
106
+ adapter: aiSdkText(deepseek('deepseek-chat')),
107
+ messages: [{ role: 'user', content: 'Invent a product.' }],
108
+ threadId: 'product-1',
109
+ outputSchema: z.object({ name: z.string(), price: z.number() }),
110
+ stream: false,
111
+ })
112
+ // product: { name: string; price: number }
113
+ ```
114
+
115
+ The bridge asks the model for JSON with the schema (AI SDK `responseFormat: { type: 'json', schema }`) and TanStack AI validates the result. A JSON answer wrapped in a Markdown code fence is also accepted.
116
+
117
+ ### Reasoning
118
+
119
+ `chat({ reasoning: 'high' })` sets the AI SDK `reasoning` call option on AI SDK 7 (spec v4) models, and reasoning deltas stream as TanStack reasoning events. `'off'` becomes `'none'`. For AI SDK 5 and 6 providers, set reasoning in `modelOptions.providerOptions` the way that provider documents it.
120
+
121
+ ### Model options
122
+
123
+ `modelOptions` takes the AI SDK call settings and passes them through:
124
+
125
+ | Option | AI SDK call option |
126
+ |---|---|
127
+ | `temperature`, `topP`, `topK`, `presencePenalty`, `frequencyPenalty`, `seed`, `stopSequences`, `maxOutputTokens` | same name |
128
+ | `providerOptions` | `providerOptions`, e.g. `{ deepseek: { ... } }` |
129
+ | `headers` | `headers` |
130
+
131
+ ### Embeddings
132
+
133
+ ```ts
134
+ import { embed } from '@tanstack/ai'
135
+ import { aiSdkEmbedding } from '@amjadiqbal/tanstack-ai-sdk-bridge'
136
+ import { openai } from '@ai-sdk/openai'
137
+
138
+ const { embeddings } = await embed({
139
+ adapter: aiSdkEmbedding(openai.embedding('text-embedding-3-small')),
140
+ input: ['red guitar', 'blue drum kit'],
141
+ })
142
+ ```
143
+
144
+ Large inputs are split by the model's `maxEmbeddingsPerCall`. `dimensions` works with AI SDK 7 models; older ones take it through `modelOptions.providerOptions`.
145
+
146
+ ### Transcription, speech, image, rerank
147
+
148
+ ```ts
149
+ import { generateImage, generateSpeech, generateTranscription, rerank } from '@tanstack/ai'
150
+ import { aiSdkImage, aiSdkRerank, aiSdkSpeech, aiSdkTranscription } from '@amjadiqbal/tanstack-ai-sdk-bridge'
151
+
152
+ import { openai } from '@ai-sdk/openai'
153
+ import { cohere } from '@ai-sdk/cohere'
154
+
155
+ const threadId = 'media-1'
156
+ await generateTranscription({ threadId, adapter: aiSdkTranscription(openai.transcription('whisper-1')), audio: file })
157
+ await generateSpeech({ threadId, adapter: aiSdkSpeech(openai.speech('gpt-4o-mini-tts')), text: 'Hello', voice: 'alloy' })
158
+ await generateImage({ threadId, adapter: aiSdkImage(openai.image('gpt-image-1')), prompt: 'a lighthouse at dusk' })
159
+ await rerank({ adapter: aiSdkRerank(cohere.reranking('rerank-v3.5')), query: 'refund policy', documents })
160
+ ```
161
+
162
+ | TanStack AI | Bridge | AI SDK model | Spec versions |
163
+ |---|---|---|---|
164
+ | `chat()` | `aiSdkText(model)` | `LanguageModel` | v2, v3, v4 |
165
+ | `embed()` | `aiSdkEmbedding(model)` | `EmbeddingModel` | v2, v3, v4 |
166
+ | `generateTranscription()` | `aiSdkTranscription(model)` | `TranscriptionModel` | v2, v3, v4 |
167
+ | `generateSpeech()` | `aiSdkSpeech(model)` | `SpeechModel` | v2, v3, v4 |
168
+ | `generateImage()` | `aiSdkImage(model)` | `ImageModel` | v2, v3, v4 |
169
+ | `rerank()` | `aiSdkRerank(model)` | `RerankingModel` | v3, v4 |
170
+
171
+ Every function takes an optional second argument `{ name }`, the adapter name TanStack AI shows in devtools and usage. It defaults to the provider id before the first dot (`deepseek.chat` becomes `deepseek`).
172
+
173
+ ## Migrating from the Vercel AI SDK
174
+
175
+ TanStack's own [migration guide](https://tanstack.com/ai/latest/docs/migration/migration-from-vercel-ai) swaps your provider packages for TanStack adapters. With the bridge you can skip that step, and keep providers that have no TanStack adapter:
176
+
177
+ | Vercel AI SDK | TanStack AI with the bridge |
178
+ |---|---|
179
+ | `streamText({ model: deepseek('deepseek-chat'), ... })` | `chat({ adapter: aiSdkText(deepseek('deepseek-chat')), ... })` |
180
+ | `generateText(...)` | `chat({ ..., stream: false })` |
181
+ | `generateObject({ schema })` | `chat({ ..., outputSchema })` |
182
+ | `embedMany({ model: openai.embedding(...) })` | `embed({ adapter: aiSdkEmbedding(openai.embedding(...)) })` |
183
+ | `transcribe`, `generateSpeech`, `generateImage`, `rerank` | `generateTranscription`, `generateSpeech`, `generateImage`, `rerank` with the matching `aiSdk*` adapter |
184
+ | `system: '...'` | `systemPrompts: ['...']` |
185
+ | `temperature`, `maxOutputTokens`, `providerOptions` | `modelOptions: { temperature, maxOutputTokens, providerOptions }` |
186
+ | `tool({ inputSchema, execute })` | `toolDefinition({ inputSchema }).server(execute)` |
187
+ | `useChat` from `@ai-sdk/react` | `useChat` from `@tanstack/ai-react` |
188
+ | `result.toUIMessageStreamResponse()` | `toServerSentEventsResponse(stream)` |
189
+
190
+ A practical order: move the server route and client first with the bridge, ship, then replace a bridged provider with a native TanStack adapter later if one exists and you need its typed per-model options.
191
+
192
+ ## What is tested
193
+
194
+ Everything below ran on 2026-10-23 with `@tanstack/ai` 1.0.0. **No live provider API was called and no API key was used**: the real provider packages talked HTTP to [aimock](https://github.com/CopilotKit/aimock) 1.46, a local server that speaks each provider's wire format. That covers the request and stream formats, not every model's behaviour.
195
+
196
+ | Provider package | Spec | Chat stream | Tool loop | Structured output | Other |
197
+ |---|---|---|---|---|---|
198
+ | `@ai-sdk/deepseek` 3.0 | v4 | ✓ | ✓ | ✓ | reasoning ✓ |
199
+ | `@ai-sdk/anthropic` 4.0 | v4 | ✓ | ✓ | ✓ | reasoning ✓ |
200
+ | `@ai-sdk/openai` 4.0 (Responses and Chat Completions) | v4 | ✓ | ✓ | ✓ | embeddings, image, speech, transcription ✓ |
201
+ | `@ai-sdk/togetherai` 3.0 | v4 | ✓ | ✓ | ✓ | |
202
+ | `@ai-sdk/cerebras` 3.0 | v4 | ✓ | ✓ | ✓ | |
203
+ | `@ai-sdk/fireworks` 3.0 | v4 | ✓ | ✓ | ✓ | |
204
+ | `ollama-ai-provider-v2` 4.1 | v4 | ✓ | ✓ | ✓ | |
205
+ | `@ai-sdk/cohere` 4.0 | v4 | | | | rerank ✓ |
206
+ | `@ai-sdk/openai-compatible` 3.x / 2.x / 1.x (AI SDK 7 / 6 / 5) | v4 / v3 / v2 | ✓ | ✓ | ✓ | |
207
+
208
+ - **Unit tests** run every adapter against AI SDK's own `MockLanguageModelV3/V4`, `MockEmbeddingModelV4`, `MockTranscriptionModelV4`, `MockSpeechModelV4`, `MockImageModelV4` and `MockRerankingModelV4` (from `ai/test`) and hand-written spec v2 models, through the real `chat()`, `embed()`, `generateTranscription()`, `generateSpeech()`, `generateImage()` and `rerank()`: streaming, tool calls with and without input deltas, `toolChoice`, reasoning levels, errors, abort, structured output, batching by `maxEmbeddingsPerCall` and `maxImagesPerCall`, and v2/v3/v4 file parts.
209
+ - **In a real browser**: a TanStack Start 1.169 app with `@tanstack/ai-react` `useChat`, a `/api/chat` server route as in the example above, and the packed npm tarball installed. Seen working: streamed replies through `@ai-sdk/deepseek` and `@ai-sdk/anthropic`, a server tool call and its result followed by the final answer, reasoning shown before the answer, a second turn on the same thread, the Stop button ending a stream mid-reply, structured output through both providers, and embeddings through `@ai-sdk/openai`.
210
+ - **Not tested**: live provider APIs, other AI SDK providers, Vue/Solid/Svelte clients (the bridge runs on the server, so the client framework should not matter), and Cohere chat/embeddings and Ollama embeddings (aimock's responses for those fail the providers' own validation).
211
+
212
+ ## Limits
213
+
214
+ - **Provider-executed tools** (an AI SDK provider's own web search, code execution and the like) are not forwarded; function tools are.
215
+ - **Reasoning signatures** are not sent back, so providers that need signed thinking blocks in later turns (Anthropic extended thinking with tools) receive the reasoning as plain text or drop it.
216
+ - `chat({ wrapFetch })` is not applied; pass a custom `fetch` to the provider factory (`createDeepSeek({ fetch })`).
217
+ - Provider file handles (`{ type: 'file' }` sources) are rejected; send images and documents as data or URLs.
218
+ - Transcription `language` and `prompt` have no AI SDK equivalent; pass them in `modelOptions.providerOptions`.
219
+ - AI SDK reranking models report no token usage, so `rerank()` usage is zero.
220
+ - Video, audio generation and realtime models are not bridged yet.
221
+
222
+ ## Support
223
+
224
+ - 🐛 **Bug or feature request**: [open an issue](https://github.com/amjadiqbal/tanstack-ai-sdk-bridge/issues)
225
+ - 🔒 **Security issue**: please report privately via GitHub's security tab
226
+
227
+ ## Need this built into your app, or something custom?
228
+
229
+ [Get in touch](https://amjad.com.pk/contact?utm_source=github&utm_medium=readme&utm_campaign=tanstack-ai-sdk-bridge).
230
+
231
+ [![Hire me on Upwork](https://img.shields.io/badge/Hire%20me-Upwork-6FDA44?style=flat-square&logo=upwork&logoColor=white)](https://www.upwork.com/freelancers/amjadkhatri)
232
+
233
+ ## More packages
234
+
235
+ Part of a family of open-source packages. See [all of them](https://github.com/amjadiqbal?tab=repositories).
236
+
237
+ | | |
238
+ |---|---|
239
+ | [query-key-kit](https://github.com/amjadiqbal/query-key-kit) | Typed query-key hierarchy and invalidation helpers for TanStack Query v5 |
240
+ | [start-seo-kit](https://github.com/amjadiqbal/start-seo-kit) | SEO for TanStack Start: meta tags, sitemaps, JSON-LD |
241
+ | [tanstack-table-url-state](https://github.com/amjadiqbal/tanstack-table-url-state) | URL state and CSV/XLSX export for TanStack Table |
242
+
243
+ ## License
244
+
245
+ MIT. See [LICENSE.md](LICENSE.md). Not affiliated with TanStack or Vercel; "AI SDK" and provider names are used only to say what this package works with.
@@ -0,0 +1,198 @@
1
+ import { AdapterYieldChunk, EmbeddingOptions, EmbeddingResult, ImageGenerationOptions, ImageGenerationResult, ReasoningLevel, RerankAdapterResult, RerankOptions, TTSOptions, TTSResult, TextOptions, TranscriptionOptions, TranscriptionResult } from "@tanstack/ai";
2
+ import { BaseEmbeddingAdapter, BaseImageAdapter, BaseRerankAdapter, BaseTTSAdapter, BaseTextAdapter, BaseTranscriptionAdapter, StructuredOutputOptions, StructuredOutputResult } from "@tanstack/ai/adapters";
3
+ import { EmbeddingModelV2, EmbeddingModelV3, EmbeddingModelV4, ImageModelV2, ImageModelV3, ImageModelV4, LanguageModelV2, LanguageModelV3, LanguageModelV4, RerankingModelV3, RerankingModelV4, SpeechModelV2, SpeechModelV3, SpeechModelV4, TranscriptionModelV2, TranscriptionModelV3, TranscriptionModelV4 } from "@ai-sdk/provider";
4
+ /** AI SDK provider spec versions this package reads. */
5
+ type SpecVersion = 'v2' | 'v3' | 'v4';
6
+ /** Options every bridge adapter takes besides the model. */
7
+ interface AiSdkAdapterOptions {
8
+ /**
9
+ * Adapter name shown by TanStack AI (devtools, usage, history source).
10
+ * Defaults to the first segment of the AI SDK provider id, e.g. `deepseek` for `deepseek.chat`.
11
+ */
12
+ name?: string;
13
+ }
14
+ /** Per-call options shared by every activity. `providerOptions` goes to the AI SDK model unchanged. */
15
+ interface AiSdkCallOptions {
16
+ /** AI SDK `providerOptions`, keyed by provider, e.g. `{ openai: { user: 'u1' } }`. */
17
+ providerOptions?: Record<string, Record<string, unknown>>;
18
+ /** Extra HTTP headers for this call. */
19
+ headers?: Record<string, string | undefined>;
20
+ }
21
+ /** Any AI SDK embedding model: spec v2, v3 or v4. */
22
+ type AiSdkEmbeddingModel = EmbeddingModelV2<string> | EmbeddingModelV3 | EmbeddingModelV4;
23
+ /** `modelOptions` for `embed()` with a bridged model. */
24
+ interface AiSdkEmbeddingModelOptions extends AiSdkCallOptions {}
25
+ /** TanStack AI embedding adapter around an AI SDK embedding model. Splits large inputs by `maxEmbeddingsPerCall`. */
26
+ export declare class AiSdkEmbeddingAdapter<TModel extends string = string> extends BaseEmbeddingAdapter<TModel, AiSdkEmbeddingModelOptions> {
27
+ readonly name: string;
28
+ readonly embeddingModel: AiSdkEmbeddingModel;
29
+ readonly specificationVersion: SpecVersion;
30
+ constructor(model: AiSdkEmbeddingModel, options?: AiSdkAdapterOptions);
31
+ createEmbeddings(options: EmbeddingOptions<AiSdkEmbeddingModelOptions>): Promise<EmbeddingResult>;
32
+ }
33
+ /**
34
+ * Wraps an AI SDK embedding model as a TanStack AI embedding adapter.
35
+ *
36
+ * @example
37
+ * import { embed } from '@tanstack/ai'
38
+ * import { openai } from '@ai-sdk/openai'
39
+ * await embed({ adapter: aiSdkEmbedding(openai.embedding('text-embedding-3-small')), input: ['hello'] })
40
+ */
41
+ export declare function aiSdkEmbedding(model: AiSdkEmbeddingModel, options?: AiSdkAdapterOptions): AiSdkEmbeddingAdapter<string>;
42
+ /** Any AI SDK image model: spec v2, v3 or v4. */
43
+ type AiSdkImageModel = ImageModelV2 | ImageModelV3 | ImageModelV4;
44
+ /** `modelOptions` for `generateImage()` with a bridged model. */
45
+ interface AiSdkImageModelOptions extends AiSdkCallOptions {
46
+ /** Aspect ratio such as `16:9`, for models that take one instead of a size. */
47
+ aspectRatio?: `${number}:${number}`;
48
+ seed?: number;
49
+ }
50
+ /**
51
+ * TanStack AI image adapter around an AI SDK image model.
52
+ * Text parts of the prompt become the prompt; image parts become input files (AI SDK v3/v4 models).
53
+ */
54
+ export declare class AiSdkImageAdapter<TModel extends string = string> extends BaseImageAdapter<TModel, AiSdkImageModelOptions> {
55
+ readonly name: string;
56
+ readonly imageModel: AiSdkImageModel;
57
+ readonly specificationVersion: SpecVersion;
58
+ constructor(model: AiSdkImageModel, options?: AiSdkAdapterOptions);
59
+ private promptOf;
60
+ generateImages(options: ImageGenerationOptions<AiSdkImageModelOptions>): Promise<ImageGenerationResult>;
61
+ }
62
+ /**
63
+ * Wraps an AI SDK image model as a TanStack AI image adapter.
64
+ *
65
+ * @example
66
+ * import { generateImage } from '@tanstack/ai'
67
+ * import { openai } from '@ai-sdk/openai'
68
+ * await generateImage({ threadId, adapter: aiSdkImage(openai.image('gpt-image-1')), prompt: 'a lighthouse' })
69
+ */
70
+ export declare function aiSdkImage(model: AiSdkImageModel, options?: AiSdkAdapterOptions): AiSdkImageAdapter<string>;
71
+ /** Any AI SDK reranking model: spec v3 or v4 (AI SDK 5 had no reranking models). */
72
+ type AiSdkRerankingModel = RerankingModelV3 | RerankingModelV4;
73
+ /** `modelOptions` for `rerank()` with a bridged model. */
74
+ interface AiSdkRerankModelOptions extends AiSdkCallOptions {}
75
+ /** TanStack AI rerank adapter around an AI SDK reranking model. AI SDK reports no token usage for reranking. */
76
+ export declare class AiSdkRerankAdapter<TModel extends string = string> extends BaseRerankAdapter<TModel, AiSdkRerankModelOptions> {
77
+ readonly name: string;
78
+ readonly rerankingModel: AiSdkRerankingModel;
79
+ readonly specificationVersion: SpecVersion;
80
+ constructor(model: AiSdkRerankingModel, options?: AiSdkAdapterOptions);
81
+ rerank(options: RerankOptions<AiSdkRerankModelOptions>): Promise<RerankAdapterResult>;
82
+ }
83
+ /**
84
+ * Wraps an AI SDK reranking model as a TanStack AI rerank adapter.
85
+ *
86
+ * @example
87
+ * import { rerank } from '@tanstack/ai'
88
+ * import { cohere } from '@ai-sdk/cohere'
89
+ * await rerank({ adapter: aiSdkRerank(cohere.reranking('rerank-v3.5')), query, documents })
90
+ */
91
+ export declare function aiSdkRerank(model: AiSdkRerankingModel, options?: AiSdkAdapterOptions): AiSdkRerankAdapter<string>;
92
+ /** Any AI SDK speech model: spec v2, v3 or v4. */
93
+ type AiSdkSpeechModel = SpeechModelV2 | SpeechModelV3 | SpeechModelV4;
94
+ /** `modelOptions` for `generateSpeech()` with a bridged model. */
95
+ interface AiSdkSpeechModelOptions extends AiSdkCallOptions {
96
+ /** Style instructions, for models that take them. */
97
+ instructions?: string;
98
+ /** Language of the text, e.g. `en`. */
99
+ language?: string;
100
+ }
101
+ /** TanStack AI text-to-speech adapter around an AI SDK speech model. */
102
+ export declare class AiSdkSpeechAdapter<TModel extends string = string> extends BaseTTSAdapter<TModel, AiSdkSpeechModelOptions> {
103
+ readonly name: string;
104
+ readonly speechModel: AiSdkSpeechModel;
105
+ readonly specificationVersion: SpecVersion;
106
+ constructor(model: AiSdkSpeechModel, options?: AiSdkAdapterOptions);
107
+ generateSpeech(options: TTSOptions<AiSdkSpeechModelOptions>): Promise<TTSResult>;
108
+ }
109
+ /**
110
+ * Wraps an AI SDK speech model as a TanStack AI text-to-speech adapter.
111
+ *
112
+ * @example
113
+ * import { generateSpeech } from '@tanstack/ai'
114
+ * import { openai } from '@ai-sdk/openai'
115
+ * await generateSpeech({ threadId, adapter: aiSdkSpeech(openai.speech('gpt-4o-mini-tts')), text: 'Hello', voice: 'alloy' })
116
+ */
117
+ export declare function aiSdkSpeech(model: AiSdkSpeechModel, options?: AiSdkAdapterOptions): AiSdkSpeechAdapter<string>;
118
+ /** Any AI SDK language model: spec v2 (AI SDK 5), v3 (AI SDK 6) or v4 (AI SDK 7). */
119
+ type AiSdkLanguageModel = LanguageModelV2 | LanguageModelV3 | LanguageModelV4;
120
+ /** `modelOptions` for `chat()` with a bridged model. Sampling settings go to the AI SDK call unchanged. */
121
+ interface AiSdkTextModelOptions extends AiSdkCallOptions {
122
+ maxOutputTokens?: number;
123
+ temperature?: number;
124
+ topP?: number;
125
+ topK?: number;
126
+ presencePenalty?: number;
127
+ frequencyPenalty?: number;
128
+ stopSequences?: string[];
129
+ seed?: number;
130
+ }
131
+ type Modalities = readonly ['text', 'image', 'audio', 'video', 'document'];
132
+ type MetadataByModality = {
133
+ text: unknown;
134
+ image: unknown;
135
+ audio: unknown;
136
+ video: unknown;
137
+ document: unknown;
138
+ };
139
+ /**
140
+ * TanStack AI text adapter around an AI SDK language model.
141
+ * Streams text, reasoning and tool calls as AG-UI events and maps usage and finish reasons.
142
+ */
143
+ export declare class AiSdkTextAdapter<TModel extends string = string> extends BaseTextAdapter<TModel, AiSdkTextModelOptions, Modalities, MetadataByModality, ReadonlyArray<string>, unknown, never, {
144
+ levels: ReasoningLevel;
145
+ budget: false;
146
+ }> {
147
+ readonly name: string;
148
+ readonly api = "ai-sdk";
149
+ readonly provider: string;
150
+ readonly inputModalities: Modalities;
151
+ /** The wrapped AI SDK model. */
152
+ readonly languageModel: AiSdkLanguageModel;
153
+ /** AI SDK spec version of the wrapped model. */
154
+ readonly specificationVersion: SpecVersion;
155
+ constructor(model: AiSdkLanguageModel, options?: AiSdkAdapterOptions);
156
+ private callOptions;
157
+ chatStream(options: TextOptions<AiSdkTextModelOptions>): AsyncIterable<AdapterYieldChunk>;
158
+ private runError;
159
+ private mapStream;
160
+ structuredOutput(options: StructuredOutputOptions<AiSdkTextModelOptions>): Promise<StructuredOutputResult<unknown>>;
161
+ }
162
+ /**
163
+ * Wraps an AI SDK language model as a TanStack AI text adapter.
164
+ *
165
+ * @example
166
+ * import { chat } from '@tanstack/ai'
167
+ * import { deepseek } from '@ai-sdk/deepseek'
168
+ * chat({ adapter: aiSdkText(deepseek('deepseek-chat')), messages, threadId })
169
+ */
170
+ export declare function aiSdkText(model: AiSdkLanguageModel, options?: AiSdkAdapterOptions): AiSdkTextAdapter<string>;
171
+ /** Any AI SDK transcription model: spec v2, v3 or v4. */
172
+ type AiSdkTranscriptionModel = TranscriptionModelV2 | TranscriptionModelV3 | TranscriptionModelV4;
173
+ /** `modelOptions` for `generateTranscription()` with a bridged model. */
174
+ interface AiSdkTranscriptionModelOptions extends AiSdkCallOptions {
175
+ /** Media type of the audio when it cannot be read from a `Blob`/`File` or data URL. Default `audio/mpeg`. */
176
+ mediaType?: string;
177
+ }
178
+ /**
179
+ * TanStack AI transcription adapter around an AI SDK transcription model.
180
+ * `language` and `prompt` have no AI SDK equivalent: pass them in `modelOptions.providerOptions`.
181
+ */
182
+ export declare class AiSdkTranscriptionAdapter<TModel extends string = string> extends BaseTranscriptionAdapter<TModel, AiSdkTranscriptionModelOptions> {
183
+ readonly name: string;
184
+ readonly transcriptionModel: AiSdkTranscriptionModel;
185
+ readonly specificationVersion: SpecVersion;
186
+ constructor(model: AiSdkTranscriptionModel, options?: AiSdkAdapterOptions);
187
+ transcribe(options: TranscriptionOptions<AiSdkTranscriptionModelOptions>): Promise<TranscriptionResult>;
188
+ }
189
+ /**
190
+ * Wraps an AI SDK transcription model as a TanStack AI transcription adapter.
191
+ *
192
+ * @example
193
+ * import { generateTranscription } from '@tanstack/ai'
194
+ * import { openai } from '@ai-sdk/openai'
195
+ * await generateTranscription({ threadId, adapter: aiSdkTranscription(openai.transcription('whisper-1')), audio: file })
196
+ */
197
+ export declare function aiSdkTranscription(model: AiSdkTranscriptionModel, options?: AiSdkAdapterOptions): AiSdkTranscriptionAdapter<string>;
198
+ export type { AiSdkAdapterOptions, AiSdkCallOptions, AiSdkEmbeddingModel, AiSdkEmbeddingModelOptions, AiSdkImageModel, AiSdkImageModelOptions, AiSdkLanguageModel, AiSdkRerankModelOptions, AiSdkRerankingModel, AiSdkSpeechModel, AiSdkSpeechModelOptions, AiSdkTextModelOptions, AiSdkTranscriptionModel, AiSdkTranscriptionModelOptions, SpecVersion };