Open History to see the last commit
1import { cloudflareGateway } from '@tanstack/ai-cloudflare'
2
3/**
4 * Client options that send a provider's calls through your Cloudflare AI
5 * Gateway. Returns `{}` unless `CLOUDFLARE_ACCOUNT_ID` and
6 * `CLOUDFLARE_AI_GATEWAY_ID` are set, so the adapters keep their default
7 * endpoints otherwise.
8 */
9export function viaCloudflareGateway(
10 provider: 'openai' | 'anthropic' | 'groq',
11): { baseURL?: string; defaultHeaders?: Record<string, string> } {
12 const accountId = process.env.CLOUDFLARE_ACCOUNT_ID
13 const gatewayId = process.env.CLOUDFLARE_AI_GATEWAY_ID
14 if (!accountId || !gatewayId) return {}
15 const gateway = cloudflareGateway(provider, {
16 accountId,
17 gatewayId,
18 cfApiKey: process.env.CLOUDFLARE_API_TOKEN,
19 })
20 return { baseURL: gateway.baseURL, defaultHeaders: gateway.headers }
21}