CrossModel

Messages

POST /v1/messages

Generate a reply using the Anthropic Messages protocol. Send a list of conversation messages and the model returns the next assistant message. Ideal when you're using the Anthropic SDK or Claude Code.

This endpoint is compatible with the Anthropic Messages SDK. Point base_url at CrossModel and set model to a CrossModel model ID. Auth uses the x-api-key header.

Endpoint

POST https://api.crossmodel.ai/v1/messages
x-api-key: cm-YOUR_KEY
anthropic-version: 2023-06-01
Content-Type: application/json

Each request needs an API key in the x-api-key header (Authorization: Bearer also works). Create and manage keys on the console's API Keys page.

$
Create message
1curl https://api.crossmodel.ai/v1/messages \2  -H "Content-Type: application/json" \3  -H "anthropic-version: 2023-06-01" \4  -H "x-api-key: $CROSSMODEL_API_KEY" \5  -d '{6    "model": "anthropic/claude-sonnet-4.6",7    "max_tokens": 1024,8    "system": "You are a helpful assistant.",9    "messages": [10      { "role": "user", "content": "Hello!" }11    ]12  }'

Request parameters

ParameterTypeRequiredNotes
modelstringYesThe model ID to use, e.g. anthropic/claude-sonnet-4.6. Call /v1/models for the full list.
messagesarrayYesThe conversation so far, in chronological order, with at least one entry. See Message object below.
max_tokensintegerYesMax tokens to generate for this reply.
systemstring or arrayNoA system prompt that sets the model's behavior and persona.
temperaturenumberNoSampling temperature, typically 01. Higher is more random and varied.
top_pnumberNoNucleus-sampling threshold. Usually adjust either temperature or top_p, not both.
top_kintegerNoSample only from the K highest-probability candidates.
stop_sequencesstring[]NoCustom stop sequences. Generation halts at the first match.
toolsarrayNoThe tools the model may call. See Function tools below.
tool_choiceobjectNoControls whether and how the model calls tools.
metadataobjectNoRequest metadata; may include user_id for safety and abuse detection.
thinkingobjectNoExtended-thinking config. type is enabled, disabled, or adaptive; when enabled, provide budget_tokens. The effect depends on the model.
streambooleanNoWhether to stream the result. Default false.

Message object

messages is a chronological array with at least one message.

FieldTypeRequiredNotes
rolestringYesThe sender's role; only user and assistant. Put the system prompt in the top-level system field, not in messages.
contentstring or arrayYesThe message content. Use a string for plain text; use a content-block array for images or tool content (see Content blocks).

Content blocks

When content is an array, each element is a content block with a type field:

typeFieldsNotes
texttextA piece of text.
imagesourceImage input. source is { "type": "base64", "media_type": ..., "data": ... } or { "type": "url", "url": ... }.
tool_useid, name, inputA tool call issued by the assistant.
tool_resulttool_use_id, content, is_errorThe result of running a tool; tool_use_id points at the corresponding tool_use.

Document and PDF input (the document content block) isn't supported yet.

Function tools

Declare functions the model can call via the tools field. The model returns a tool_use content block when needed; your code runs it and passes the result back as a tool_result content block.

{
  "tools": [
    {
      "name": "get_weather",
      "description": "Get current weather for a city.",
      "input_schema": {
        "type": "object",
        "properties": {
          "city": { "type": "string" }
        },
        "required": ["city"]
      }
    }
  ]
}
FieldTypeRequiredNotes
namestringYesThe function name the model uses to reference the tool.
descriptionstringNoWhat the function does. A clear description helps the model decide when to call it.
input_schemaobjectNoJSON Schema for the function's parameters.

Example request

curl https://api.crossmodel.ai/v1/messages \
  -H "x-api-key: cm-YOUR_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "max_tokens": 1024,
    "system": "You are a helpful assistant.",
    "messages": [
      { "role": "user", "content": "Hello!" }
    ]
  }'

Response

A non-streaming request returns a message object.

{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "anthropic/claude-sonnet-4.6",
  "content": [
    { "type": "text", "text": "Hello! How can I help?" }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 18,
    "output_tokens": 14,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0
  }
}
FieldTypeNotes
idstringA unique ID for this reply.
typestringAlways message.
rolestringAlways assistant.
modelstringThe model ID used for this request.
contentarrayThe generated content blocks.
stop_reasonstringWhy it stopped — see below.
stop_sequencestring or nullThe stop sequence that was matched, or null if none.
usageobjectToken usage for this request, used for billing.

Response content blocks

In the response content array, each element is a content block with a type field:

typeFieldsNotes
texttextThe generated text.
tool_useid, name, inputA function call issued by the model. input is the arguments object.

stop_reason

ValueNotes
end_turnThe model finished its reply naturally.
max_tokensHit the max_tokens cap.
stop_sequenceMatched a stop sequence.
tool_useThe model switched to issuing a tool call.

The usage object

FieldTypeNotes
input_tokensintegerInput tokens.
output_tokensintegerOutput tokens.
cache_creation_input_tokensintegerInput tokens written to the cache.
cache_read_input_tokensintegerInput tokens that hit the cache.

Streaming response

Set stream to true and the endpoint returns text/event-stream. A reply is made up of these events, in order:

EventNotes
message_startThe message begins, with initial message info.
content_block_startA content block begins.
content_block_deltaAn increment of a content block (text_delta, input_json_delta, or thinking_delta).
content_block_stopA content block ends.
message_deltaCarries stop_reason and usage.
message_stopThe message ends.
curl https://api.crossmodel.ai/v1/messages \
  -H "x-api-key: cm-YOUR_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4.6",
    "max_tokens": 1024,
    "messages": [{ "role": "user", "content": "Hi" }],
    "stream": true
  }'

Errors

Errors use the Anthropic format:

{
  "type": "error",
  "error": {
    "type": "authentication_error",
    "message": "Missing API key."
  }
}
HTTP statuserror.typeNotes
400invalid_request_errorMalformed body JSON, message structure, or parameters.
401authentication_errorAPI key missing or invalid.
402permission_errorOut of balance or not permitted.
404invalid_request_errorThe requested model doesn't exist or is currently unavailable.
429rate_limit_errorToo many requests — rate limited.
502api_errorThe model service returned an error or an abnormal response.
503overloaded_errorModel temporarily unavailable — retry shortly.
500api_errorA CrossModel internal error.