Skip to main content

Deep Infra logoDeep Infra

Access 25 Deep Infra models through Mastra's model router. Authentication is handled automatically using the DEEPINFRA_API_KEY environment variable.

Learn more in the Deep Infra documentation.

.env
DEEPINFRA_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: "deepinfra/MiniMaxAI/MiniMax-M2.5"
});

// 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);
}

Models
Direct link to Models

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
deepinfra/deepseek-ai/DeepSeek-R1-0528164K$0.50$2
deepinfra/deepseek-ai/DeepSeek-V3.2164K$0.26$0.38
deepinfra/deepseek-ai/DeepSeek-V4-Flash1.0M$0.10$0.20
deepinfra/deepseek-ai/DeepSeek-V4-Pro1.0M$1$3
deepinfra/google/gemma-4-26B-A4B-it262K$0.07$0.34
deepinfra/google/gemma-4-31B-it262K$0.13$0.38
deepinfra/meta-llama/Llama-3.3-70B-Instruct-Turbo131K$0.10$0.32
deepinfra/meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP81.0M$0.15$0.60
deepinfra/meta-llama/Llama-4-Scout-17B-16E-Instruct328K$0.10$0.30
deepinfra/MiniMaxAI/MiniMax-M2.5197K$0.15$1
deepinfra/moonshotai/Kimi-K2.5262K$0.45$2
deepinfra/moonshotai/Kimi-K2.6262K$0.75$4
deepinfra/openai/gpt-oss-120b131K$0.04$0.19
deepinfra/openai/gpt-oss-20b131K$0.03$0.14
deepinfra/Qwen/Qwen3-Coder-480B-A35B-Instruct-Turbo262K$0.30$1
deepinfra/Qwen/Qwen3.5-35B-A3B262K$0.14$1
deepinfra/Qwen/Qwen3.5-397B-A17B262K$0.45$3
deepinfra/Qwen/Qwen3.6-35B-A3B262K$0.15$0.95
deepinfra/XiaomiMiMo/MiMo-V2.5262K$0.40$2
deepinfra/XiaomiMiMo/MiMo-V2.5-Pro1.0M$1$3
deepinfra/zai-org/GLM-4.6203K$0.43$2
deepinfra/zai-org/GLM-4.7203K$0.40$2
deepinfra/zai-org/GLM-4.7-Flash203K$0.06$0.40
deepinfra/zai-org/GLM-5203K$0.60$2
deepinfra/zai-org/GLM-5.1203K$1$4
25 available models

Advanced configuration
Direct link to Advanced configuration

Custom headers
Direct link to Custom headers

src/mastra/agents/my-agent.ts
const agent = new Agent({
id: "custom-agent",
name: "custom-agent",
model: {
id: "deepinfra/MiniMaxAI/MiniMax-M2.5",
apiKey: process.env.DEEPINFRA_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});

Dynamic model selection
Direct 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
? "deepinfra/zai-org/GLM-5.1"
: "deepinfra/MiniMaxAI/MiniMax-M2.5";
}
});

Direct provider installation
Direct link to Direct provider installation

This provider can also be installed directly as a standalone package, which can be used instead of the Mastra model router string. View the package documentation for more details.

npm install @ai-sdk/deepinfra

For detailed provider-specific documentation, see the AI SDK Deep Infra provider docs.