docs

Messages (Anthropic format)

POST/v1/messagesAnthropic Messages API shape

Some tools speak only the Anthropic Messages protocol: Claude Code, the Anthropic SDKs, and apps built on them. This endpoint accepts that request shape and answers in that response shape, so those tools work with an OSMEXO key. It serves every text model on OSMEXO, not only Claude: the same request can run on anthropic/claude-opus-5.5, z-ai/glm-5.4 or any other id from /v1/models.

Pricing, limits, retries and errors are the same as for Chat Completions.

Connect a client

Anthropic clients add /v1/messages themselves, so give them the base URL without /v1:

SettingValue
Base URL__GATEWAY_URL__
API keyyour sk-llm-… key
Modelan OSMEXO id such as anthropic/claude-sonnet-5.5, or Anthropic's own name for a Claude model

The key is accepted in either header: x-api-key: sk-llm-… (what Anthropic SDKs send) or Authorization: Bearer sk-llm-…. The anthropic-version header is accepted and ignored.

For Claude Code, see Coding agents.

Request

bash
curl "https://api.osmexo.com/v1/messages" \
  -H "x-api-key: $OSMEXO_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5.5",
    "max_tokens": 1024,
    "system": "You are a terse assistant.",
    "messages": [
      { "role": "user", "content": "What is the capital of France?" }
    ]
  }'

With the Anthropic SDK, change only the base URL and the key:

python
from anthropic import Anthropic

client = Anthropic(base_url="https://api.osmexo.com", api_key="sk-llm-…")
message = client.messages.create(
    model="anthropic/claude-sonnet-5.5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "What is the capital of France?"}],
)
print(message.content[0].text)

Supported fields

FieldNotes
model, requiredAn OSMEXO id (vendor/name). Anthropic's names for Claude models also work: claude-opus-5-5 and dated forms such as claude-opus-5-5-20260401 are matched to anthropic/claude-opus-5.5.
max_tokens, requiredIf it is above the model's output limit, the request runs at that limit instead of failing.
messages, requireduser and assistant turns. Content is a string or an array of blocks, see below. A system turn inside messages is accepted too.
systemA string or an array of text blocks.
streamAnthropic event stream, see Streaming.
temperature, top_p
stop_sequencesUp to 4 are used.
toolsYour own tools: { name, description, input_schema }.
tool_choiceauto, any, none or { type: "tool", name }. disable_parallel_tool_use is honoured.
metadata.user_idStored as the end-user id.

Content blocks

BlockIn a requestIn a response
textYes. A cache_control marker on it is kept, so prompt caching works.Yes
imageYes, with a base64 or url source, on models with image input.No
tool_useYes, in assistant turns.Yes
tool_resultYes, in user turns. Text content is passed to the model.No
thinkingAccepted and left out: earlier reasoning is not sent back to the model.Yes, on reasoning models, with an empty signature.
document and other blocks400 invalid_request_error.No

Not supported: the thinking request setting (the model decides for itself), tools that Anthropic runs on its side (web search, code execution and similar; they are left out of the request), message batches and files.

Response

json
{
  "id": "msg_01M9…",
  "type": "message",
  "role": "assistant",
  "model": "anthropic/claude-sonnet-5.5",
  "content": [{ "type": "text", "text": "Paris." }],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 24,
    "output_tokens": 2,
    "cache_read_input_tokens": 0,
    "cache_creation_input_tokens": 0
  }
}
FieldNotes
modelThe model name you sent.
stop_reasonend_turn, max_tokens, tool_use or refusal.
usage.input_tokensFresh input only. Cached input is counted apart, in cache_read_input_tokens and cache_creation_input_tokens, as Anthropic does.

What the request cost is in the X-LLM-Cost-Micro response header and in the dashboard; see response headers.

Tool calls

The model answers with a tool_use block and stop_reason: "tool_use". Send the result back as a tool_result block in the next user turn:

json
{
  "role": "user",
  "content": [
    { "type": "tool_result", "tool_use_id": "call_1", "content": "18°C, sunny" }
  ]
}

Streaming

With "stream": true the response is the Anthropic event stream. Every frame has an event: name and a JSON data: object whose type repeats that name:

text
event: message_start
event: content_block_start      (text, thinking or tool_use)
event: content_block_delta      (text_delta, thinking_delta or input_json_delta)
event: content_block_stop
event: message_delta            (stop_reason and the final usage)
event: message_stop

There is no [DONE] frame on a successful stream; message_stop ends it. A failure after the first event arrives as event: error. Before the first event, a failure is a normal JSON error with its status code.

Count tokens

POST/v1/messages/count_tokensestimate

Takes the same body (without max_tokens) and returns { "input_tokens": n }. The number is an estimate from the size of the request, about four characters per token, not the model's own tokenizer. No model is called and nothing is charged. Use usage on a real response for the exact count.

Errors

The status codes and their meaning are the same as everywhere else, see Errors. The body uses Anthropic's shape, so Anthropic SDKs raise their usual exceptions:

json
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "code": "validation_failed",
    "message": "max_tokens is required and must be positive",
    "param": "max_tokens",
    "request_id": "req_01M9…"
  }
}
HTTPerror.type
400invalid_request_error
401authentication_error
402billing_error
403permission_error
404not_found_error
413request_too_large
429rate_limit_error
503overloaded_error
other 5xxapi_error

error.code keeps the OSMEXO code (for example insufficient_credits), which is the one to act on.