Skip to main content

Quickstart

Add credits, create an API key, then send a request to any supported model.

Add credits
Direct link to Add credits

Gateway uses prepaid credit, so add credits before your first request. Without credit, requests return 402.

  1. Sign in at projects.mastra.ai.
  2. Open Billing in your organization and add credits.

Optionally turn on auto top-up so requests don't fail when your balance runs low.

Create an API key
Direct link to Create an API key

  1. Open Gateway > API keys and select Create key.
  2. Copy the key. It starts with msk-gateway- and is shown only once.

Store the key in an environment variable:

.env
MASTRA_GATEWAY_API_KEY="msk-gateway-..."

Send a request
Direct link to Send a request

curl https://gateway-api.mastra.ai/v1/chat/completions \
-H "Authorization: Bearer $MASTRA_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-6.1-sol",
"messages": [{ "role": "user", "content": "Say hello in one word." }]
}'

Change the model value to call another provider, for example anthropic/claude-sonnet-5.5. Find more models in the model catalog, or list them with GET /v1/models.

The response includes an x-request-id header. Use it to find the request in your usage logs.

Use Gateway from a Mastra agent
Direct link to Use Gateway from a Mastra agent

Set MASTRA_GATEWAY_API_KEY, then use a model ID with the mastra/ prefix:

src/mastra/agents/assistant.ts
import { Agent } from '@mastra/core/agent'

export const assistant = new Agent({
id: 'assistant',
name: 'Assistant',
instructions: 'You are a helpful assistant.',
model: 'mastra/openai/gpt-6.1-sol',
})

Next steps
Direct link to Next steps

On this page