跳到主要内容
非官方简体中文翻译,内容版权归 Mastra 所有,遵循 Apache-2.0 许可。

AI/ML API logoAI/ML API

Access 177 AI/ML API models through Mastra's model router. Authentication is handled automatically using the AIMLAPI_API_KEY environment variable.

Learn more in the AI/ML API documentation.

.env
AIMLAPI_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: "aimlapi/aion-labs/aion-rp-llama-3.1-8b"
});

// 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 uses the OpenAI-compatible /chat/completions endpoint. Some provider-specific features may not be available. Check the AI/ML API documentation for details.

Models
Models的直接链接

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
aimlapi/aion-labs/aion-rp-llama-3.1-8b33K$1$2
aimlapi/alibaba/qwen-max32K$2$8
aimlapi/alibaba/qwen-plus131K$0.52$2
aimlapi/alibaba/qwen3-coder-480b-a35b-instruct262K$1$7
aimlapi/alibaba/qwen3-next-80b-a3b-instruct129K$0.21$2
aimlapi/alibaba/qwen3.8-2.4t-a95b262K$3$9
aimlapi/alibaba/qwen3.8-27b262K$0.62$4
aimlapi/alibaba/qwen3.8-flash1.0M$0.21$0.61
aimlapi/alibaba/qwen3.8-max1.0M$3$8
aimlapi/alibaba/qwen3.8-max-prime1.0M$6$17
aimlapi/amazon/nova-lite-v1300K$0.08$0.33
aimlapi/amazon/nova-micro-v1128K$0.05$0.19
aimlapi/amazon/nova-pro-v1300K$1$4
aimlapi/anthracite-org/magnum-v4-72b32K$4$7
aimlapi/anthropic/claude-fable-51.0M$13$65
aimlapi/anthropic/claude-fable-5.11.0M$13$65
aimlapi/anthropic/claude-haiku-4.5200K$1$7
aimlapi/anthropic/claude-haiku-5.51.0M$0.13$0.65
aimlapi/anthropic/claude-opus-4.5200K$7$34
aimlapi/anthropic/claude-opus-4.71.0M$7$34
aimlapi/anthropic/claude-opus-4.81.0M$7$34
aimlapi/anthropic/claude-opus-51.0M$7$33
aimlapi/anthropic/claude-opus-5.51.0M$5$26
aimlapi/anthropic/claude-sonnet-4.5200K$4$21
aimlapi/anthropic/claude-sonnet-4.6200K$4$21
aimlapi/anthropic/claude-sonnet-51.0M$3$13
aimlapi/anthropic/claude-sonnet-5.51.0M$3$13
aimlapi/bytedance-seed/seed-1.6-flash262K$0.10$0.41
aimlapi/bytedance-seed/seed-2.0-code262K$0.69$4
aimlapi/bytedance-seed/seed-2.0-lite262K$0.34$3
aimlapi/bytedance-seed/seed-2.0-mini262K$0.14$0.55
aimlapi/cognitivecomputations/dolphin-mistral-24b-venice-edition128K$0.28$1
aimlapi/cohere/command-a256K$3$14
aimlapi/cohere/command-r-08-2024128K$0.21$0.83
aimlapi/cohere/command-r-plus-08-2024128K$3$14
aimlapi/cohere/command-r7b-12-2024128K$0.05$0.21
aimlapi/deepseek/deepseek-chat1.0M$0.39$2
aimlapi/deepseek/deepseek-chat-v3-0324128K$0.40$2
aimlapi/deepseek/deepseek-v4-flash1.0M$0.39$2
aimlapi/deepseek/deepseek-v4-flash-vision-exp1.0M$0.57$2
aimlapi/deepseek/deepseek-v4-pro1.0M$1$4
aimlapi/deepseek/deepseek-v4-pro-08131.0M$2$5
aimlapi/deepseek/deepseek-v4.1-flash1.0M$0.39$2
aimlapi/google/gemini-3-8-flash1.0M$0.97$5
aimlapi/google/gemini-3.1-flash-lite-preview1.0M$0.34$2
aimlapi/google/gemini-3.1-pro-preview1.0M$3$16
aimlapi/google/gemini-3.1-pro-preview-customtools1.0M$3$17
aimlapi/google/gemini-3.6-flash1.0M$2$10
aimlapi/google/gemini-3.7-flash1.0M$0.97$5
aimlapi/google/gemini-3.8-flash1.0M$0.97$5
aimlapi/google/gemini-flash-latest1.0M$2$12
aimlapi/google/gemma-2-27b-it8K$0.89$0.89
aimlapi/google/gemma-3-12b-it131K$0.07$0.21
aimlapi/google/gemma-3-27b-it128K$0.21$0.63
aimlapi/google/gemma-3-4b-it131K$0.07$0.14
aimlapi/google/gemma-4-26b-a4b-it262K$0.21$0.83
aimlapi/google/gemma-4-31b-it256K$1$2
aimlapi/gryphe/mythomax-l2-13b4K$3$3
aimlapi/ibm-granite/granite-4.0-h-micro131K$0.02$0.15
aimlapi/inception/mercury-2128K$0.34$1
aimlapi/inception/mercury-2.5260K$0.28$1
aimlapi/inference-net/schematron-v2-small128K$0.07$0.32
aimlapi/inference-net/schematron-v2-turbo128K$0.04$0.21
aimlapi/mancer/weaver8K$1$1
aimlapi/meta-llama/Llama-3.3-70B-Instruct-Turbo128K$1$1
aimlapi/meta/muse-glimmer-30b131K$0.48$2
aimlapi/meta/muse-spark-1.11.0M$2$6
aimlapi/meta/muse-spark-1.21.0M$2$6
aimlapi/meta/muse-spark-1.31.0M$2$6
aimlapi/mistralai/codestral-2508256K$0.41$1
aimlapi/mistralai/devstral-2512262K$0.61$3
aimlapi/mistralai/ministral-14b-2512262K$0.48$0.48
aimlapi/mistralai/ministral-3b-2512131K$0.21$0.21
aimlapi/mistralai/ministral-8b-2512262K$0.41$0.41
aimlapi/mistralai/mistral-large128K$3$8
aimlapi/mistralai/mistral-large-2407131K$3$8
aimlapi/mistralai/mistral-medium-3131K$0.55$3
aimlapi/mistralai/mistral-medium-3-5262K$2$10
aimlapi/mistralai/mistral-medium-3.1131K$0.55$3
aimlapi/mistralai/mistral-nemo128K$0.21$0.23
aimlapi/mistralai/mistral-saba33K$0.28$0.83
aimlapi/mistralai/mistral-small-24b-instruct-250133K$0.07$0.11
aimlapi/mistralai/mistral-small-2603262K$0.26$1
aimlapi/mistralai/mistral-small-3.1-24b-instruct128K$0.48$0.76
aimlapi/mistralai/mistral-small-3.2-24b-instruct128K$0.10$0.28
aimlapi/mistralai/mixtral-8x22b-instruct66K$3$8
aimlapi/mistralai/voxtral-small-24b-250732K$0.14$0.41
aimlapi/moonshot/kimi-k31.0M$4$20
aimlapi/moonshotai/kimi-k2131K$0.78$3
aimlapi/moonshotai/kimi-k2-0905262K$1$4
aimlapi/moonshotai/kimi-k2-thinking262K$0.83$3
aimlapi/morph/morph-v3-fast82K$1$2
aimlapi/morph/morph-v3-large262K$1$3
aimlapi/nousresearch/hermes-3-llama-3.1-405b131K$1$1
aimlapi/nousresearch/hermes-3-llama-3.1-70b131K$0.96$0.96
aimlapi/openai/gpt-3.5-turbo16K$0.65$2
aimlapi/openai/gpt-48K$39$78
aimlapi/openai/gpt-4-turbo128K$13$39
aimlapi/openai/gpt-4.11.0M$3$10
aimlapi/openai/gpt-4.1-mini1.0M$0.52$2
aimlapi/openai/gpt-4.1-nano1.0M$0.13$0.52
aimlapi/openai/gpt-4o128K$3$13
aimlapi/openai/gpt-4o-2024-05-13128K$7$20
aimlapi/openai/gpt-4o-2024-08-06128K$3$13
aimlapi/openai/gpt-4o-2024-11-20128K$3$13
aimlapi/openai/gpt-4o-mini128K$0.20$0.78
aimlapi/openai/gpt-5400K$2$13
aimlapi/openai/gpt-5-1400K$2$13
aimlapi/openai/gpt-5-2400K$2$18
aimlapi/openai/gpt-5-41.1M$3$20
aimlapi/openai/gpt-5-51.1M$7$39
aimlapi/openai/gpt-5-mini400K$0.33$3
aimlapi/openai/gpt-5-nano400K$0.07$0.52
aimlapi/openai/gpt-5-pro400K$21$165
aimlapi/openai/gpt-5.1-codex-max400K$3$28
aimlapi/openai/gpt-5.2-pro400K$29$231
aimlapi/openai/gpt-5.3-codex400K$5$39
aimlapi/openai/gpt-5.4-image-2272K$11$21
aimlapi/openai/gpt-5.4-mini400K$2$12
aimlapi/openai/gpt-5.4-nano400K$0.28$2
aimlapi/openai/gpt-5.4-pro1.1M$41$248
aimlapi/openai/gpt-5.5-pro1.1M$41$248
aimlapi/openai/gpt-5.6-luna1.1M$0.26$2
aimlapi/openai/gpt-5.6-luna-pro1.1M$0.28$2
aimlapi/openai/gpt-5.6-sol1.1M$5$26
aimlapi/openai/gpt-5.6-sol-pro1.1M$6$28
aimlapi/openai/gpt-5.6-terra1.1M$3$16
aimlapi/openai/gpt-5.6-terra-pro1.1M$3$17
aimlapi/openai/gpt-6-astra1.1M$13$65
aimlapi/openai/gpt-6-luna1.1M$0.13$0.65
aimlapi/openai/gpt-6-sol1.1M$3$13
aimlapi/openai/gpt-6.1-sol1.1M$3$13
aimlapi/openai/gpt-oss-120b131K$0.48$1
aimlapi/openai/gpt-oss-20b131K$0.10$0.41
aimlapi/openai/gpt-oss-safeguard-20b131K$0.10$0.41
aimlapi/openai/o1128K$20$78
aimlapi/openai/o1-pro200K$206$825
aimlapi/openai/o3-mini200K$1$6
aimlapi/openai/o3-pro200K$28$110
aimlapi/perplexity/sonar128K$1$1
aimlapi/perplexity/sonar-pro200K$4$20
aimlapi/rekaai/reka-edge16K$0.14$0.14
aimlapi/relace/relace-apply-3256K$1$2
aimlapi/relace/relace-search256K$1$4
aimlapi/sakana/fugu-max1.0M$3$8
aimlapi/sakana/fugu-ultra1.0M$7$41
aimlapi/sakana/fugu-ultra-v21.0M$7$41
aimlapi/sao10k/l3-lunaris-8b8K$0.07$0.07
aimlapi/sao10k/l3.1-euryale-70b131K$2$2
aimlapi/sao10k/l3.3-euryale-70b131K$0.89$1
aimlapi/stepfun/step-5-preview1.0M$1$4
aimlapi/tencent/hy-mt2-1.8b8K$0.06$0.24
aimlapi/tencent/hy-mt2-30b-a3b8K$0.10$0.41
aimlapi/tencent/hy-mt2-7b8K$0.10$0.41
aimlapi/tencent/hy3262K$0.28$1
aimlapi/tencent/hy4-preview1.0M$1$3
aimlapi/thedrummer/cydonia-24b-v4.1131K$0.41$0.69
aimlapi/thedrummer/skyfall-36b-v233K$0.76$1
aimlapi/thedrummer/unslopnemo-12b33K$0.55$0.55
aimlapi/thinkingmachines/inkling1.0M$1$6
aimlapi/thinkingmachines/inkling-small524K$0.80$2
aimlapi/unbiased/pareto262K$3$10
aimlapi/undi95/remm-slerp-l2-13b6K$0.69$1
aimlapi/upstage/solar-pro-3128K$0.21$0.83
aimlapi/upstage/solar-pro4524K$0.04$0.17
aimlapi/x-ai/grok-4-20-0309-non-reasoning2.0M$2$3
aimlapi/x-ai/grok-4-fast-non-reasoning2.0M$2$3
aimlapi/xiaomi/mimo-v2.51.0M$0.19$0.39
aimlapi/xiaomi/mimo-v2.5-pro1.0M$0.60$1
aimlapi/z-ai/glm-4.5v66K$0.83$2
aimlapi/z-ai/glm-4.6v131K$0.41$1
aimlapi/z-ai/glm-4.7-flash203K$0.17$0.69
aimlapi/z-ai/glm-5-turbo262K$2$5
aimlapi/z-ai/glm-5.3-flash1.0M$0.20$0.65
aimlapi/z-ai/glm-5v-turbo203K$2$5
aimlapi/zhipu/glm-5.21.0M$2$6
aimlapi/zhipu/glm-5.31.0M$2$6
177 available models

Model availability, capabilities, context windows, and pricing are sourced from models.dev and may change.

Advanced configuration
Advanced configuration的直接链接

Custom headers
Custom headers的直接链接

src/mastra/agents/my-agent.ts
const agent = new Agent({
id: "custom-agent",
name: "custom-agent",
model: {
url: "https://api.aimlapi.com/v1",
id: "aimlapi/aion-labs/aion-rp-llama-3.1-8b",
apiKey: process.env.AIMLAPI_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});

Dynamic model selection
Dynamic model selection的直接链接

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
? "aimlapi/zhipu/glm-5.3"
: "aimlapi/aion-labs/aion-rp-llama-3.1-8b";
}
});