跳至主要內容

FastRouter 標誌FastRouter

透過 Mastra 的模型路由器存取 47 個 FastRouter 模型。系統會自動使用 FASTROUTER_API_KEY 環境變數進行驗證。

詳情請參閱FastRouter 文件

.env
FASTROUTER_API_KEY=your-api-key
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: 'fastrouter/anthropic/claude-opus-4.1',
})

// 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)
}
資訊

Mastra 使用與 OpenAI 相容的 /chat/completions 端點。部分 Provider 專屬功能可能無法使用,詳情請參閱FastRouter 文件

模型
模型 的直接連結

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
fastrouter/anthropic/claude-opus-4.1200K$15$75
fastrouter/anthropic/claude-opus-4.81.0M$5$25
fastrouter/anthropic/claude-sonnet-4200K$3$15
fastrouter/anthropic/claude-sonnet-4.61.0M$3$15
fastrouter/bytedance/seedance-24K
fastrouter/deepseek-ai/deepseek-r1-distill-llama-70b131K$0.03$0.14
fastrouter/deepseek/deepseek-v4-pro1.0M$2$3
fastrouter/google/gemini-2.5-flash1.0M$0.30$3
fastrouter/google/gemini-2.5-pro1.0M$1$10
fastrouter/google/gemini-3-pro-image-preview66K$2$12
fastrouter/google/gemini-3.1-flash-image-preview66K$0.50$3
fastrouter/google/gemini-3.1-pro-preview1.0M$2$12
fastrouter/google/gemini-3.5-flash1.0M$2$9
fastrouter/google/gemma-4-31b-it262K$0.13$0.38
fastrouter/google/imagen-4.0-fast480
fastrouter/google/imagen-4.0-ultra480
fastrouter/google/veo3.1400K
fastrouter/google/veo3.1-fast400K
fastrouter/google/veo3.1-lite400K
fastrouter/leonardo-ai/lucid-origin4K
fastrouter/leonardo-ai/lucid-realism4K
fastrouter/minimax/minimax-m2.7205K$0.30$1
fastrouter/minimax/minimax-m2.7-highspeed205K$0.60$2
fastrouter/moonshotai/kimi-k2131K$0.55$2
fastrouter/moonshotai/kimi-k2.6262K$0.75$4
fastrouter/openai/gpt-4.11.0M$2$8
fastrouter/openai/gpt-5400K$1$10
fastrouter/openai/gpt-5-mini400K$0.25$2
fastrouter/openai/gpt-5-nano400K$0.05$0.40
fastrouter/openai/gpt-5.3-codex400K$2$14
fastrouter/openai/gpt-5.4-mini400K$0.75$5
fastrouter/openai/gpt-5.4-nano400K$0.20$1
fastrouter/openai/gpt-5.51.1M$5$30
fastrouter/openai/gpt-5.5-pro1.1M$30$180
fastrouter/openai/gpt-image-2128K
fastrouter/openai/gpt-oss-120b131K$0.15$0.60
fastrouter/openai/gpt-oss-20b131K$0.05$0.20
fastrouter/openai/gpt-realtime-1.532K$4$16
fastrouter/qwen/qwen3-coder262K$0.30$1
fastrouter/sarvam/sarvam-105b131K$0.04$0.16
fastrouter/sarvam/sarvam-30b128K$0.02$0.10
fastrouter/wanx/wan-v2-6400K
fastrouter/x-ai/grok-4256K$3$15
fastrouter/x-ai/grok-4.31.0M$1$3
fastrouter/x-ai/grok-build-0.1256K$1$2
fastrouter/z-ai/glm-5205K$0.95$3
fastrouter/z-ai/glm-5.1200K$1$4
47 available models

進階設定
進階設定 的直接連結

自訂標頭
自訂標頭 的直接連結

src/mastra/agents/my-agent.ts
const agent = new Agent({
id: 'custom-agent',
name: 'custom-agent',
model: {
url: 'https://go.fastrouter.ai/api/v1',
id: 'fastrouter/anthropic/claude-opus-4.1',
apiKey: process.env.FASTROUTER_API_KEY,
headers: {
'X-Custom-Header': 'value',
},
},
})

動態選擇模型
動態選擇模型 的直接連結

src/mastra/agents/my-agent.ts
const agent = new Agent({
id: 'dynamic-agent',
name: 'Dynamic Agent',
model: ({ requestContext }) => {
const useAdvanced = requestContext.task === 'complex'
return useAdvanced ? 'fastrouter/z-ai/glm-5.1' : 'fastrouter/anthropic/claude-opus-4.1'
},
})