Skip to main content

Cloudflare AI Gateway logoCloudflare AI Gateway

Cloudflare AI Gateway is an intelligent control plane for AI applications with dynamic routing, caching, observability, and unified billing.

Learn more in the Cloudflare AI Gateway documentation.

Usage
Direct link to Usage

src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";

const agent = new Agent({
id: "my-agent",
name: "My Agent",
instructions: "You are a helpful assistant",
model: "cloudflare-ai-gateway/alibaba/qwen3-max"
});
note

Mastra uses the OpenAI-compatible /chat/completions endpoint. Some provider-specific features may not be available. Check the Cloudflare AI Gateway documentation for details.

Configuration
Direct link to Configuration

# Gateway configuration
CLOUDFLARE_ACCOUNT_ID=your-account-id
CLOUDFLARE_GATEWAY_ID=your-gateway-id
CLOUDFLARE_API_TOKEN=your-gateway-key

CLOUDFLARE_API_TOKEN authenticates requests to Cloudflare AI Gateway. Configure upstream provider keys stored in Cloudflare (Bring Your Own Key, or BYOK), or use Cloudflare Unified Billing. Cloudflare has deprecated /compat for standard single-model chat completions.

Available models
Direct link to Available models

See the Cloudflare AI models documentation for the full catalog. The table below lists the model IDs currently indexed in Mastra’s model router.

Model
alibaba/qwen3-max
alibaba/qwen3.5-397b-a17b
alibaba/qwen3.7-max
alibaba/qwen3.7-plus
alibaba/qwen3.8-max
anthropic/claude-fable-5
anthropic/claude-fable-5.1
anthropic/claude-fable-5.2
anthropic/claude-haiku-4.5
anthropic/claude-haiku-5.5
anthropic/claude-opus-4.5
anthropic/claude-opus-4.6
anthropic/claude-opus-4.7
anthropic/claude-opus-4.8
anthropic/claude-opus-5
anthropic/claude-opus-5.5
anthropic/claude-sonnet-4.5
anthropic/claude-sonnet-4.6
anthropic/claude-sonnet-5
anthropic/claude-sonnet-5.5
deepseek-ai/deepseek-v4.1-flash-1017
deepseek/deepseek-v4-pro
fireworks/ember-1
google/gemini-2.5-flash
google/gemini-2.5-flash-lite
google/gemini-2.5-pro
google/gemini-3-flash
google/gemini-3.1-flash-lite
google/gemini-3.1-pro
google/gemini-3.5-flash
google/gemini-3.5-flash-lite
google/gemini-3.6-flash
google/gemini-3.7-flash
google/gemini-3.8-flash
google/gemini-4-argon
google/gemini-4-carbon
google/gemini-4-hydrogen
google/gemini-4-neon
meta/muse-ember-1.0
meta/muse-spark-1.1
meta/muse-spark-1.2
meta/muse-spark-1.3
meta/muse-spark-open
meta/muse-wonder-1.0
minimax/m3.1-flash
moonshotai/kimi-k3
moonshotai/kimi-k3.1-pro
moonshotai/kimi-k3.1-pro-highspeed
openai/gpt-4.1
openai/gpt-4.1-mini
openai/gpt-4.1-nano
openai/gpt-4o
openai/gpt-4o-mini
openai/gpt-5
openai/gpt-5-mini
openai/gpt-5-nano
openai/gpt-5.1
openai/gpt-5.4
openai/gpt-5.4-mini
openai/gpt-5.4-nano
openai/gpt-5.4-pro
openai/gpt-5.5
openai/gpt-5.5-pro
openai/gpt-5.6-luna
openai/gpt-5.6-sol
openai/gpt-5.6-terra
openai/gpt-6-astra
openai/gpt-6-luna
openai/gpt-6-sol
openai/gpt-6.1-sol
openai/gpt-6.1-terra
openai/gpt-6.2-astra
openai/gpt-6.2-sol
openai/o3
openai/o3-mini
openai/o4-mini
particle/particle-1
reflection-ai/beam-1.0-501b-a23b
xai/grok-4.20-0309-non-reasoning
xai/grok-4.20-0309-reasoning
xai/grok-4.3
xai/grok-4.5
xai/grok-4.6
xai/grok-4.7
xiaomi/mimo-v2.6-pro
z-ai/glm-5.3
On this page