Your first request
Every example below sends the same prompt. They assume a secret key in MODELRELAY_API_KEY; see Getting started to create one. Use any model ID from the models page or mrl model list.
Responses API
POST /api/v1/responses is ModelRelay’s provider-neutral API. The same request shape works for every model. Send the key in X-ModelRelay-Api-Key; this endpoint rejects secret keys sent as Authorization: Bearer.
curl https://api.modelrelay.ai/api/v1/responses \
-H "X-ModelRelay-Api-Key: $MODELRELAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"input": [
{"type": "message", "role": "user", "content": [{"type": "text", "text": "What is the capital of France?"}]}
]
}'
The response contains output items, usage, the model, and a stop reason. See the Responses API reference for the full schema.
OpenAI SDK
The /v1 endpoints accept the OpenAI wire format. Set the base URL to https://api.modelrelay.ai/v1 and pass your ModelRelay key as the API key.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["MODELRELAY_API_KEY"],
base_url="https://api.modelrelay.ai/v1",
)
completion = client.chat.completions.create(
model="claude-sonnet-5-5",
messages=[{"role": "user", "content": "What is the capital of France?"}],
)
print(completion.choices[0].message.content)
client.responses.create(...) works against POST /v1/responses with the same client. Without an SDK:
curl https://api.modelrelay.ai/v1/chat/completions \
-H "Authorization: Bearer $MODELRELAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"messages": [{"role": "user", "content": "What is the capital of France?"}]
}'
See Chat Completions compatibility for supported fields.
Anthropic SDK
POST /v1/messages accepts the Anthropic Messages format. The Anthropic SDK adds /v1/messages to its base URL, so set the base URL to https://api.modelrelay.ai.
import os
import anthropic
client = anthropic.Anthropic(
api_key=os.environ["MODELRELAY_API_KEY"],
base_url="https://api.modelrelay.ai",
)
message = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "What is the capital of France?"}],
)
print(message.content[0].text)
Without an SDK:
curl https://api.modelrelay.ai/v1/messages \
-H "x-api-key: $MODELRELAY_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "What is the capital of France?"}]
}'
See Messages compatibility for supported fields.
mrl
mrl "What is the capital of France?" --model claude-sonnet-5-5
Add --stream to print output as it arrives and --usage to print token usage. Piped input is prepended to the prompt:
git diff | mrl "Explain these changes" --model claude-sonnet-5-5
Set a default model with mrl config set --model claude-sonnet-5-5 to omit --model. See the CLI reference.
Next steps
- Streaming
- Tool use
- Structured output
- Reasoning effort
- Error handling
- SDK compatibility — TypeScript examples, streaming, and field mappings