Messages

Call OpenGateway’s Anthropic-compatible Messages endpoint with catalog-supported models, Bearer or x-api-key authentication, streaming events, and SDK examples.

POST /v1/messages accepts the Anthropic Messages request format. OpenGateway routes it only to models that advertise messages support and relays the Anthropic-style response.

Endpoint#

POST https://apis.opengateway.ai/v1/messages

Authentication#

Use Authorization: Bearer <key> as the default. The Messages endpoint also accepts x-api-key, but only when the request has no Authorization header. If both headers are sent, Authorization takes precedence; an empty or invalid Bearer value returns 401 and does not fall back to x-api-key.

Model support#

Call a model only when its entry in the public GET /v1/models catalog lists messages in endpoints. The featured UltraFast model deepseek/deepseek-v4.1-flash-ultrafast supports Messages. A key restricted to an allowlist sees only the models it can use.

Request body#

Send the standard Anthropic Messages body with model, max_tokens, and messages. Fields such as system, temperature, tools, and tool_choice follow the selected model’s Anthropic-compatible support. The data plane requires a JSON object and a non-empty model, then forwards the request to the provider; the provider validates the rest of the Messages body.

OpenGateway consumes extra.fallbacks when supplied and removes extra before forwarding the request. It rewrites the public model ID for the upstream call and returns the public catalog ID in the response. The anthropic-version and anthropic-beta headers are forwarded when present.

Non-streaming response#

A successful response uses the Anthropic Message shape. The gateway rewrites id to its request ID and model to the public catalog model ID; the rest of the response follows the provider’s Messages response.

JSON
{
"id": "msg_example",
"type": "message",
"role": "assistant",
"model": "deepseek/deepseek-v4.1-flash-ultrafast",
"content": [{"type": "text", "text": "Hello!"}],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {"input_tokens": 12, "output_tokens": 4}
}

Streaming events#

Set stream: true to receive Anthropic server-sent events. The data plane passes through the Messages event stream; it rewrites the ID and public model in message_start. Common event names include message_start, content_block_start, content_block_delta, content_block_stop, message_delta, and message_stop. Tool input may arrive in input_json_delta pieces.

cURL example#

Bash
curl https://apis.opengateway.ai/v1/messages \
-H "Authorization: Bearer $OPENGATEWAY_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek/deepseek-v4.1-flash-ultrafast",
"max_tokens": 256,
"messages": [{"role": "user", "content": "Hello"}]
}'

Anthropic SDK examples#

Pass the OpenGateway key with authToken in TypeScript or auth_token in Python. These options send Authorization: Bearer and avoid relying on the SDK’s default x-api-key header.

TypeScript#

TypeScript
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
baseURL: "https://apis.opengateway.ai",
authToken: process.env.OPENGATEWAY_API_KEY,
});
const message = await anthropic.messages.create({
model: "deepseek/deepseek-v4.1-flash-ultrafast",
max_tokens: 256,
messages: [{ role: "user", content: "Hello" }],
});
console.log(message.content);

Python#

Python
import os
from anthropic import Anthropic
client = Anthropic(
base_url="https://apis.opengateway.ai",
auth_token=os.environ["OPENGATEWAY_API_KEY"],
)
message = client.messages.create(
model="deepseek/deepseek-v4.1-flash-ultrafast",
max_tokens=256,
messages=[{"role": "user", "content": "Hello"}],
)
print(message.content)

See also#

Messages — OpenGateway