@cloudflare/tanstack-ai 0.0.0 → 0.1.1
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/LICENSE +21 -0
- package/README.md +282 -0
- package/dist/_tsup-dts-rollup.d.cts +820 -0
- package/dist/_tsup-dts-rollup.d.ts +820 -0
- package/dist/adapters/anthropic.cjs +13 -0
- package/dist/adapters/anthropic.cjs.map +1 -0
- package/dist/adapters/anthropic.d.cts +5 -0
- package/dist/adapters/anthropic.d.ts +5 -0
- package/dist/adapters/anthropic.js +13 -0
- package/dist/adapters/anthropic.js.map +1 -0
- package/dist/adapters/gemini.cjs +22 -0
- package/dist/adapters/gemini.cjs.map +1 -0
- package/dist/adapters/gemini.d.cts +14 -0
- package/dist/adapters/gemini.d.ts +14 -0
- package/dist/adapters/gemini.js +22 -0
- package/dist/adapters/gemini.js.map +1 -0
- package/dist/adapters/grok.cjs +17 -0
- package/dist/adapters/grok.cjs.map +1 -0
- package/dist/adapters/grok.d.cts +9 -0
- package/dist/adapters/grok.d.ts +9 -0
- package/dist/adapters/grok.js +17 -0
- package/dist/adapters/grok.js.map +1 -0
- package/dist/adapters/openai.cjs +29 -0
- package/dist/adapters/openai.cjs.map +1 -0
- package/dist/adapters/openai.d.cts +17 -0
- package/dist/adapters/openai.d.ts +17 -0
- package/dist/adapters/openai.js +29 -0
- package/dist/adapters/openai.js.map +1 -0
- package/dist/adapters/openrouter.cjs +13 -0
- package/dist/adapters/openrouter.cjs.map +1 -0
- package/dist/adapters/openrouter.d.cts +7 -0
- package/dist/adapters/openrouter.d.ts +7 -0
- package/dist/adapters/openrouter.js +13 -0
- package/dist/adapters/openrouter.js.map +1 -0
- package/dist/adapters/workers-ai-image.cjs +13 -0
- package/dist/adapters/workers-ai-image.cjs.map +1 -0
- package/dist/adapters/workers-ai-image.d.cts +3 -0
- package/dist/adapters/workers-ai-image.d.ts +3 -0
- package/dist/adapters/workers-ai-image.js +13 -0
- package/dist/adapters/workers-ai-image.js.map +1 -0
- package/dist/adapters/workers-ai-summarize.cjs +12 -0
- package/dist/adapters/workers-ai-summarize.cjs.map +1 -0
- package/dist/adapters/workers-ai-summarize.d.cts +3 -0
- package/dist/adapters/workers-ai-summarize.d.ts +3 -0
- package/dist/adapters/workers-ai-summarize.js +12 -0
- package/dist/adapters/workers-ai-summarize.js.map +1 -0
- package/dist/adapters/workers-ai-transcription.cjs +13 -0
- package/dist/adapters/workers-ai-transcription.cjs.map +1 -0
- package/dist/adapters/workers-ai-transcription.d.cts +3 -0
- package/dist/adapters/workers-ai-transcription.d.ts +3 -0
- package/dist/adapters/workers-ai-transcription.js +13 -0
- package/dist/adapters/workers-ai-transcription.js.map +1 -0
- package/dist/adapters/workers-ai-tts.cjs +13 -0
- package/dist/adapters/workers-ai-tts.cjs.map +1 -0
- package/dist/adapters/workers-ai-tts.d.cts +3 -0
- package/dist/adapters/workers-ai-tts.d.ts +3 -0
- package/dist/adapters/workers-ai-tts.js +13 -0
- package/dist/adapters/workers-ai-tts.js.map +1 -0
- package/dist/adapters/workers-ai.cjs +11 -0
- package/dist/adapters/workers-ai.cjs.map +1 -0
- package/dist/adapters/workers-ai.d.cts +3 -0
- package/dist/adapters/workers-ai.d.ts +3 -0
- package/dist/adapters/workers-ai.js +11 -0
- package/dist/adapters/workers-ai.js.map +1 -0
- package/dist/chunk-2RO3A3R4.js +96 -0
- package/dist/chunk-2RO3A3R4.js.map +1 -0
- package/dist/chunk-2VII5BK2.js +42 -0
- package/dist/chunk-2VII5BK2.js.map +1 -0
- package/dist/chunk-3VQDXJLW.cjs +46 -0
- package/dist/chunk-3VQDXJLW.cjs.map +1 -0
- package/dist/chunk-4ACSLQDI.cjs +216 -0
- package/dist/chunk-4ACSLQDI.cjs.map +1 -0
- package/dist/chunk-4DE2IREA.cjs +8 -0
- package/dist/chunk-4DE2IREA.cjs.map +1 -0
- package/dist/chunk-5YEJ5ZRQ.js +503 -0
- package/dist/chunk-5YEJ5ZRQ.js.map +1 -0
- package/dist/chunk-6FBIXTAL.cjs +315 -0
- package/dist/chunk-6FBIXTAL.cjs.map +1 -0
- package/dist/chunk-6OXP4IVS.cjs +48 -0
- package/dist/chunk-6OXP4IVS.cjs.map +1 -0
- package/dist/chunk-7AEFXYJG.js +65 -0
- package/dist/chunk-7AEFXYJG.js.map +1 -0
- package/dist/chunk-7HSUHP63.cjs +42 -0
- package/dist/chunk-7HSUHP63.cjs.map +1 -0
- package/dist/chunk-AHXFO2BB.cjs +31 -0
- package/dist/chunk-AHXFO2BB.cjs.map +1 -0
- package/dist/chunk-ALUCJNDE.js +109 -0
- package/dist/chunk-ALUCJNDE.js.map +1 -0
- package/dist/chunk-AN23SOZX.cjs +96 -0
- package/dist/chunk-AN23SOZX.cjs.map +1 -0
- package/dist/chunk-F75IZQCM.js +48 -0
- package/dist/chunk-F75IZQCM.js.map +1 -0
- package/dist/chunk-GL2EQLMI.cjs +109 -0
- package/dist/chunk-GL2EQLMI.cjs.map +1 -0
- package/dist/chunk-M64PETK7.cjs +84 -0
- package/dist/chunk-M64PETK7.cjs.map +1 -0
- package/dist/chunk-OV65IEEY.cjs +57 -0
- package/dist/chunk-OV65IEEY.cjs.map +1 -0
- package/dist/chunk-PAVBM57P.js +57 -0
- package/dist/chunk-PAVBM57P.js.map +1 -0
- package/dist/chunk-R2MRGLZ4.js +84 -0
- package/dist/chunk-R2MRGLZ4.js.map +1 -0
- package/dist/chunk-RGDUK5KX.cjs +65 -0
- package/dist/chunk-RGDUK5KX.cjs.map +1 -0
- package/dist/chunk-S3ALRROX.js +57 -0
- package/dist/chunk-S3ALRROX.js.map +1 -0
- package/dist/chunk-SFZAUNHJ.cjs +57 -0
- package/dist/chunk-SFZAUNHJ.cjs.map +1 -0
- package/dist/chunk-SIOQQHXS.js +31 -0
- package/dist/chunk-SIOQQHXS.js.map +1 -0
- package/dist/chunk-UUFEOQ6B.js +315 -0
- package/dist/chunk-UUFEOQ6B.js.map +1 -0
- package/dist/chunk-V6TY7KAL.js +8 -0
- package/dist/chunk-V6TY7KAL.js.map +1 -0
- package/dist/chunk-VV3JFKAN.js +216 -0
- package/dist/chunk-VV3JFKAN.js.map +1 -0
- package/dist/chunk-VZJHRPOT.cjs +503 -0
- package/dist/chunk-VZJHRPOT.cjs.map +1 -0
- package/dist/chunk-XU7YEPML.js +46 -0
- package/dist/chunk-XU7YEPML.js.map +1 -0
- package/dist/index.cjs +97 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +64 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +97 -0
- package/dist/index.js.map +1 -0
- package/package.json +119 -10
|
@@ -0,0 +1,820 @@
|
|
|
1
|
+
import type { AiModels as AiModels_2 } from '@cloudflare/workers-types';
|
|
2
|
+
import { ANTHROPIC_MODELS } from '@tanstack/ai-anthropic';
|
|
3
|
+
import { AnthropicChatModel } from '@tanstack/ai-anthropic';
|
|
4
|
+
import { AnthropicSummarizeAdapter } from '@tanstack/ai-anthropic';
|
|
5
|
+
import type { AnyTextAdapter } from '@tanstack/ai';
|
|
6
|
+
import type { BaseAiTextEmbeddings as BaseAiTextEmbeddings_2 } from '@cloudflare/workers-types';
|
|
7
|
+
import type { BaseAiTextGeneration as BaseAiTextGeneration_2 } from '@cloudflare/workers-types';
|
|
8
|
+
import type { BaseAiTextToImage as BaseAiTextToImage_2 } from '@cloudflare/workers-types';
|
|
9
|
+
import { BaseImageAdapter } from '@tanstack/ai/adapters';
|
|
10
|
+
import { BaseSummarizeAdapter } from '@tanstack/ai/adapters';
|
|
11
|
+
import { BaseTextAdapter } from '@tanstack/ai/adapters';
|
|
12
|
+
import { BaseTranscriptionAdapter } from '@tanstack/ai/adapters';
|
|
13
|
+
import { BaseTTSAdapter } from '@tanstack/ai/adapters';
|
|
14
|
+
import { GeminiImageAdapter } from '@tanstack/ai-gemini';
|
|
15
|
+
import { GeminiImageModel } from '@tanstack/ai-gemini';
|
|
16
|
+
import { GeminiImageModels } from '@tanstack/ai-gemini';
|
|
17
|
+
import { GeminiSummarizeAdapter } from '@tanstack/ai-gemini';
|
|
18
|
+
import { GeminiSummarizeModel } from '@tanstack/ai-gemini';
|
|
19
|
+
import { GeminiSummarizeModels } from '@tanstack/ai-gemini';
|
|
20
|
+
import { GeminiTextModel } from '@tanstack/ai-gemini';
|
|
21
|
+
import { GeminiTextModels } from '@tanstack/ai-gemini';
|
|
22
|
+
import { GeminiTTSAdapter } from '@tanstack/ai-gemini';
|
|
23
|
+
import { GeminiTTSModels } from '@tanstack/ai-gemini';
|
|
24
|
+
import { GROK_CHAT_MODELS } from '@tanstack/ai-grok';
|
|
25
|
+
import { GROK_IMAGE_MODELS } from '@tanstack/ai-grok';
|
|
26
|
+
import { GrokChatModel } from '@tanstack/ai-grok';
|
|
27
|
+
import { GrokImageAdapter } from '@tanstack/ai-grok';
|
|
28
|
+
import { GrokImageModel } from '@tanstack/ai-grok';
|
|
29
|
+
import { GrokSummarizeAdapter } from '@tanstack/ai-grok';
|
|
30
|
+
import { GrokSummarizeModel } from '@tanstack/ai-grok';
|
|
31
|
+
import { GrokTextAdapter } from '@tanstack/ai-grok';
|
|
32
|
+
import type { ImageGenerationOptions } from '@tanstack/ai';
|
|
33
|
+
import type { ImageGenerationResult } from '@tanstack/ai';
|
|
34
|
+
import { OPENAI_CHAT_MODELS } from '@tanstack/ai-openai';
|
|
35
|
+
import { OPENAI_IMAGE_MODELS } from '@tanstack/ai-openai';
|
|
36
|
+
import { OPENAI_TRANSCRIPTION_MODELS } from '@tanstack/ai-openai';
|
|
37
|
+
import { OPENAI_TTS_MODELS } from '@tanstack/ai-openai';
|
|
38
|
+
import { OPENAI_VIDEO_MODELS } from '@tanstack/ai-openai';
|
|
39
|
+
import { OpenAIChatModel } from '@tanstack/ai-openai';
|
|
40
|
+
import { OpenAIImageAdapter } from '@tanstack/ai-openai';
|
|
41
|
+
import { OpenAIImageModel } from '@tanstack/ai-openai';
|
|
42
|
+
import { OpenAISummarizeAdapter } from '@tanstack/ai-openai';
|
|
43
|
+
import { OpenAITextAdapter } from '@tanstack/ai-openai';
|
|
44
|
+
import { OpenAITranscriptionAdapter } from '@tanstack/ai-openai';
|
|
45
|
+
import { OpenAITranscriptionModel } from '@tanstack/ai-openai';
|
|
46
|
+
import { OpenAITTSAdapter } from '@tanstack/ai-openai';
|
|
47
|
+
import { OpenAITTSModel } from '@tanstack/ai-openai';
|
|
48
|
+
import { OpenAIVideoAdapter } from '@tanstack/ai-openai';
|
|
49
|
+
import { OpenAIVideoModel } from '@tanstack/ai-openai';
|
|
50
|
+
import { OpenRouterImageAdapter } from '@tanstack/ai-openrouter';
|
|
51
|
+
import { OpenRouterSummarizeAdapter } from '@tanstack/ai-openrouter';
|
|
52
|
+
import type { StreamChunk } from '@tanstack/ai';
|
|
53
|
+
import { StructuredOutputOptions } from '@tanstack/ai/adapters';
|
|
54
|
+
import { StructuredOutputResult } from '@tanstack/ai/adapters';
|
|
55
|
+
import type { SummarizationOptions } from '@tanstack/ai';
|
|
56
|
+
import type { SummarizationResult } from '@tanstack/ai';
|
|
57
|
+
import type { TextOptions } from '@tanstack/ai';
|
|
58
|
+
import type { TranscriptionOptions } from '@tanstack/ai';
|
|
59
|
+
import type { TranscriptionResult } from '@tanstack/ai';
|
|
60
|
+
import type { TTSOptions } from '@tanstack/ai';
|
|
61
|
+
import type { TTSResult } from '@tanstack/ai';
|
|
62
|
+
|
|
63
|
+
declare type AiGatewayAdapterConfig = (AiGatewayBindingConfig | AiGatewayCredentialsConfig) & AiGatewayConfig;
|
|
64
|
+
export { AiGatewayAdapterConfig }
|
|
65
|
+
export { AiGatewayAdapterConfig as AiGatewayAdapterConfig_alias_1 }
|
|
66
|
+
|
|
67
|
+
export declare interface AiGatewayBindingConfig {
|
|
68
|
+
/**
|
|
69
|
+
* The AI Gateway binding
|
|
70
|
+
* @example
|
|
71
|
+
* env.AI.gateway('my-gateway-id')
|
|
72
|
+
*/
|
|
73
|
+
binding: CloudflareAiGateway;
|
|
74
|
+
/**
|
|
75
|
+
* The Provider API Key if you want to manually pass it, ignore if using Unified Billing or BYOK.
|
|
76
|
+
*/
|
|
77
|
+
apiKey?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export declare interface AiGatewayConfig {
|
|
81
|
+
skipCache?: boolean;
|
|
82
|
+
cacheTtl?: number;
|
|
83
|
+
customCacheKey?: string;
|
|
84
|
+
metadata?: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export declare interface AiGatewayCredentialsConfig {
|
|
88
|
+
/**
|
|
89
|
+
* The Cloudflare account ID
|
|
90
|
+
*/
|
|
91
|
+
accountId: string;
|
|
92
|
+
/**
|
|
93
|
+
* The AI Gateway ID
|
|
94
|
+
*/
|
|
95
|
+
gatewayId: string;
|
|
96
|
+
/**
|
|
97
|
+
* The Provider API Key if you want to manually pass it, ignore if using Unified Billing or BYOK.
|
|
98
|
+
*/
|
|
99
|
+
apiKey?: string;
|
|
100
|
+
/**
|
|
101
|
+
* The Cloudflare AI Gateway API Key, required if your Gateway is authenticated.
|
|
102
|
+
*/
|
|
103
|
+
cfApiKey?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { ANTHROPIC_MODELS }
|
|
107
|
+
export { ANTHROPIC_MODELS as ANTHROPIC_MODELS_alias_1 }
|
|
108
|
+
|
|
109
|
+
export { AnthropicChatModel }
|
|
110
|
+
export { AnthropicChatModel as AnthropicChatModel_alias_1 }
|
|
111
|
+
|
|
112
|
+
declare type AnthropicGatewayConfig = AiGatewayAdapterConfig & {
|
|
113
|
+
anthropicVersion?: string;
|
|
114
|
+
};
|
|
115
|
+
export { AnthropicGatewayConfig }
|
|
116
|
+
export { AnthropicGatewayConfig as AnthropicGatewayConfig_alias_1 }
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Normalise a Workers AI binary response to a base64 string.
|
|
120
|
+
*
|
|
121
|
+
* Handles:
|
|
122
|
+
* - `Uint8Array` / `ArrayBuffer` — raw bytes
|
|
123
|
+
* - `ReadableStream<Uint8Array>` — streamed bytes
|
|
124
|
+
* - `{ [binaryKey]: "base64..." }` — JSON wrapper (e.g. `{ image: "..." }`)
|
|
125
|
+
*
|
|
126
|
+
* @param result The raw value returned from Workers AI
|
|
127
|
+
* @param binaryKey The JSON field to look for when the result is an object
|
|
128
|
+
* (defaults to `"image"`; pass `"audio"` for TTS responses)
|
|
129
|
+
*/
|
|
130
|
+
export declare function binaryToBase64(result: unknown, binaryKey?: string): Promise<string>;
|
|
131
|
+
|
|
132
|
+
export declare interface CloudflareAiGateway {
|
|
133
|
+
run(request: unknown): Promise<Response>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Collect all chunks from a ReadableStream<Uint8Array> into a single Uint8Array.
|
|
138
|
+
*/
|
|
139
|
+
export declare function collectStream(stream: ReadableStream<Uint8Array>): Promise<Uint8Array>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates an Anthropic chat adapter which uses Cloudflare AI Gateway.
|
|
143
|
+
* Supports both binding and credential-based configurations.
|
|
144
|
+
*
|
|
145
|
+
* Since AnthropicTextConfig extends the Anthropic SDK's ClientOptions,
|
|
146
|
+
* we can inject the gateway fetch directly — no subclassing needed.
|
|
147
|
+
*/
|
|
148
|
+
declare function createAnthropicChat(model: AnthropicChatModel, config: AnthropicGatewayConfig): AnyTextAdapter;
|
|
149
|
+
export { createAnthropicChat }
|
|
150
|
+
export { createAnthropicChat as createAnthropicChat_alias_1 }
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Creates an Anthropic summarize adapter which uses Cloudflare AI Gateway.
|
|
154
|
+
* Supports both binding and credential-based configurations.
|
|
155
|
+
*/
|
|
156
|
+
declare function createAnthropicSummarize(model: AnthropicChatModel, config: AnthropicGatewayConfig): AnthropicSummarizeAdapter<"claude-opus-4-6" | "claude-opus-4-5" | "claude-sonnet-4-5" | "claude-haiku-4-5" | "claude-opus-4-1" | "claude-sonnet-4" | "claude-3-7-sonnet" | "claude-opus-4" | "claude-3-5-haiku" | "claude-3-haiku">;
|
|
157
|
+
export { createAnthropicSummarize }
|
|
158
|
+
export { createAnthropicSummarize as createAnthropicSummarize_alias_1 }
|
|
159
|
+
|
|
160
|
+
export declare function createGatewayFetch(provider: string, config: AiGatewayAdapterConfig, headers?: Record<string, string>): typeof fetch;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Creates a Gemini adapter which uses Cloudflare AI Gateway.
|
|
164
|
+
* Does not support the AI binding (Google GenAI SDK lacks custom fetch support).
|
|
165
|
+
* See {@link https://github.com/googleapis/js-genai/issues/999 | googleapis/js-genai#999}.
|
|
166
|
+
* @param model The Gemini model to use
|
|
167
|
+
* @param config Configuration options (credentials only)
|
|
168
|
+
*/
|
|
169
|
+
declare function createGeminiChat(model: GeminiChatModel, config: GeminiGatewayConfig): AnyTextAdapter;
|
|
170
|
+
export { createGeminiChat }
|
|
171
|
+
export { createGeminiChat as createGeminiChat_alias_1 }
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Creates a Gemini Image adapter which uses Cloudflare AI Gateway.
|
|
175
|
+
* Does not support the AI binding (Google GenAI SDK lacks custom fetch support).
|
|
176
|
+
* See {@link https://github.com/googleapis/js-genai/issues/999 | googleapis/js-genai#999}.
|
|
177
|
+
* @param model The Gemini model to use
|
|
178
|
+
* @param config Configuration options (credentials only)
|
|
179
|
+
*/
|
|
180
|
+
declare function createGeminiImage(model: GeminiImageModel, config: GeminiGatewayConfig): GeminiImageAdapter<"gemini-3-pro-image-preview" | "gemini-2.5-flash-image" | "gemini-2.0-flash-preview-image-generation" | "imagen-3.0-generate-002" | "imagen-4.0-generate-001" | "imagen-4.0-fast-generate-001" | "imagen-4.0-ultra-generate-001">;
|
|
181
|
+
export { createGeminiImage }
|
|
182
|
+
export { createGeminiImage as createGeminiImage_alias_1 }
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Creates a Gemini Summarize adapter which uses Cloudflare AI Gateway.
|
|
186
|
+
* Does not support the AI binding (Google GenAI SDK lacks custom fetch support).
|
|
187
|
+
* See {@link https://github.com/googleapis/js-genai/issues/999 | googleapis/js-genai#999}.
|
|
188
|
+
* @param model The Gemini model to use
|
|
189
|
+
* @param config Configuration options (credentials only)
|
|
190
|
+
*/
|
|
191
|
+
declare function createGeminiSummarize(model: GeminiSummarizeModel, config: GeminiGatewayConfig): GeminiSummarizeAdapter<"gemini-2.0-flash" | "gemini-2.0-flash-lite" | "gemini-1.5-flash" | "gemini-1.5-pro">;
|
|
192
|
+
export { createGeminiSummarize }
|
|
193
|
+
export { createGeminiSummarize as createGeminiSummarize_alias_1 }
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Creates a Gemini TTS adapter which uses Cloudflare AI Gateway.
|
|
197
|
+
* Does not support the AI binding (Google GenAI SDK lacks custom fetch support).
|
|
198
|
+
* See {@link https://github.com/googleapis/js-genai/issues/999 | googleapis/js-genai#999}.
|
|
199
|
+
*
|
|
200
|
+
* @experimental Gemini TTS is an experimental feature and may change.
|
|
201
|
+
* @param model The Gemini TTS model to use
|
|
202
|
+
* @param config Configuration options (credentials only)
|
|
203
|
+
*/
|
|
204
|
+
declare function createGeminiTts(model: GeminiTTSModel, config: GeminiGatewayConfig): GeminiTTSAdapter<"gemini-2.5-flash-preview-tts" | "gemini-2.5-pro-preview-tts">;
|
|
205
|
+
export { createGeminiTts }
|
|
206
|
+
export { createGeminiTts as createGeminiTts_alias_1 }
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Creates a Grok chat adapter which uses Cloudflare AI Gateway.
|
|
210
|
+
* Supports both binding and credential-based configurations.
|
|
211
|
+
*
|
|
212
|
+
* Since GrokTextConfig extends the OpenAI SDK's ClientOptions,
|
|
213
|
+
* we can inject the gateway fetch directly — no subclassing needed.
|
|
214
|
+
*/
|
|
215
|
+
declare function createGrokChat(model: GrokChatModel, config: GrokGatewayConfig): GrokTextAdapter<"grok-4-1-fast-reasoning" | "grok-4-1-fast-non-reasoning" | "grok-code-fast-1" | "grok-4-fast-reasoning" | "grok-4-fast-non-reasoning" | "grok-4" | "grok-3" | "grok-3-mini" | "grok-2-vision-1212">;
|
|
216
|
+
export { createGrokChat }
|
|
217
|
+
export { createGrokChat as createGrokChat_alias_1 }
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Creates a Grok image adapter which uses Cloudflare AI Gateway.
|
|
221
|
+
* Supports both binding and credential-based configurations.
|
|
222
|
+
*/
|
|
223
|
+
declare function createGrokImage(model: GrokImageModel, config: GrokGatewayConfig): GrokImageAdapter<"grok-2-image-1212">;
|
|
224
|
+
export { createGrokImage }
|
|
225
|
+
export { createGrokImage as createGrokImage_alias_1 }
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Creates a Grok summarize adapter which uses Cloudflare AI Gateway.
|
|
229
|
+
* Supports both binding and credential-based configurations.
|
|
230
|
+
*/
|
|
231
|
+
declare function createGrokSummarize(model: GrokSummarizeModel, config: GrokGatewayConfig): GrokSummarizeAdapter<"grok-4-1-fast-reasoning" | "grok-4-1-fast-non-reasoning" | "grok-code-fast-1" | "grok-4-fast-reasoning" | "grok-4-fast-non-reasoning" | "grok-4" | "grok-3" | "grok-3-mini" | "grok-2-vision-1212">;
|
|
232
|
+
export { createGrokSummarize }
|
|
233
|
+
export { createGrokSummarize as createGrokSummarize_alias_1 }
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Creates an OpenAI chat adapter which uses Cloudflare AI Gateway.
|
|
237
|
+
* Supports both binding and credential-based configurations.
|
|
238
|
+
* @param model The OpenAI model to use
|
|
239
|
+
* @param config Configuration options
|
|
240
|
+
*/
|
|
241
|
+
declare function createOpenAiChat(model: OpenAIChatModel, config: OpenAiGatewayConfig): OpenAITextAdapter<"gpt-5.2" | "gpt-5.2-pro" | "gpt-5.2-chat-latest" | "gpt-5.1" | "gpt-5.1-codex" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "gpt-5-pro" | "gpt-5-codex" | "o3" | "o3-pro" | "o3-mini" | "o4-mini" | "o3-deep-research" | "o4-mini-deep-research" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4" | "gpt-4-turbo" | "gpt-4o" | "gpt-4o-mini" | "gpt-3.5-turbo" | "gpt-audio" | "gpt-audio-mini" | "gpt-4o-audio" | "gpt-4o-mini-audio" | "gpt-5.1-chat-latest" | "gpt-5-chat-latest" | "chatgpt-4o-latest" | "gpt-5.1-codex-mini" | "codex-mini-latest" | "gpt-4o-search-preview" | "gpt-4o-mini-search-preview" | "computer-use-preview" | "o1" | "o1-pro">;
|
|
242
|
+
export { createOpenAiChat }
|
|
243
|
+
export { createOpenAiChat as createOpenAiChat_alias_1 }
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Creates an OpenAI image adapter which uses Cloudflare AI Gateway.
|
|
247
|
+
* @param model The OpenAI image model to use
|
|
248
|
+
* @param config Configuration options
|
|
249
|
+
*/
|
|
250
|
+
declare function createOpenAiImage(model: OpenAIImageModel, config: OpenAiGatewayConfig): OpenAIImageAdapter<"gpt-image-1" | "gpt-image-1-mini" | "dall-e-3" | "dall-e-2">;
|
|
251
|
+
export { createOpenAiImage }
|
|
252
|
+
export { createOpenAiImage as createOpenAiImage_alias_1 }
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Creates an OpenAI summarize adapter which uses Cloudflare AI Gateway.
|
|
256
|
+
* @param model The OpenAI model to use
|
|
257
|
+
* @param config Configuration options
|
|
258
|
+
*/
|
|
259
|
+
declare function createOpenAiSummarize(model: OpenAIChatModel, config: OpenAiGatewayConfig): OpenAISummarizeAdapter<"gpt-5.2" | "gpt-5.2-pro" | "gpt-5.2-chat-latest" | "gpt-5.1" | "gpt-5.1-codex" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "gpt-5-pro" | "gpt-5-codex" | "o3" | "o3-pro" | "o3-mini" | "o4-mini" | "o3-deep-research" | "o4-mini-deep-research" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4" | "gpt-4-turbo" | "gpt-4o" | "gpt-4o-mini" | "gpt-3.5-turbo" | "gpt-audio" | "gpt-audio-mini" | "gpt-4o-audio" | "gpt-4o-mini-audio" | "gpt-5.1-chat-latest" | "gpt-5-chat-latest" | "chatgpt-4o-latest" | "gpt-5.1-codex-mini" | "codex-mini-latest" | "gpt-4o-search-preview" | "gpt-4o-mini-search-preview" | "computer-use-preview" | "o1" | "o1-pro">;
|
|
260
|
+
export { createOpenAiSummarize }
|
|
261
|
+
export { createOpenAiSummarize as createOpenAiSummarize_alias_1 }
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Creates an OpenAI transcription adapter which uses Cloudflare AI Gateway.
|
|
265
|
+
* @param model The OpenAI transcription model to use
|
|
266
|
+
* @param config Configuration options
|
|
267
|
+
*/
|
|
268
|
+
declare function createOpenAiTranscription(model: OpenAITranscriptionModel, config: OpenAiGatewayConfig): OpenAITranscriptionAdapter<"whisper-1" | "gpt-4o-transcribe" | "gpt-4o-mini-transcribe" | "gpt-4o-transcribe-diarize">;
|
|
269
|
+
export { createOpenAiTranscription }
|
|
270
|
+
export { createOpenAiTranscription as createOpenAiTranscription_alias_1 }
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Creates an OpenAI TTS adapter which uses Cloudflare AI Gateway.
|
|
274
|
+
* @param model The OpenAI TTS model to use
|
|
275
|
+
* @param config Configuration options
|
|
276
|
+
*/
|
|
277
|
+
declare function createOpenAiTts(model: OpenAITTSModel, config: OpenAiGatewayConfig): OpenAITTSAdapter<"tts-1" | "tts-1-hd" | "gpt-4o-audio-preview">;
|
|
278
|
+
export { createOpenAiTts }
|
|
279
|
+
export { createOpenAiTts as createOpenAiTts_alias_1 }
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Creates an OpenAI video adapter which uses Cloudflare AI Gateway.
|
|
283
|
+
* @param model The OpenAI video model to use
|
|
284
|
+
* @param config Configuration options
|
|
285
|
+
*/
|
|
286
|
+
declare function createOpenAiVideo(model: OpenAIVideoModel, config: OpenAiGatewayConfig): OpenAIVideoAdapter<"sora-2" | "sora-2-pro">;
|
|
287
|
+
export { createOpenAiVideo }
|
|
288
|
+
export { createOpenAiVideo as createOpenAiVideo_alias_1 }
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Creates an OpenRouter chat adapter which uses Cloudflare AI Gateway.
|
|
292
|
+
* Supports both binding and credential-based configurations.
|
|
293
|
+
*
|
|
294
|
+
* @param model The model to use (e.g. "openai/gpt-4o", "anthropic/claude-sonnet-4-5")
|
|
295
|
+
* @param config Configuration options
|
|
296
|
+
*/
|
|
297
|
+
declare function createOpenRouterChat(model: OpenRouterChatModel, config: OpenRouterGatewayConfig): AnyTextAdapter;
|
|
298
|
+
export { createOpenRouterChat }
|
|
299
|
+
export { createOpenRouterChat as createOpenRouterChat_alias_1 }
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Creates an OpenRouter image adapter which uses Cloudflare AI Gateway.
|
|
303
|
+
* Supports both binding and credential-based configurations.
|
|
304
|
+
*
|
|
305
|
+
* @param model The image model to use
|
|
306
|
+
* @param config Configuration options
|
|
307
|
+
*/
|
|
308
|
+
declare function createOpenRouterImage(model: OpenRouterImageModel, config: OpenRouterGatewayConfig): OpenRouterImageAdapter<any>;
|
|
309
|
+
export { createOpenRouterImage }
|
|
310
|
+
export { createOpenRouterImage as createOpenRouterImage_alias_1 }
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Creates an OpenRouter summarize adapter which uses Cloudflare AI Gateway.
|
|
314
|
+
* Supports both binding and credential-based configurations.
|
|
315
|
+
*
|
|
316
|
+
* @param model The model to use for summarization
|
|
317
|
+
* @param config Configuration options
|
|
318
|
+
*/
|
|
319
|
+
declare function createOpenRouterSummarize(model: OpenRouterSummarizeModel, config: OpenRouterGatewayConfig): OpenRouterSummarizeAdapter<any>;
|
|
320
|
+
export { createOpenRouterSummarize }
|
|
321
|
+
export { createOpenRouterSummarize as createOpenRouterSummarize_alias_1 }
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Creates a fetch function that intercepts OpenAI SDK requests and translates them
|
|
325
|
+
* to Workers AI binding calls (env.AI.run). This allows the WorkersAiTextAdapter
|
|
326
|
+
* to use the OpenAI SDK against a plain Workers AI binding.
|
|
327
|
+
*
|
|
328
|
+
* NOTE: The `input` URL parameter is intentionally ignored. The model name and all
|
|
329
|
+
* request parameters are extracted from the JSON body, matching Workers AI's
|
|
330
|
+
* `binding.run(model, inputs)` calling convention.
|
|
331
|
+
*/
|
|
332
|
+
export declare function createWorkersAiBindingFetch(binding: WorkersAiBinding): typeof fetch;
|
|
333
|
+
|
|
334
|
+
declare function createWorkersAiChat(model: WorkersAiTextModel, config: WorkersAiAdapterConfig): WorkersAiTextAdapter<WorkersAiTextModel>;
|
|
335
|
+
export { createWorkersAiChat }
|
|
336
|
+
export { createWorkersAiChat as createWorkersAiChat_alias_1 }
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Creates a Workers AI embedding adapter.
|
|
340
|
+
*
|
|
341
|
+
* Note: Factory takes `(model, config)` for ergonomics — the class constructor
|
|
342
|
+
* uses `(config, model)` to match TanStack AI's upstream convention.
|
|
343
|
+
*/
|
|
344
|
+
export declare function createWorkersAiEmbedding(model: WorkersAiEmbeddingModel, config: WorkersAiAdapterConfig): WorkersAiEmbeddingAdapter;
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Creates a Workers AI image generation adapter.
|
|
348
|
+
*
|
|
349
|
+
* Works with TanStack AI's `generateImage()` activity function:
|
|
350
|
+
* ```ts
|
|
351
|
+
* import { generateImage } from "@tanstack/ai";
|
|
352
|
+
* import { createWorkersAiImage } from "@cloudflare/tanstack-ai";
|
|
353
|
+
*
|
|
354
|
+
* const adapter = createWorkersAiImage(
|
|
355
|
+
* "@cf/stabilityai/stable-diffusion-xl-base-1.0",
|
|
356
|
+
* { binding: env.AI },
|
|
357
|
+
* );
|
|
358
|
+
*
|
|
359
|
+
* const result = await generateImage({ adapter, prompt: "a cat in space" });
|
|
360
|
+
* ```
|
|
361
|
+
*
|
|
362
|
+
* Note: Factory takes `(model, config)` for ergonomics — the class constructor
|
|
363
|
+
* uses `(config, model)` to match TanStack AI's upstream convention.
|
|
364
|
+
*/
|
|
365
|
+
declare function createWorkersAiImage(model: WorkersAiImageModel, config: WorkersAiAdapterConfig): WorkersAiImageAdapter;
|
|
366
|
+
export { createWorkersAiImage }
|
|
367
|
+
export { createWorkersAiImage as createWorkersAiImage_alias_1 }
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Creates a Workers AI summarization adapter.
|
|
371
|
+
*
|
|
372
|
+
* Works with TanStack AI's `summarize()` activity function:
|
|
373
|
+
* ```ts
|
|
374
|
+
* import { summarize } from "@tanstack/ai";
|
|
375
|
+
* import { createWorkersAiSummarize } from "@cloudflare/tanstack-ai";
|
|
376
|
+
*
|
|
377
|
+
* const adapter = createWorkersAiSummarize("@cf/facebook/bart-large-cnn", {
|
|
378
|
+
* binding: env.AI,
|
|
379
|
+
* });
|
|
380
|
+
*
|
|
381
|
+
* const result = await summarize({ adapter, text: "Long article here..." });
|
|
382
|
+
* // result.summary
|
|
383
|
+
* ```
|
|
384
|
+
*
|
|
385
|
+
* Note: Factory takes `(model, config)` for ergonomics — the class constructor
|
|
386
|
+
* uses `(config, model)` to match TanStack AI's upstream convention.
|
|
387
|
+
*/
|
|
388
|
+
declare function createWorkersAiSummarize(model: WorkersAiSummarizeModel, config: WorkersAiAdapterConfig): WorkersAiSummarizeAdapter;
|
|
389
|
+
export { createWorkersAiSummarize }
|
|
390
|
+
export { createWorkersAiSummarize as createWorkersAiSummarize_alias_1 }
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Creates a Workers AI transcription adapter for speech-to-text.
|
|
394
|
+
*
|
|
395
|
+
* Works with TanStack AI's `generateTranscription()` activity function:
|
|
396
|
+
* ```ts
|
|
397
|
+
* import { generateTranscription } from "@tanstack/ai";
|
|
398
|
+
* import { createWorkersAiTranscription } from "@cloudflare/tanstack-ai";
|
|
399
|
+
*
|
|
400
|
+
* const adapter = createWorkersAiTranscription(
|
|
401
|
+
* "@cf/openai/whisper-large-v3-turbo",
|
|
402
|
+
* { binding: env.AI },
|
|
403
|
+
* );
|
|
404
|
+
*
|
|
405
|
+
* const result = await generateTranscription({ adapter, audio: audioData });
|
|
406
|
+
* // result.text — the transcribed text
|
|
407
|
+
* ```
|
|
408
|
+
*
|
|
409
|
+
* Note: Factory takes `(model, config)` for ergonomics — the class constructor
|
|
410
|
+
* uses `(config, model)` to match TanStack AI's upstream convention.
|
|
411
|
+
*/
|
|
412
|
+
declare function createWorkersAiTranscription(model: WorkersAiTranscriptionModel, config: WorkersAiAdapterConfig): WorkersAiTranscriptionAdapter;
|
|
413
|
+
export { createWorkersAiTranscription }
|
|
414
|
+
export { createWorkersAiTranscription as createWorkersAiTranscription_alias_1 }
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Creates a Workers AI text-to-speech adapter.
|
|
418
|
+
*
|
|
419
|
+
* Works with TanStack AI's `generateSpeech()` activity function:
|
|
420
|
+
* ```ts
|
|
421
|
+
* import { generateSpeech } from "@tanstack/ai";
|
|
422
|
+
* import { createWorkersAiTts } from "@cloudflare/tanstack-ai";
|
|
423
|
+
*
|
|
424
|
+
* const adapter = createWorkersAiTts(
|
|
425
|
+
* "@cf/deepgram/aura-1",
|
|
426
|
+
* { binding: env.AI },
|
|
427
|
+
* );
|
|
428
|
+
*
|
|
429
|
+
* const result = await generateSpeech({ adapter, text: "Hello world" });
|
|
430
|
+
* // result.audio — base64-encoded audio
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* Note: Factory takes `(model, config)` for ergonomics — the class constructor
|
|
434
|
+
* uses `(config, model)` to match TanStack AI's upstream convention.
|
|
435
|
+
*/
|
|
436
|
+
declare function createWorkersAiTts(model: WorkersAiTTSModel, config: WorkersAiAdapterConfig): WorkersAiTTSAdapter;
|
|
437
|
+
export { createWorkersAiTts }
|
|
438
|
+
export { createWorkersAiTts as createWorkersAiTts_alias_1 }
|
|
439
|
+
|
|
440
|
+
export declare const default_alias: {
|
|
441
|
+
fetch(request: Request, env: Env): Promise<Response>;
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
declare interface Env {
|
|
445
|
+
AI: Ai;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/** Alias for consistency with other providers (AnthropicChatModel, GrokChatModel, etc.) */
|
|
449
|
+
declare type GeminiChatModel = GeminiTextModel;
|
|
450
|
+
export { GeminiChatModel }
|
|
451
|
+
export { GeminiChatModel as GeminiChatModel_alias_1 }
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Gemini-specific gateway config (credentials only, no binding support).
|
|
455
|
+
* Includes cache control options from AiGatewayConfig.
|
|
456
|
+
* See {@link https://github.com/googleapis/js-genai/issues/999 | googleapis/js-genai#999}.
|
|
457
|
+
*/
|
|
458
|
+
declare type GeminiGatewayConfig = AiGatewayCredentialsConfig & AiGatewayConfig;
|
|
459
|
+
export { GeminiGatewayConfig }
|
|
460
|
+
export { GeminiGatewayConfig as GeminiGatewayConfig_alias_1 }
|
|
461
|
+
|
|
462
|
+
export { GeminiImageModel }
|
|
463
|
+
export { GeminiImageModel as GeminiImageModel_alias_1 }
|
|
464
|
+
|
|
465
|
+
export { GeminiImageModels }
|
|
466
|
+
export { GeminiImageModels as GeminiImageModels_alias_1 }
|
|
467
|
+
|
|
468
|
+
export { GeminiSummarizeModel }
|
|
469
|
+
export { GeminiSummarizeModel as GeminiSummarizeModel_alias_1 }
|
|
470
|
+
|
|
471
|
+
export { GeminiSummarizeModels }
|
|
472
|
+
export { GeminiSummarizeModels as GeminiSummarizeModels_alias_1 }
|
|
473
|
+
|
|
474
|
+
export { GeminiTextModel }
|
|
475
|
+
export { GeminiTextModel as GeminiTextModel_alias_1 }
|
|
476
|
+
|
|
477
|
+
export { GeminiTextModels }
|
|
478
|
+
export { GeminiTextModels as GeminiTextModels_alias_1 }
|
|
479
|
+
|
|
480
|
+
/** Derived from GeminiTTSModels since @tanstack/ai-gemini doesn't export a GeminiTTSModel type. */
|
|
481
|
+
declare type GeminiTTSModel = (typeof GeminiTTSModels)[number];
|
|
482
|
+
export { GeminiTTSModel }
|
|
483
|
+
export { GeminiTTSModel as GeminiTTSModel_alias_1 }
|
|
484
|
+
|
|
485
|
+
export { GeminiTTSModels }
|
|
486
|
+
export { GeminiTTSModels as GeminiTTSModels_alias_1 }
|
|
487
|
+
|
|
488
|
+
export { GROK_CHAT_MODELS }
|
|
489
|
+
export { GROK_CHAT_MODELS as GROK_CHAT_MODELS_alias_1 }
|
|
490
|
+
|
|
491
|
+
export { GROK_IMAGE_MODELS }
|
|
492
|
+
export { GROK_IMAGE_MODELS as GROK_IMAGE_MODELS_alias_1 }
|
|
493
|
+
|
|
494
|
+
export { GrokChatModel }
|
|
495
|
+
export { GrokChatModel as GrokChatModel_alias_1 }
|
|
496
|
+
|
|
497
|
+
declare type GrokGatewayConfig = AiGatewayAdapterConfig;
|
|
498
|
+
export { GrokGatewayConfig }
|
|
499
|
+
export { GrokGatewayConfig as GrokGatewayConfig_alias_1 }
|
|
500
|
+
|
|
501
|
+
export { GrokImageModel }
|
|
502
|
+
export { GrokImageModel as GrokImageModel_alias_1 }
|
|
503
|
+
|
|
504
|
+
export { GrokSummarizeModel }
|
|
505
|
+
export { GrokSummarizeModel as GrokSummarizeModel_alias_1 }
|
|
506
|
+
|
|
507
|
+
/** Returns true if this is a plain Workers AI binding config (`{ binding: env.AI }`) */
|
|
508
|
+
export declare function isDirectBindingConfig(config: WorkersAiAdapterConfig): config is WorkersAiDirectBindingConfig;
|
|
509
|
+
|
|
510
|
+
/** Returns true if this is a plain Workers AI REST config (accountId + apiKey, no gatewayId) */
|
|
511
|
+
export declare function isDirectCredentialsConfig(config: WorkersAiAdapterConfig): config is WorkersAiDirectCredentialsConfig;
|
|
512
|
+
|
|
513
|
+
/** Returns true if this is an AI Gateway config (has gateway binding or `gatewayId`) */
|
|
514
|
+
export declare function isGatewayConfig(config: WorkersAiAdapterConfig): config is AiGatewayAdapterConfig;
|
|
515
|
+
|
|
516
|
+
export { OPENAI_CHAT_MODELS }
|
|
517
|
+
export { OPENAI_CHAT_MODELS as OPENAI_CHAT_MODELS_alias_1 }
|
|
518
|
+
|
|
519
|
+
export { OPENAI_IMAGE_MODELS }
|
|
520
|
+
export { OPENAI_IMAGE_MODELS as OPENAI_IMAGE_MODELS_alias_1 }
|
|
521
|
+
|
|
522
|
+
export { OPENAI_TRANSCRIPTION_MODELS }
|
|
523
|
+
export { OPENAI_TRANSCRIPTION_MODELS as OPENAI_TRANSCRIPTION_MODELS_alias_1 }
|
|
524
|
+
|
|
525
|
+
export { OPENAI_TTS_MODELS }
|
|
526
|
+
export { OPENAI_TTS_MODELS as OPENAI_TTS_MODELS_alias_1 }
|
|
527
|
+
|
|
528
|
+
export { OPENAI_VIDEO_MODELS }
|
|
529
|
+
export { OPENAI_VIDEO_MODELS as OPENAI_VIDEO_MODELS_alias_1 }
|
|
530
|
+
|
|
531
|
+
export { OpenAIChatModel }
|
|
532
|
+
export { OpenAIChatModel as OpenAIChatModel_alias_1 }
|
|
533
|
+
|
|
534
|
+
declare type OpenAiGatewayConfig = AiGatewayAdapterConfig;
|
|
535
|
+
export { OpenAiGatewayConfig }
|
|
536
|
+
export { OpenAiGatewayConfig as OpenAiGatewayConfig_alias_1 }
|
|
537
|
+
|
|
538
|
+
export { OpenAIImageModel }
|
|
539
|
+
export { OpenAIImageModel as OpenAIImageModel_alias_1 }
|
|
540
|
+
|
|
541
|
+
export { OpenAITranscriptionModel }
|
|
542
|
+
export { OpenAITranscriptionModel as OpenAITranscriptionModel_alias_1 }
|
|
543
|
+
|
|
544
|
+
export { OpenAITTSModel }
|
|
545
|
+
export { OpenAITTSModel as OpenAITTSModel_alias_1 }
|
|
546
|
+
|
|
547
|
+
export { OpenAIVideoModel }
|
|
548
|
+
export { OpenAIVideoModel as OpenAIVideoModel_alias_1 }
|
|
549
|
+
|
|
550
|
+
/** OpenRouter chat model identifier. Accepts any string since OpenRouter proxies hundreds of models. */
|
|
551
|
+
declare type OpenRouterChatModel = string;
|
|
552
|
+
export { OpenRouterChatModel }
|
|
553
|
+
export { OpenRouterChatModel as OpenRouterChatModel_alias_1 }
|
|
554
|
+
|
|
555
|
+
declare type OpenRouterGatewayConfig = AiGatewayAdapterConfig;
|
|
556
|
+
export { OpenRouterGatewayConfig }
|
|
557
|
+
export { OpenRouterGatewayConfig as OpenRouterGatewayConfig_alias_1 }
|
|
558
|
+
|
|
559
|
+
/** OpenRouter image model identifier. */
|
|
560
|
+
declare type OpenRouterImageModel = string;
|
|
561
|
+
export { OpenRouterImageModel }
|
|
562
|
+
export { OpenRouterImageModel as OpenRouterImageModel_alias_1 }
|
|
563
|
+
|
|
564
|
+
/** OpenRouter summarize model identifier (same as chat models). */
|
|
565
|
+
declare type OpenRouterSummarizeModel = string;
|
|
566
|
+
export { OpenRouterSummarizeModel }
|
|
567
|
+
export { OpenRouterSummarizeModel as OpenRouterSummarizeModel_alias_1 }
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Shared binary-data utilities for Workers AI adapters.
|
|
571
|
+
*
|
|
572
|
+
* Workers AI returns binary data (images, audio) in various formats —
|
|
573
|
+
* Uint8Array, ArrayBuffer, ReadableStream, or JSON objects with a base64 field.
|
|
574
|
+
* These helpers normalise everything into base64 strings for the TanStack AI
|
|
575
|
+
* result types.
|
|
576
|
+
*/
|
|
577
|
+
/**
|
|
578
|
+
* Convert a Uint8Array to a base64 string.
|
|
579
|
+
*/
|
|
580
|
+
export declare function uint8ArrayToBase64(bytes: Uint8Array): string;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Config for Workers AI adapters. Supports four modes:
|
|
584
|
+
* - Plain binding: `{ binding: env.AI }`
|
|
585
|
+
* - Plain REST: `{ accountId, apiKey }`
|
|
586
|
+
* - AI Gateway binding: `{ binding: env.AI.gateway(id) }`
|
|
587
|
+
* - AI Gateway REST: `{ accountId, gatewayId, ... }`
|
|
588
|
+
*
|
|
589
|
+
* The third union member intersects `AiGatewayAdapterConfig` with `{ apiKey?: string }`.
|
|
590
|
+
* For the gateway binding variant, `AiGatewayBindingConfig` already includes `apiKey?`,
|
|
591
|
+
* so the intersection is redundant there. For the gateway credentials variant, this
|
|
592
|
+
* `apiKey` represents the Workers AI token (used in the `Authorization` header to the
|
|
593
|
+
* upstream provider), distinct from `cfApiKey` (used in the `cf-aig-authorization`
|
|
594
|
+
* header for authenticated gateways).
|
|
595
|
+
*/
|
|
596
|
+
declare type WorkersAiAdapterConfig = WorkersAiDirectBindingConfig | WorkersAiDirectCredentialsConfig | (AiGatewayAdapterConfig & {
|
|
597
|
+
apiKey?: string;
|
|
598
|
+
});
|
|
599
|
+
export { WorkersAiAdapterConfig }
|
|
600
|
+
export { WorkersAiAdapterConfig as WorkersAiAdapterConfig_alias_1 }
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* The Workers AI binding interface (env.AI).
|
|
604
|
+
* Accepts a model name and inputs, returns results directly.
|
|
605
|
+
* Includes `gateway()` which is present on `env.AI` but not on `env.AI.gateway(id)`,
|
|
606
|
+
* enabling structural discrimination from `CloudflareAiGateway`.
|
|
607
|
+
*/
|
|
608
|
+
export declare interface WorkersAiBinding {
|
|
609
|
+
run(model: string, inputs: Record<string, unknown>, options?: Record<string, unknown>): Promise<unknown>;
|
|
610
|
+
gateway(gatewayId: string): CloudflareAiGateway;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
export declare interface WorkersAiDirectBindingConfig {
|
|
614
|
+
/**
|
|
615
|
+
* The Workers AI binding (env.AI).
|
|
616
|
+
* @example
|
|
617
|
+
* { binding: env.AI }
|
|
618
|
+
*/
|
|
619
|
+
binding: WorkersAiBinding;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
export declare interface WorkersAiDirectCredentialsConfig {
|
|
623
|
+
/**
|
|
624
|
+
* The Cloudflare account ID
|
|
625
|
+
*/
|
|
626
|
+
accountId: string;
|
|
627
|
+
/**
|
|
628
|
+
* The Cloudflare API key for Workers AI
|
|
629
|
+
*/
|
|
630
|
+
apiKey: string;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export declare class WorkersAiEmbeddingAdapter {
|
|
634
|
+
readonly name: "workers-ai-embedding";
|
|
635
|
+
private model;
|
|
636
|
+
private config;
|
|
637
|
+
constructor(config: WorkersAiAdapterConfig, model: WorkersAiEmbeddingModel);
|
|
638
|
+
embed(texts: string[]): Promise<WorkersAiEmbeddingResult>;
|
|
639
|
+
private embedViaBinding;
|
|
640
|
+
private embedViaRest;
|
|
641
|
+
private embedViaGateway;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
export declare type WorkersAiEmbeddingModel = {
|
|
645
|
+
[K in keyof AiModels_2]: AiModels_2[K] extends BaseAiTextEmbeddings_2 ? K : never;
|
|
646
|
+
}[keyof AiModels_2];
|
|
647
|
+
|
|
648
|
+
export declare interface WorkersAiEmbeddingResult {
|
|
649
|
+
embeddings: number[][];
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
export declare class WorkersAiImageAdapter extends BaseImageAdapter<WorkersAiImageModel> {
|
|
653
|
+
readonly name: "workers-ai-image";
|
|
654
|
+
private adapterConfig;
|
|
655
|
+
constructor(config: WorkersAiAdapterConfig, model: WorkersAiImageModel);
|
|
656
|
+
generateImages(options: ImageGenerationOptions): Promise<ImageGenerationResult>;
|
|
657
|
+
private generateViaBinding;
|
|
658
|
+
private generateViaRest;
|
|
659
|
+
private generateViaGateway;
|
|
660
|
+
/** Wrap a base64 image string into the standard ImageGenerationResult. */
|
|
661
|
+
private wrapResult;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
declare type WorkersAiImageModel = {
|
|
665
|
+
[K in keyof AiModels_2]: AiModels_2[K] extends BaseAiTextToImage_2 ? K : never;
|
|
666
|
+
}[keyof AiModels_2];
|
|
667
|
+
export { WorkersAiImageModel }
|
|
668
|
+
export { WorkersAiImageModel as WorkersAiImageModel_alias_1 }
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Make a REST API call to Workers AI.
|
|
672
|
+
*
|
|
673
|
+
* Handles the common pattern shared by all Workers AI adapters:
|
|
674
|
+
* - Build the URL from account ID and model name
|
|
675
|
+
* - Set Authorization and Content-Type headers
|
|
676
|
+
* - Check response.ok and throw a descriptive error on failure
|
|
677
|
+
*
|
|
678
|
+
* @param config Credentials config with accountId and apiKey
|
|
679
|
+
* @param model Workers AI model name (e.g. "@cf/stabilityai/stable-diffusion-xl-base-1.0")
|
|
680
|
+
* @param body JSON request body
|
|
681
|
+
* @param options Optional settings:
|
|
682
|
+
* - `label` — human-readable label for error messages (default: "Workers AI")
|
|
683
|
+
* - `signal` — AbortSignal for request cancellation / timeout
|
|
684
|
+
* @returns The raw Response object — caller is responsible for parsing
|
|
685
|
+
*/
|
|
686
|
+
export declare function workersAiRestFetch(config: WorkersAiDirectCredentialsConfig, model: string, body: Record<string, unknown>, options?: {
|
|
687
|
+
label?: string;
|
|
688
|
+
signal?: AbortSignal;
|
|
689
|
+
}): Promise<Response>;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Make a binary REST API call to Workers AI.
|
|
693
|
+
*
|
|
694
|
+
* Some models (e.g. `@cf/deepgram/nova-3`) require raw binary audio with an
|
|
695
|
+
* appropriate `Content-Type` header instead of JSON. This function sends the
|
|
696
|
+
* audio bytes directly as the request body.
|
|
697
|
+
*
|
|
698
|
+
* @param config Credentials config with accountId and apiKey
|
|
699
|
+
* @param model Workers AI model name
|
|
700
|
+
* @param audioBytes Raw audio bytes
|
|
701
|
+
* @param contentType MIME type of the audio (e.g. "audio/wav")
|
|
702
|
+
* @param options Optional settings
|
|
703
|
+
* @returns The raw Response object
|
|
704
|
+
*/
|
|
705
|
+
export declare function workersAiRestFetchBinary(config: WorkersAiDirectCredentialsConfig, model: string, audioBytes: Uint8Array, contentType: string, options?: {
|
|
706
|
+
label?: string;
|
|
707
|
+
signal?: AbortSignal;
|
|
708
|
+
}): Promise<Response>;
|
|
709
|
+
|
|
710
|
+
export declare class WorkersAiSummarizeAdapter extends BaseSummarizeAdapter<WorkersAiSummarizeModel> {
|
|
711
|
+
readonly name: "workers-ai-summarize";
|
|
712
|
+
private adapterConfig;
|
|
713
|
+
constructor(config: WorkersAiAdapterConfig, model: WorkersAiSummarizeModel);
|
|
714
|
+
summarize(options: SummarizationOptions): Promise<SummarizationResult>;
|
|
715
|
+
private summarizeViaBinding;
|
|
716
|
+
private summarizeViaRest;
|
|
717
|
+
private summarizeViaGateway;
|
|
718
|
+
private wrapResult;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* Workers AI models that support summarization.
|
|
723
|
+
*/
|
|
724
|
+
declare type WorkersAiSummarizeModel = "@cf/facebook/bart-large-cnn";
|
|
725
|
+
export { WorkersAiSummarizeModel }
|
|
726
|
+
export { WorkersAiSummarizeModel as WorkersAiSummarizeModel_alias_1 }
|
|
727
|
+
|
|
728
|
+
export declare class WorkersAiTextAdapter<TModel extends WorkersAiTextModel> extends BaseTextAdapter<TModel, any, any, any> {
|
|
729
|
+
name: "workers-ai";
|
|
730
|
+
private client;
|
|
731
|
+
constructor(model: TModel, config: WorkersAiAdapterConfig);
|
|
732
|
+
chatStream(options: TextOptions<any>): AsyncIterable<StreamChunk>;
|
|
733
|
+
structuredOutput(options: StructuredOutputOptions<any>): Promise<StructuredOutputResult<unknown>>;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
declare type WorkersAiTextModel = {
|
|
737
|
+
[K in keyof AiModels_2]: AiModels_2[K] extends BaseAiTextGeneration_2 ? K : never;
|
|
738
|
+
}[keyof AiModels_2];
|
|
739
|
+
export { WorkersAiTextModel }
|
|
740
|
+
export { WorkersAiTextModel as WorkersAiTextModel_alias_1 }
|
|
741
|
+
|
|
742
|
+
export declare class WorkersAiTranscriptionAdapter extends BaseTranscriptionAdapter<WorkersAiTranscriptionModel> {
|
|
743
|
+
readonly name: "workers-ai-transcription";
|
|
744
|
+
private adapterConfig;
|
|
745
|
+
constructor(config: WorkersAiAdapterConfig, model: WorkersAiTranscriptionModel);
|
|
746
|
+
transcribe(options: TranscriptionOptions): Promise<TranscriptionResult>;
|
|
747
|
+
/**
|
|
748
|
+
* Build the audio field for the request payload, handling model-specific formats.
|
|
749
|
+
*
|
|
750
|
+
* - `@cf/deepgram/nova-3` requires `{ body: base64, contentType: "audio/..." }`
|
|
751
|
+
* - `@cf/openai/whisper-large-v3-turbo` REST/gateway accepts a base64 string
|
|
752
|
+
* - Other Whisper models accept `number[]` (binding) or base64 (REST)
|
|
753
|
+
*/
|
|
754
|
+
private buildAudioPayload;
|
|
755
|
+
private transcribeViaBinding;
|
|
756
|
+
private transcribeViaRest;
|
|
757
|
+
/**
|
|
758
|
+
* Transcribe via REST using raw binary audio.
|
|
759
|
+
* Required for models like Deepgram Nova-3 that expect raw audio bytes
|
|
760
|
+
* with a Content-Type header (e.g. "audio/wav") instead of JSON.
|
|
761
|
+
*/
|
|
762
|
+
private transcribeViaRestBinary;
|
|
763
|
+
private transcribeViaGateway;
|
|
764
|
+
/**
|
|
765
|
+
* Normalize Workers AI transcription results into the standard
|
|
766
|
+
* TanStack AI TranscriptionResult shape.
|
|
767
|
+
*
|
|
768
|
+
* Handles three response formats:
|
|
769
|
+
* - Whisper: `{ text, words?, vtt? }`
|
|
770
|
+
* - Whisper v3-turbo: `{ text, segments?, transcription_info? }`
|
|
771
|
+
* - Deepgram Nova-3: `{ results: { channels: [{ alternatives: [{ transcript, words }] }] } }`
|
|
772
|
+
*/
|
|
773
|
+
private normalizeResult;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Workers AI models that support speech-to-text transcription.
|
|
778
|
+
*
|
|
779
|
+
* Note: the typed `AiModels` interface in `@cloudflare/workers-types` may lag
|
|
780
|
+
* behind what's deployed. We use a string union here that matches the known
|
|
781
|
+
* models including Deepgram partner models.
|
|
782
|
+
*
|
|
783
|
+
* **Nova-3 note:** `@cf/deepgram/nova-3` uses a different input format than the
|
|
784
|
+
* Whisper models. Via binding it accepts `{ audio: { body: base64, contentType } }`.
|
|
785
|
+
* Via REST it requires multipart form data (not JSON). The adapter handles both.
|
|
786
|
+
*/
|
|
787
|
+
declare type WorkersAiTranscriptionModel = "@cf/openai/whisper" | "@cf/openai/whisper-tiny-en" | "@cf/openai/whisper-large-v3-turbo" | "@cf/deepgram/nova-3";
|
|
788
|
+
export { WorkersAiTranscriptionModel }
|
|
789
|
+
export { WorkersAiTranscriptionModel as WorkersAiTranscriptionModel_alias_1 }
|
|
790
|
+
|
|
791
|
+
export declare class WorkersAiTTSAdapter extends BaseTTSAdapter<WorkersAiTTSModel> {
|
|
792
|
+
readonly name: "workers-ai-tts";
|
|
793
|
+
private adapterConfig;
|
|
794
|
+
constructor(config: WorkersAiAdapterConfig, model: WorkersAiTTSModel);
|
|
795
|
+
generateSpeech(options: TTSOptions): Promise<TTSResult>;
|
|
796
|
+
private generateViaBinding;
|
|
797
|
+
private generateViaRest;
|
|
798
|
+
private generateViaGateway;
|
|
799
|
+
/**
|
|
800
|
+
* Normalize binding results. Workers AI TTS can return:
|
|
801
|
+
* - Uint8Array / ArrayBuffer (raw audio bytes)
|
|
802
|
+
* - ReadableStream<Uint8Array> (streamed audio bytes)
|
|
803
|
+
* - { audio: "base64..." } (JSON wrapper)
|
|
804
|
+
*/
|
|
805
|
+
private normalizeResult;
|
|
806
|
+
private wrapAudioResult;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* Workers AI models that support text-to-speech generation.
|
|
811
|
+
*
|
|
812
|
+
* Note: the typed `AiModels` interface in `@cloudflare/workers-types` may lag
|
|
813
|
+
* behind what's deployed. We use a string union here that matches the known
|
|
814
|
+
* models including Deepgram partner models.
|
|
815
|
+
*/
|
|
816
|
+
declare type WorkersAiTTSModel = "@cf/deepgram/aura-1" | "@cf/deepgram/aura-2-en" | "@cf/deepgram/aura-2-es";
|
|
817
|
+
export { WorkersAiTTSModel }
|
|
818
|
+
export { WorkersAiTTSModel as WorkersAiTTSModel_alias_1 }
|
|
819
|
+
|
|
820
|
+
export { }
|