Messages
Send Anthropic-compatible conversations to https://api.livrouter.com/v1/messages. This protocol uses content blocks and a top-level system instruction. It has a different response and stream format from Chat Completions.
Send a request
curl https://api.livrouter.com/v1/messages \ -H "x-api-key: $OPENAI_API_KEY" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "YOUR_MESSAGES_MODEL_ID", "max_tokens": 256, "system": "Answer concisely.", "messages": [{"role": "user", "content": "Say hello in one sentence."}] }'Replace YOUR_MESSAGES_MODEL_ID with a Messages-compatible model from your catalog. Set OPENAI_API_KEY to your LivRouter key as shown in Quickstart; the variable name does not change the request protocol.
Request fields
| Field | Type | Notes |
|---|---|---|
| model | string, required | Exact ID of a model supporting Messages. |
| messages | array, required | Ordered user and assistant turns; content can contain supported blocks. |
| max_tokens | integer, required | Maximum number of output tokens. Stay within the model limits. |
| system | string or content blocks | Top-level instruction; do not add a system-role message. |
| stream | boolean | Return named server-sent events when true. |
| tools | array, optional | Requires model and route support for tool use. |
Read the response
Illustrative response fields are shown below; IDs, tokens, model names, and stop reasons vary. Collect text from content blocks whose type is text, rather than assuming the first block always contains text.
{ "id": "msg_example", "type": "message", "role": "assistant", "content": [{"type": "text", "text": "Hello! How can I help?"}], "stop_reason": "end_turn", "usage": {"input_tokens": 12, "output_tokens": 9}}Streaming and tools
Add "stream": true and use curl -N for an unbuffered terminal test. Parse named events such as message_start, content_block_delta, and message_stop. Messages streams do not use the Chat Completions [DONE] convention.
A tool_use block asks your application to execute a tool. Return its result in the matching tool_result block and continue the conversation. See Function calling for the application-side workflow.
SDK setup and troubleshooting
Use the Anthropic SDK guide or Claude Code guide for client configuration. A repeated /v1/v1/messages path means the SDK base URL includes an extra version prefix. Check errors and usage logs if the model or authentication fails.