Open History to see the last commit
@tanstack/ai-cloudflare#
Cloudflare adapter for TanStack AI: Workers AI chat, summarization, embeddings, image generation, text-to-speech, and transcription over the env.AI binding or the REST API, with AI Gateway routing for any provider.
Installation#
npm install @tanstack/ai @tanstack/ai-cloudflare
Usage#
import { chat, toServerSentEventsResponse } from '@tanstack/ai'
import { createCloudflareText } from '@tanstack/ai-cloudflare'
import type { Ai } from '@cloudflare/workers-types'
export default {
async fetch(request: Request, env: { AI: Ai }) {
const { messages } = await request.json()
const stream = chat({
adapter: createCloudflareText('@cf/zai-org/glm-5.3-flash', {
binding: env.AI,
}),
messages,
})
return toServerSentEventsResponse(stream)
},
}
Outside a Worker, pass { accountId, apiKey } or set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN and use cloudflareText(model).
See the docs for AI Gateway, media adapters, and model options.