AI/ML API
Access 181 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);
}
note
Mastra uses the OpenAI-compatible /chat/completions endpoint. Some provider-specific features may not be available. Check the AI/ML API documentation for details.
ModelsDirect link to Models
| Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
|---|---|---|---|---|---|---|---|---|
aimlapi/aion-labs/aion-rp-llama-3.1-8b | 33K | $1 | $2 | |||||
aimlapi/alibaba/qwen-max | 32K | $2 | $8 | |||||
aimlapi/alibaba/qwen-plus | 131K | $0.52 | $2 | |||||
aimlapi/alibaba/qwen3-coder-480b-a35b-instruct | 262K | $2 | $10 | |||||
aimlapi/alibaba/qwen3-max | 262K | $2 | $8 | |||||
aimlapi/alibaba/qwen3-max-preview | 252K | $2 | $8 | |||||
aimlapi/alibaba/qwen3-next-80b-a3b-instruct | 129K | $0.20 | $2 | |||||
aimlapi/alibaba/qwen3-vl-flash | 262K | $0.07 | $0.52 | |||||
aimlapi/alibaba/qwen3.6-max-preview | 262K | $0.65 | $4 | |||||
aimlapi/alibaba/qwen3.8-2.4t-a95b | 262K | $3 | $9 | |||||
aimlapi/alibaba/qwen3.8-27b | 262K | $0.62 | $4 | |||||
aimlapi/alibaba/qwen3.8-flash | 1.0M | $0.21 | $0.61 | |||||
aimlapi/alibaba/qwen3.8-max | 1.0M | $3 | $8 | |||||
aimlapi/alibaba/qwen3.8-max-prime | 1.0M | $6 | $17 | |||||
aimlapi/amazon/nova-lite-v1 | 300K | $0.08 | $0.33 | |||||
aimlapi/amazon/nova-micro-v1 | 128K | $0.05 | $0.19 | |||||
aimlapi/amazon/nova-pro-v1 | 300K | $1 | $4 | |||||
aimlapi/anthracite-org/magnum-v4-72b | 32K | $4 | $7 | |||||
aimlapi/anthropic/claude-fable-5 | 1.0M | $13 | $65 | |||||
aimlapi/anthropic/claude-fable-5.1 | 1.0M | $13 | $65 | |||||
aimlapi/anthropic/claude-haiku-4.5 | 200K | $1 | $7 | |||||
aimlapi/anthropic/claude-haiku-5.5 | 1.0M | $0.13 | $0.65 | |||||
aimlapi/anthropic/claude-opus-4.5 | 200K | $7 | $34 | |||||
aimlapi/anthropic/claude-opus-4.7 | 1.0M | $7 | $34 | |||||
aimlapi/anthropic/claude-opus-4.8 | 1.0M | $7 | $34 | |||||
aimlapi/anthropic/claude-opus-5 | 1.0M | $7 | $33 | |||||
aimlapi/anthropic/claude-opus-5.5 | 1.0M | $5 | $26 | |||||
aimlapi/anthropic/claude-sonnet-4.5 | 200K | $4 | $21 | |||||
aimlapi/anthropic/claude-sonnet-4.6 | 200K | $4 | $21 | |||||
aimlapi/anthropic/claude-sonnet-5 | 1.0M | $3 | $13 | |||||
aimlapi/anthropic/claude-sonnet-5.5 | 1.0M | $3 | $13 | |||||
aimlapi/bytedance-seed/seed-1.6-flash | 262K | $0.10 | $0.41 | |||||
aimlapi/bytedance-seed/seed-2.0-code | 262K | $0.69 | $4 | |||||
aimlapi/bytedance-seed/seed-2.0-lite | 262K | $0.34 | $3 | |||||
aimlapi/bytedance-seed/seed-2.0-mini | 262K | $0.14 | $0.55 | |||||
aimlapi/cognitivecomputations/dolphin-mistral-24b-venice-edition | 128K | $0.28 | $1 | |||||
aimlapi/cohere/command-a | 256K | $3 | $14 | |||||
aimlapi/cohere/command-r-08-2024 | 128K | $0.21 | $0.83 | |||||
aimlapi/cohere/command-r-plus-08-2024 | 128K | $3 | $14 | |||||
aimlapi/cohere/command-r7b-12-2024 | 128K | $0.05 | $0.21 | |||||
aimlapi/deepseek/deepseek-chat | 1.0M | $0.39 | $2 | |||||
aimlapi/deepseek/deepseek-chat-v3-0324 | 128K | $0.40 | $2 | |||||
aimlapi/deepseek/deepseek-v4-flash | 1.0M | $0.39 | $2 | |||||
aimlapi/deepseek/deepseek-v4-flash-vision-exp | 1.0M | $0.57 | $2 | |||||
aimlapi/deepseek/deepseek-v4-pro | 1.0M | $1 | $4 | |||||
aimlapi/deepseek/deepseek-v4-pro-0813 | 1.0M | $2 | $5 | |||||
aimlapi/deepseek/deepseek-v4.1-flash | 1.0M | $0.39 | $2 | |||||
aimlapi/google/gemini-3-8-flash | 1.0M | $0.97 | $5 | |||||
aimlapi/google/gemini-3.1-flash-lite-preview | 1.0M | $0.34 | $2 | |||||
aimlapi/google/gemini-3.1-pro-preview | 1.0M | $3 | $16 | |||||
aimlapi/google/gemini-3.1-pro-preview-customtools | 1.0M | $3 | $17 | |||||
aimlapi/google/gemini-3.6-flash | 1.0M | $2 | $10 | |||||
aimlapi/google/gemini-3.7-flash | 1.0M | $0.97 | $5 | |||||
aimlapi/google/gemini-3.8-flash | 1.0M | $0.97 | $5 | |||||
aimlapi/google/gemini-flash-latest | 1.0M | $2 | $12 | |||||
aimlapi/google/gemma-2-27b-it | 8K | $0.89 | $0.89 | |||||
aimlapi/google/gemma-3-12b-it | 131K | $0.07 | $0.21 | |||||
aimlapi/google/gemma-3-27b-it | 128K | $0.21 | $0.63 | |||||
aimlapi/google/gemma-3-4b-it | 131K | $0.07 | $0.14 | |||||
aimlapi/google/gemma-4-26b-a4b-it | 262K | $0.21 | $0.83 | |||||
aimlapi/google/gemma-4-31b-it | 256K | $1 | $2 | |||||
aimlapi/gryphe/mythomax-l2-13b | 4K | $3 | $3 | |||||
aimlapi/ibm-granite/granite-4.0-h-micro | 131K | $0.02 | $0.15 | |||||
aimlapi/inception/mercury-2 | 128K | $0.34 | $1 | |||||
aimlapi/inception/mercury-2.5 | 260K | $0.28 | $1 | |||||
aimlapi/inference-net/schematron-v2-small | 128K | $0.07 | $0.32 | |||||
aimlapi/inference-net/schematron-v2-turbo | 128K | $0.04 | $0.21 | |||||
aimlapi/mancer/weaver | 8K | $1 | $1 | |||||
aimlapi/meta-llama/Llama-3.3-70B-Instruct-Turbo | 128K | $1 | $1 | |||||
aimlapi/meta/muse-glimmer-30b | 131K | $0.48 | $2 | |||||
aimlapi/meta/muse-spark-1.1 | 1.0M | $2 | $6 | |||||
aimlapi/meta/muse-spark-1.2 | 1.0M | $2 | $6 | |||||
aimlapi/meta/muse-spark-1.3 | 1.0M | $2 | $6 | |||||
aimlapi/mistralai/codestral-2508 | 256K | $0.41 | $1 | |||||
aimlapi/mistralai/devstral-2512 | 262K | $0.61 | $3 | |||||
aimlapi/mistralai/ministral-14b-2512 | 262K | $0.48 | $0.48 | |||||
aimlapi/mistralai/ministral-3b-2512 | 131K | $0.21 | $0.21 | |||||
aimlapi/mistralai/ministral-8b-2512 | 262K | $0.41 | $0.41 | |||||
aimlapi/mistralai/mistral-large | 128K | $3 | $8 | |||||
aimlapi/mistralai/mistral-large-2407 | 131K | $3 | $8 | |||||
aimlapi/mistralai/mistral-medium-3 | 131K | $0.55 | $3 | |||||
aimlapi/mistralai/mistral-medium-3-5 | 262K | $2 | $10 | |||||
aimlapi/mistralai/mistral-medium-3.1 | 131K | $0.55 | $3 | |||||
aimlapi/mistralai/mistral-nemo | 128K | $0.21 | $0.23 | |||||
aimlapi/mistralai/mistral-saba | 33K | $0.28 | $0.83 | |||||
aimlapi/mistralai/mistral-small-24b-instruct-2501 | 33K | $0.07 | $0.11 | |||||
aimlapi/mistralai/mistral-small-2603 | 262K | $0.26 | $1 | |||||
aimlapi/mistralai/mistral-small-3.1-24b-instruct | 128K | $0.48 | $0.76 | |||||
aimlapi/mistralai/mistral-small-3.2-24b-instruct | 128K | $0.10 | $0.28 | |||||
aimlapi/mistralai/mixtral-8x22b-instruct | 66K | $3 | $8 | |||||
aimlapi/mistralai/voxtral-small-24b-2507 | 32K | $0.14 | $0.41 | |||||
aimlapi/moonshot/kimi-k3 | 1.0M | $4 | $20 | |||||
aimlapi/moonshotai/kimi-k2 | 131K | $0.78 | $3 | |||||
aimlapi/moonshotai/kimi-k2-0905 | 262K | $1 | $4 | |||||
aimlapi/moonshotai/kimi-k2-thinking | 262K | $0.83 | $3 | |||||
aimlapi/morph/morph-v3-fast | 82K | $1 | $2 | |||||
aimlapi/morph/morph-v3-large | 262K | $1 | $3 | |||||
aimlapi/nousresearch/hermes-3-llama-3.1-405b | 131K | $1 | $1 | |||||
aimlapi/nousresearch/hermes-3-llama-3.1-70b | 131K | $0.96 | $0.96 | |||||
aimlapi/openai/gpt-3.5-turbo | 16K | $0.65 | $2 | |||||
aimlapi/openai/gpt-4 | 8K | $39 | $78 | |||||
aimlapi/openai/gpt-4-turbo | 128K | $13 | $39 | |||||
aimlapi/openai/gpt-4.1 | 1.0M | $3 | $10 | |||||
aimlapi/openai/gpt-4.1-mini | 1.0M | $0.52 | $2 | |||||
aimlapi/openai/gpt-4.1-nano | 1.0M | $0.13 | $0.52 | |||||
aimlapi/openai/gpt-4o | 128K | $3 | $13 | |||||
aimlapi/openai/gpt-4o-2024-05-13 | 128K | $7 | $20 | |||||
aimlapi/openai/gpt-4o-2024-08-06 | 128K | $3 | $13 | |||||
aimlapi/openai/gpt-4o-2024-11-20 | 128K | $3 | $13 | |||||
aimlapi/openai/gpt-4o-mini | 128K | $0.20 | $0.78 | |||||
aimlapi/openai/gpt-5 | 400K | $2 | $15 | |||||
aimlapi/openai/gpt-5-1 | 400K | $2 | $13 | |||||
aimlapi/openai/gpt-5-2 | 400K | $2 | $18 | |||||
aimlapi/openai/gpt-5-4 | 1.1M | $3 | $20 | |||||
aimlapi/openai/gpt-5-5 | 1.1M | $7 | $39 | |||||
aimlapi/openai/gpt-5-mini | 400K | $0.38 | $3 | |||||
aimlapi/openai/gpt-5-nano | 400K | $0.08 | $0.61 | |||||
aimlapi/openai/gpt-5-pro | 400K | $21 | $165 | |||||
aimlapi/openai/gpt-5.1-codex-max | 400K | $3 | $28 | |||||
aimlapi/openai/gpt-5.2-pro | 400K | $29 | $231 | |||||
aimlapi/openai/gpt-5.3-codex | 400K | $5 | $39 | |||||
aimlapi/openai/gpt-5.4-image-2 | 272K | $11 | $21 | |||||
aimlapi/openai/gpt-5.4-mini | 400K | $2 | $12 | |||||
aimlapi/openai/gpt-5.4-nano | 400K | $0.28 | $2 | |||||
aimlapi/openai/gpt-5.4-pro | 1.1M | $41 | $248 | |||||
aimlapi/openai/gpt-5.5-pro | 1.1M | $41 | $248 | |||||
aimlapi/openai/gpt-5.6-luna | 1.1M | $0.26 | $2 | |||||
aimlapi/openai/gpt-5.6-luna-pro | 1.1M | $0.28 | $2 | |||||
aimlapi/openai/gpt-5.6-sol | 1.1M | $5 | $26 | |||||
aimlapi/openai/gpt-5.6-sol-pro | 1.1M | $6 | $28 | |||||
aimlapi/openai/gpt-5.6-terra | 1.1M | $3 | $16 | |||||
aimlapi/openai/gpt-5.6-terra-pro | 1.1M | $3 | $17 | |||||
aimlapi/openai/gpt-6-astra | 1.1M | $13 | $65 | |||||
aimlapi/openai/gpt-6-luna | 1.1M | $0.13 | $0.65 | |||||
aimlapi/openai/gpt-6-sol | 1.1M | $3 | $13 | |||||
aimlapi/openai/gpt-6.1-sol | 1.1M | $3 | $13 | |||||
aimlapi/openai/gpt-oss-120b | 131K | $0.48 | $1 | |||||
aimlapi/openai/gpt-oss-20b | 131K | $0.10 | $0.41 | |||||
aimlapi/openai/gpt-oss-safeguard-20b | 131K | $0.10 | $0.41 | |||||
aimlapi/openai/o1 | 128K | $20 | $78 | |||||
aimlapi/openai/o1-pro | 200K | $206 | $825 | |||||
aimlapi/openai/o3-mini | 200K | $1 | $6 | |||||
aimlapi/openai/o3-pro | 200K | $28 | $110 | |||||
aimlapi/perplexity/sonar | 128K | $1 | $1 | |||||
aimlapi/perplexity/sonar-pro | 200K | $4 | $20 | |||||
aimlapi/rekaai/reka-edge | 16K | $0.14 | $0.14 | |||||
aimlapi/relace/relace-apply-3 | 256K | $1 | $2 | |||||
aimlapi/relace/relace-search | 256K | $1 | $4 | |||||
aimlapi/sakana/fugu-max | 1.0M | $3 | $8 | |||||
aimlapi/sakana/fugu-ultra | 1.0M | $7 | $41 | |||||
aimlapi/sakana/fugu-ultra-v2 | 1.0M | $7 | $41 | |||||
aimlapi/sao10k/l3-lunaris-8b | 8K | $0.07 | $0.07 | |||||
aimlapi/sao10k/l3.1-euryale-70b | 131K | $2 | $2 | |||||
aimlapi/sao10k/l3.3-euryale-70b | 131K | $0.89 | $1 | |||||
aimlapi/stepfun/step-5-preview | 1.0M | $1 | $4 | |||||
aimlapi/tencent/hy-mt2-1.8b | 8K | $0.06 | $0.24 | |||||
aimlapi/tencent/hy-mt2-30b-a3b | 8K | $0.10 | $0.41 | |||||
aimlapi/tencent/hy-mt2-7b | 8K | $0.10 | $0.41 | |||||
aimlapi/tencent/hy3 | 262K | $0.28 | $1 | |||||
aimlapi/tencent/hy4-preview | 1.0M | $1 | $3 | |||||
aimlapi/thedrummer/cydonia-24b-v4.1 | 131K | $0.41 | $0.69 | |||||
aimlapi/thedrummer/skyfall-36b-v2 | 33K | $0.76 | $1 | |||||
aimlapi/thedrummer/unslopnemo-12b | 33K | $0.55 | $0.55 | |||||
aimlapi/thinkingmachines/inkling | 1.0M | $1 | $6 | |||||
aimlapi/thinkingmachines/inkling-small | 524K | $0.80 | $2 | |||||
aimlapi/unbiased/pareto | 262K | $3 | $10 | |||||
aimlapi/undi95/remm-slerp-l2-13b | 6K | $0.69 | $1 | |||||
aimlapi/upstage/solar-pro-3 | 128K | $0.21 | $0.83 | |||||
aimlapi/upstage/solar-pro4 | 524K | $0.04 | $0.17 | |||||
aimlapi/x-ai/grok-4-20-0309-non-reasoning | 2.0M | $2 | $3 | |||||
aimlapi/x-ai/grok-4-fast-non-reasoning | 2.0M | $2 | $3 | |||||
aimlapi/xiaomi/mimo-v2.5 | 1.0M | $0.19 | $0.39 | |||||
aimlapi/xiaomi/mimo-v2.5-pro | 1.0M | $0.60 | $1 | |||||
aimlapi/z-ai/glm-4.5v | 66K | $0.83 | $2 | |||||
aimlapi/z-ai/glm-4.6v | 131K | $0.41 | $1 | |||||
aimlapi/z-ai/glm-4.7-flash | 203K | $0.17 | $0.69 | |||||
aimlapi/z-ai/glm-5-turbo | 262K | $2 | $5 | |||||
aimlapi/z-ai/glm-5.3-flash | 1.0M | $0.20 | $0.65 | |||||
aimlapi/z-ai/glm-5v-turbo | 203K | $2 | $5 | |||||
aimlapi/zhipu/glm-5.2 | 1.0M | $2 | $6 | |||||
aimlapi/zhipu/glm-5.3 | 1.0M | $2 | $6 |
Model availability, capabilities, context windows, and pricing are sourced from models.dev and may change.
Advanced configurationDirect link to Advanced configuration
Custom headersDirect link to 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 selectionDirect link to 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";
}
});