Skip to main content

Opper logoOpper

Access 40 Opper models through Mastra's model router. Authentication is handled automatically using the OPPER_API_KEY environment variable.

Learn more in the Opper documentation.

.env
OPPER_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: "opper/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 Opper documentation for details.

Models
Direct link to Models

ModelContextToolsReasoningImageAudioVideoInput $/1MOutput $/1M
opper/anthropic/claude-fable-51.0M$10$50
opper/anthropic/claude-haiku-4-5200K$1$5
opper/anthropic/claude-opus-4-5200K$5$25
opper/anthropic/claude-opus-4-61.0M$5$25
opper/anthropic/claude-opus-4-71.0M$5$25
opper/anthropic/claude-opus-4-81.0M$5$25
opper/anthropic/claude-opus-51.0M$5$25
opper/anthropic/claude-sonnet-4-5200K$3$15
opper/anthropic/claude-sonnet-4-61.0M$3$15
opper/anthropic/claude-sonnet-51.0M$2$10
opper/gemini/gemini-3-flash-preview1.0M$0.50$3
opper/gemini/gemini-3.1-pro-preview1.0M$2$12
opper/gemini/gemini-3.5-flash1.0M$2$9
opper/gemini/gemini-3.5-flash-lite1.0M$0.30$3
opper/meta/muse-spark-1.21.0M$1$4
opper/minimax/m31.0M$0.60$2
opper/mistral/devstral-2512262K$0.40$2
opper/mistral/mistral-large-2512262K$0.50$2
opper/mistral/mistral-small-2603256K$0.15$0.60
opper/moonshot/kimi-k31.0M$3$15
opper/openai/gpt-5.3-chat-latest128K$2$14
opper/openai/gpt-5.3-codex400K$2$14
opper/openai/gpt-5.41.1M$3$15
opper/openai/gpt-5.4-mini400K$0.75$5
opper/openai/gpt-5.4-nano400K$0.20$1
opper/openai/gpt-5.4-pro1.1M$30$180
opper/openai/gpt-5.51.1M$5$30
opper/openai/gpt-5.5-pro1.1M$30$180
opper/openai/gpt-5.6-luna1.1M$0.20$1
opper/openai/gpt-5.6-sol1.1M$5$30
opper/openai/gpt-5.6-terra1.1M$2$12
opper/perplexity/sonar128K$1$1
opper/perplexity/sonar-pro200K$3$15
opper/perplexity/sonar-reasoning-pro128K$2$8
opper/vertexai/gemini-3.7-flash1.0M$0.75$4
opper/vertexai/gemini-3.7-flash-eu1.0M$0.75$4
opper/xai/grok-4.31.0M$1$3
opper/xai/grok-4.5500K$2$6
opper/xai/grok-4.6500K$2$6
opper/xai/grok-build-0.1256K$1$2
40 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.opper.ai/v3/compat",
id: "opper/anthropic/claude-fable-5",
apiKey: process.env.OPPER_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
? "opper/xai/grok-build-0.1"
: "opper/anthropic/claude-fable-5";
}
});
On this page