Skip to main content
Mastra is a TypeScript framework for building agents, workflows, and RAG applications. Opper is a first-class provider in Mastra’s model router — there is no base URL to configure and no compatibility shim to set up. Prefix a model with opper/ and Mastra handles the rest.

Setup

Set your key in the environment:
Then name any Opper model on an agent:
Mastra picks up OPPER_API_KEY automatically — no client construction, no baseURL.

Choosing a model

Model IDs are the catalog ID with an opper/ 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 for model, so you can pick per request — cheap model for routine work, frontier model for the hard path:
To move that decision off your code entirely, deploy a routing graph and name it once instead.

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.

Routing graphs

Move model choice out of application code.

Vercel AI SDK

The other TypeScript toolkit with an Opper provider.