/cloudflare-vm:ai-gatewayfrom cloudflare-vm
Cloudflare AI Gateway: Expert guidance for implementing Cloudflare AI Gateway - a universal gateway for AI model providers with analytics, caching, rate limiting, and routing capabilities.
Ships in cloudflare-vm. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Vendored from themusebook/skills (derived from cloudflare/skills, Apache-2.0). This snapshot may be outdated: confirm limits, pricing, API signatures and config options against https://developers.cloudflare.com/ before you cite them. When this file and the docs disagree, trust the docs.
When invoked: read every file in this skill's directory before answering, so you have the full reference: configuration.md, dynamic-routing.md, features.md, sdk-integration.md, troubleshooting.md. Then answer the user's question (or, if none was given, summarise the product: what it is, config, API, patterns and gotchas). Related products are sibling skills, linked as ../<product>/.
Expert guidance for implementing Cloudflare AI Gateway - a universal gateway for AI model providers with analytics, caching, rate limiting, and routing capabilities.
What's your setup?
Most modern pattern using official ai-gateway-provider package with automatic fallbacks.
import { createAiGateway } from 'ai-gateway-provider';
import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';
const gateway = createAiGateway({
accountId: process.env.CF_ACCOUNT_ID,
gateway: process.env.CF_GATEWAY_ID,
});
const openai = createOpenAI({
apiKey: process.env.OPENAI_API_KEY
});
// Single model
const { text } = await generateText({
model: gateway(openai('gpt-4o')),
prompt: 'Hello'
});
// Automatic fallback array
const { text } = await generateText({
model: gateway([
openai('gpt-4o'), // Try first
anthropic('claude-sonnet-4-5'), // Fallback
]),
prompt: 'Hello'
});
Install: npm install ai-gateway-provider ai @ai-sdk/openai @ai-sdk/anthropic
Drop-in replacement for OpenAI API with multi-provider support.
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/compat`,
defaultHeaders: {
'cf-aig-authorization': `Bearer ${cfToken}` // For authenticated gateways
}
});
// Switch providers by changing model format: {provider}/{model}
const response = await client.chat.completions.create({
model: 'openai/gpt-4o', // or 'anthropic/claude-sonnet-4-5'
messages: [{ role: 'user', content: 'Hello!' }]
});
For Cloudflare Workers using Workers AI.
export default {
async fetch(request, env, ctx) {
const response = await env.AI.run(
'@cf/meta/llama-3-8b-instruct',
{ messages: [{ role: 'user', content: 'Hello!' }] },
{
gateway: {
id: 'my-gateway',
metadata: { userId: '123', team: 'engineering' }
}
}
);
return Response.json(response);
}
};
| Header | Purpose | Example | Notes |
|---|---|---|---|
cf-aig-authorization | Gateway auth | Bearer {token} | Required for authenticated gateways |
cf-aig-metadata | Tracking | {"userId":"x"} | Max 5 entries, flat structure |
cf-aig-cache-ttl | Cache duration | 3600 | Seconds, min 60, max 2592000 (30 days) |
cf-aig-skip-cache | Bypass cache | true | - |
cf-aig-cache-key | Custom cache key | my-key | Must be unique per response |
cf-aig-collect-log | Skip logging | false | Default: true |
cf-aig-cache-status | Cache hit/miss | Response only | HIT or MISS |
| File | Purpose |
|---|---|
| sdk-integration.md | Vercel AI SDK, OpenAI SDK, Workers binding patterns |
| configuration.md | Dashboard setup, wrangler, API tokens |
| features.md | Caching, rate limits, guardrails, DLP, BYOK, unified billing |
| dynamic-routing.md | Fallbacks, A/B testing, conditional routing |
| troubleshooting.md | Debugging, errors, observability, gotchas |
| Task | Files |
|---|---|
| First-time setup | README + configuration.md |
| SDK integration | README + sdk-integration.md |
| Enable caching | README + features.md |
| Setup fallbacks | README + dynamic-routing.md |
| Debug errors | README + troubleshooting.md |
AI Gateway acts as a proxy between your application and AI providers:
Your App → AI Gateway → AI Provider (OpenAI, Anthropic, etc.)
↓
Analytics, Caching, Rate Limiting, Logging
Key URL patterns:
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completionshttps://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/{provider}/{endpoint}dynamic/{route-name}cf-aig-authorization header with Cloudflare API token (recommended)env.AI.run() detailsWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
64 skills in this plugin
/agents-sdkCloudflare Agents SDK: Cloudflare Agents SDK enables building AI-powered agents on Durable Objects with state, WebSockets, SQL, scheduling, and AI integration./ai-searchCloudflare AI Search Reference: Expert guidance for implementing Cloudflare AI Search (formerly AutoRAG), Cloudflare's managed semantic search and RAG service./analytics-engineCloudflare Workers Analytics Engine Reference: Expert guidance for implementing unlimited-cardinality analytics at scale using Cloudflare Workers Analytics Engine.npx claudepluginhub vmaia00/claude-specs --plugin cloudflare-vm