docs/src/content/en/models/providers/cloudflare-workers-ai.mdx
Access 42 Cloudflare Workers AI models through Mastra's model router. Authentication is handled automatically using the CLOUDFLARE_ACCOUNT_ID environment variable.
Learn more in the Cloudflare Workers AI documentation.
CLOUDFLARE_ACCOUNT_ID=your-api-key
import { Agent } from "@mastra/core/agent";
const agent = new Agent({
id: "my-agent",
name: "My Agent",
instructions: "You are a helpful assistant",
model: "cloudflare-workers-ai/@cf/ai4bharat/indictrans2-en-indic-1B"
});
// Generate a response
const response = await agent.generate("Hello!");
// Stream a response
const stream = await agent.stream("Tell me a story");
for await (const chunk of stream) {
console.log(chunk);
}
:::info
Mastra uses the OpenAI-compatible /chat/completions endpoint. Some provider-specific features may not be available. Check the Cloudflare Workers AI documentation for details.
:::
<ProviderModelsTable models={[ { "model": "cloudflare-workers-ai/@cf/ai4bharat/indictrans2-en-indic-1B", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.34, "outputCost": 0.34 }, { "model": "cloudflare-workers-ai/@cf/aisingapore/gemma-sea-lion-v4-27b-it", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.35, "outputCost": 0.56 }, { "model": "cloudflare-workers-ai/@cf/baai/bge-base-en-v1.5", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.067, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/baai/bge-large-en-v1.5", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.2, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/baai/bge-m3", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.012, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/baai/bge-reranker-base", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.0031, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/baai/bge-small-en-v1.5", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.02, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/deepgram/aura-2-en", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": null, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/deepgram/aura-2-es", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": null, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/deepgram/nova-3", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": null, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/deepseek-ai/deepseek-r1-distill-qwen-32b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.5, "outputCost": 4.88 }, { "model": "cloudflare-workers-ai/@cf/facebook/bart-large-cnn", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": null, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/google/gemma-3-12b-it", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.35, "outputCost": 0.56 }, { "model": "cloudflare-workers-ai/@cf/huggingface/distilbert-sst-2-int8", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.026, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/ibm-granite/granite-4.0-h-micro", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.017, "outputCost": 0.11 }, { "model": "cloudflare-workers-ai/@cf/meta/llama-2-7b-chat-fp16", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.56, "outputCost": 6.67 }, { "model": "cloudflare-workers-ai/@cf/meta/llama-3-8b-instruct", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.28, "outputCost": 0.83 }, { "model": "cloudflare-workers-ai/@cf/meta/llama-3-8b-instruct-awq", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.12, "outputCost": 0.27 }, { "model": "cloudflare-workers-ai/@cf/meta/llama-3.1-8b-instruct", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.28, "outputCost": 0.8299999999999998 }, { "model": "cloudflare-workers-ai/@cf/meta/llama-3.1-8b-instruct-awq", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.12, "outputCost": 0.27 }, { "model": "cloudflare-workers-ai/@cf/meta/llama-3.1-8b-instruct-fp8", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.15, "outputCost": 0.29 }, { "model": "cloudflare-workers-ai/@cf/meta/llama-3.2-11b-vision-instruct", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.049, "outputCost": 0.68 }, { "model": "cloudflare-workers-ai/@cf/meta/llama-3.2-1b-instruct", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.027, "outputCost": 0.2 }, { "model": "cloudflare-workers-ai/@cf/meta/llama-3.2-3b-instruct", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.051, "outputCost": 0.34 }, { "model": "cloudflare-workers-ai/@cf/meta/llama-3.3-70b-instruct-fp8-fast", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.29, "outputCost": 2.25 }, { "model": "cloudflare-workers-ai/@cf/meta/llama-4-scout-17b-16e-instruct", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.27, "outputCost": 0.85 }, { "model": "cloudflare-workers-ai/@cf/meta/llama-guard-3-8b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.48, "outputCost": 0.03 }, { "model": "cloudflare-workers-ai/@cf/meta/m2m100-1.2b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.34, "outputCost": 0.34 }, { "model": "cloudflare-workers-ai/@cf/mistral/mistral-7b-instruct-v0.1", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.11, "outputCost": 0.19 }, { "model": "cloudflare-workers-ai/@cf/mistralai/mistral-small-3.1-24b-instruct", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.35, "outputCost": 0.56 }, { "model": "cloudflare-workers-ai/@cf/moonshotai/kimi-k2.5", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 256000, "maxOutput": 256000, "inputCost": 0.6, "outputCost": 3 }, { "model": "cloudflare-workers-ai/@cf/myshell-ai/melotts", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": null, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/nvidia/nemotron-3-120b-a12b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 256000, "maxOutput": 256000, "inputCost": 0.5, "outputCost": 1.5 }, { "model": "cloudflare-workers-ai/@cf/openai/gpt-oss-120b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.35, "outputCost": 0.75 }, { "model": "cloudflare-workers-ai/@cf/openai/gpt-oss-20b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.2, "outputCost": 0.3 }, { "model": "cloudflare-workers-ai/@cf/pfnet/plamo-embedding-1b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.019, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/pipecat-ai/smart-turn-v2", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": null, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/qwen/qwen2.5-coder-32b-instruct", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.66, "outputCost": 1 }, { "model": "cloudflare-workers-ai/@cf/qwen/qwen3-30b-a3b-fp8", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.051, "outputCost": 0.34 }, { "model": "cloudflare-workers-ai/@cf/qwen/qwen3-embedding-0.6b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.012, "outputCost": null }, { "model": "cloudflare-workers-ai/@cf/qwen/qwq-32b", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 128000, "maxOutput": 16384, "inputCost": 0.66, "outputCost": 1 }, { "model": "cloudflare-workers-ai/@cf/zai-org/glm-4.7-flash", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": true, "reasoning": true, "contextWindow": 131072, "maxOutput": 131072, "inputCost": 0.06, "outputCost": 0.4 } ]} />
const agent = new Agent({
id: "custom-agent",
name: "custom-agent",
model: {
url: "https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/v1",
id: "cloudflare-workers-ai/@cf/ai4bharat/indictrans2-en-indic-1B",
apiKey: process.env.CLOUDFLARE_ACCOUNT_ID,
headers: {
"X-Custom-Header": "value"
}
}
});
const agent = new Agent({
id: "dynamic-agent",
name: "Dynamic Agent",
model: ({ requestContext }) => {
const useAdvanced = requestContext.task === "complex";
return useAdvanced
? "cloudflare-workers-ai/@cf/zai-org/glm-4.7-flash"
: "cloudflare-workers-ai/@cf/ai4bharat/indictrans2-en-indic-1B";
}
});