Skip to main content

Anthropic Messages

POST https://gateway-api.mastra.ai/v1/messages

Compatible with the Anthropic Messages API, including streaming, tools, and extended thinking. Errors on this endpoint use the Anthropic error format.

Request
Direct link to Request

Authenticate with x-api-key or Authorization: Bearer:

curl https://gateway-api.mastra.ai/v1/messages \
-H "x-api-key: $MASTRA_GATEWAY_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-haiku-5.5",
"max_tokens": 100,
"messages": [{ "role": "user", "content": "Hello, Claude." }]
}'

Anthropic SDK
Direct link to Anthropic SDK

The SDK appends /v1/messages, so set the base URL without /v1:

import Anthropic from '@anthropic-ai/sdk'

const client = new Anthropic({
apiKey: process.env.MASTRA_GATEWAY_API_KEY,
baseURL: 'https://gateway-api.mastra.ai',
})

const message = await client.messages.create({
model: 'anthropic/claude-haiku-5.5',
max_tokens: 100,
messages: [{ role: 'user', content: 'Hello, Claude.' }],
})

Extended thinking
Direct link to Extended thinking

When a conversation includes signed thinking blocks from an earlier turn, Gateway routes the next turn to a provider that can verify them. This can narrow failover for that request.

On this page