opper/ and Mastra handles the rest.
Setup
Set your key in the environment:OPPER_API_KEY automatically — no client construction, no baseURL.
Choosing a model
Model IDs are the catalog ID with anopper/ prefix: opper/anthropic/claude-sonnet-5, opper/openai/gpt-5.5, opper/xai/grok-4.6. Mastra’s router ships a snapshot of the catalog with context windows and per-token pricing, sourced from models.dev.
Because that list is a snapshot, a model added to Opper very recently may not appear in Mastra’s router yet. Name it explicitly with the object form below, or check the Opper catalog for what’s live.
Routing per request
Mastra accepts a function formodel, so you can pick per request — cheap model for routine work, frontier model for the hard path:
Custom headers
The object form takes explicit configuration, which is also how you attach usage tags:Mastra routes through Opper’s OpenAI-compatible
/chat/completions surface. Opper features that live outside that surface — structured output beyond response_format, realtime, and the audio and image endpoints — need a direct call rather than the Mastra agent.Related
Routing graphs
Move model choice out of application code.
Vercel AI SDK
The other TypeScript toolkit with an Opper provider.