POST/v1/messages
Messages
POST /v1/messages: create a message in the Anthropic Messages format, for Claude and the other models that support it.
Die Dokumentation ist auf Englisch.
Creates a message in the Anthropic Messages format. Works with the models that list /v1/messages in their endpoints: the Anthropic models and a number of others. Other models return 400 unsupported_endpoint.
Base URL: https://api.nexrouting.com/v1 (also https://nexrouting.com/api/v1).
With the Anthropic SDK, use https://api.nexrouting.com as base URL: the SDK adds /v1/messages itself. See Anthropic SDK.
Headers
x-api-keystringrequired- Your key.
Authorization: Bearer <key>works too. anthropic-versionstring- Passed on to the model provider.
2023-06-01when you leave it out. anthropic-betastring- Passed on to the model provider. Whether a beta works depends on the model.
Content-Typestringapplication/json. The body is read as JSON either way.
Body
modelstringrequired- Model ID, such as
anthropic/claude-sonnet-5.5. max_tokensintegerrequired- Upper limit for output tokens.
messagesarrayrequired- The conversation:
userandassistantturns with text, image or tool blocks. systemstring | array- The system prompt.
streambooleantrueto receive server-sent events. See Streaming.tools, tool_choice, thinking, …- Passed on as they are, as in the Anthropic API.
cache_controlon blocks works for prompt caching; see Pricing & usage.
The gateway checks model and stream. Everything else in the body goes to the model provider unchanged, in the Anthropic format, so which other parameters work depends on the model. When the provider rejects a parameter, you get 400 invalid_request with its reason.
Example request
curl https://api.nexrouting.com/v1/messages \ -H "x-api-key: $NEXROUTING_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "anthropic/claude-sonnet-5.5", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello"}] }'Example response
{ "id": "msg_01XfK2", "type": "message", "role": "assistant", "model": "anthropic/claude-sonnet-5.5", "content": [{ "type": "text", "text": "Hello! How can I help you today?" }], "stop_reason": "end_turn", "stop_sequence": null, "usage": { "input_tokens": 9, "output_tokens": 12, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0 }}Billed input is input_tokens plus the cache tokens; output is output_tokens.
Errors
Anthropic error shape, {"type": "error", "error": {"type": "…", "message": "…"}}, without a code. The error.type per status is in Errors.
Not available
/v1/messages/count_tokens and the Message Batches endpoints return 404 not_found.