Skip to main content

Prime Inference logoPrime Inference

Access 64 Prime Inference models through Mastra's model router. Authentication is handled automatically using the PRIME_API_KEY environment variable.

Learn more in the Prime Inference documentation.

.env
PRIME_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: "prime/anthropic/claude-fable-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);
}
note

Mastra uses the OpenAI-compatible /chat/completions endpoint. Some provider-specific features may not be available. Check the Prime Inference documentation for details.

Models
Direct link to Models

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
prime/anthropic/claude-fable-51.0M$10$50
prime/anthropic/claude-fable-5.11.0M$10$50
prime/anthropic/claude-opus-4.61.0M$5$25
prime/anthropic/claude-opus-4.71.0M$5$25
prime/anthropic/claude-opus-4.81.0M$5$25
prime/anthropic/claude-opus-51.0M$5$25
prime/anthropic/claude-opus-5.51.0M$4$20
prime/anthropic/claude-sonnet-4.61.0M$3$15
prime/anthropic/claude-sonnet-51.0M$2$10
prime/deepseek/deepseek-v4-flash1.0M$0.44$1
prime/deepseek/deepseek-v4-flash-07311.0M$0.44$1
prime/deepseek/deepseek-v4-pro1.0M$2$4
prime/deepseek/deepseek-v4.1-flash1.0M$0.30$1
prime/google/gemini-3-flash-preview1.0M$0.50$3
prime/google/gemini-3.1-pro-preview1.0M$2$12
prime/google/gemini-3.5-flash1.0M$2$9
prime/google/gemini-3.6-flash1.0M$2$8
prime/google/gemini-3.7-flash1.0M$1$7
prime/google/gemini-3.8-flash1.0M$0.75$4
prime/google/gemma-3-27b-it131K$0.12$0.30
prime/meta-llama/llama-3.3-70b-instruct131K$1$2
prime/mistralai/mistral-large-2512262K$0.50$2
prime/mistralai/mistral-nemo131K$0.17$0.17
prime/mistralai/mistral-small-2603262K$0.17$0.66
prime/mistralai/mixtral-8x22b-instruct66K$2$7
prime/moonshotai/kimi-k2-0905262K$0.60$3
prime/moonshotai/kimi-k31.0M$3$17
prime/openai/gpt-4.11.0M$2$8
prime/openai/gpt-4.1-mini1.0M$0.40$2
prime/openai/gpt-4.1-nano1.0M$0.10$0.40
prime/openai/gpt-4o128K$3$10
prime/openai/gpt-4o-mini128K$0.15$0.60
prime/openai/gpt-5400K$1$10
prime/openai/gpt-5-mini400K$0.25$2
prime/openai/gpt-5-nano400K$0.05$0.40
prime/openai/gpt-5.1400K$1$10
prime/openai/gpt-5.2400K$2$14
prime/openai/gpt-5.2-pro400K$21$168
prime/openai/gpt-5.3-codex400K$2$14
prime/openai/gpt-5.41.1M$3$15
prime/openai/gpt-5.4-mini400K$0.75$5
prime/openai/gpt-5.4-nano400K$0.20$1
prime/openai/gpt-5.4-pro1.1M$30$180
prime/openai/gpt-5.51.1M$5$30
prime/openai/gpt-5.6-luna1.1M$0.20$1
prime/openai/gpt-5.6-luna-pro1.1M$1$6
prime/openai/gpt-5.6-sol1.1M$5$30
prime/openai/gpt-5.6-sol-pro1.1M$5$30
prime/openai/gpt-5.6-terra1.1M$3$15
prime/openai/gpt-5.6-terra-pro1.1M$3$15
prime/openai/gpt-6-astra1.1M$10$50
prime/openai/gpt-6-luna1.1M$0.10$0.50
prime/openai/gpt-6-sol1.1M$2$10
prime/openai/gpt-6.1-sol1.1M$2$10
prime/openai/gpt-oss-120b131K$0.35$0.75
prime/openai/gpt-oss-20b131K$0.07$0.30
prime/qwen/qwen3-coder-next262K$0.30$2
prime/qwen/qwen3-vl-235b-a22b-instruct262K$0.30$2
prime/qwen/qwen3-vl-30b-a3b-instruct262K$0.20$0.70
prime/x-ai/grok-4.6500K$2$6
prime/x-ai/grok-4.7500K$2$5
prime/z-ai/glm-5.21.0M$2$5
prime/z-ai/glm-5.31.0M$1$4
prime/z-ai/glm-5.3-flash1.0M$0.15$0.50
64 available models

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

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: {
url: "https://api.pinference.ai/api/v1",
id: "prime/anthropic/claude-fable-5",
apiKey: process.env.PRIME_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
? "prime/z-ai/glm-5.3-flash"
: "prime/anthropic/claude-fable-5";
}
});