Skip to content

Messages

The Messages API is the primary way to interact with Claude models through Claudexia. Send a structured list of messages and receive a model-generated response.

Endpoint

http
POST https://api.claudexia.tech/v1/messages

Authentication

Include your API key in the x-api-key header:

http
x-api-key: sk_cdx_YOUR_KEY

Request Body

ParameterTypeRequiredDescription
modelstringYesThe model ID to use (e.g. claude-sonnet-4-20250514).
max_tokensintegerYesMaximum number of tokens to generate.
messagesarrayYesArray of message objects with role ("user" or "assistant") and content (string or array of content blocks).
systemstringNoSystem prompt to guide the model's behavior.
temperaturenumberNoSampling temperature between 0 and 1. Default: 1.
top_pnumberNoNucleus sampling parameter. Default: 0.999.
streambooleanNoIf true, returns a stream of Server-Sent Events. Default: false.
thinkingobjectNoEnable extended thinking. See Thinking below.

Response

FieldTypeDescription
idstringUnique message ID (e.g. msg_01XFDUDYJgAACzvnptvVoYEL).
typestringAlways "message".
rolestringAlways "assistant".
contentarrayArray of content blocks. Each block has type ("text") and text.
modelstringThe model that generated the response.
stop_reasonstringWhy the model stopped: "end_turn", "max_tokens", or "stop_sequence".
usageobjectToken usage with input_tokens and output_tokens.

Example

Request

bash
curl https://api.claudexia.tech/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: sk_cdx_YOUR_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4.5",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello, Claude!"}
    ]
  }'

Response

json
{
  "id": "msg_01XFDUDYJgAACzvnptvVoYEL",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help you today?"
    }
  ],
  "model": "claude-sonnet-4.5",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 12,
    "output_tokens": 10
  }
}

Streaming

Set stream: true in the request body to receive the response as a stream of Server-Sent Events (SSE). See the Streaming page for details on the event format.

bash
curl --no-buffer https://api.claudexia.tech/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: sk_cdx_<YOUR_KEY>" \
  -H "anthropic-version: 2023-06-01" \
  -H "accept: text/event-stream" \
  -d '{
    "model": "claude-opus-4.7",
    "max_tokens": 1024,
    "stream": true,
    "messages": [{"role": "user", "content": "Hello"}]
  }'

Vision (image blocks)

When using vision-capable models, send multimodal content: mix text with image blocks (URL source shown below).

json
{
  "model": "claude-sonnet-4.5",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "What is in this image?"},
        {
          "type": "image",
          "source": {"type": "url", "url": "https://example.com/picture.jpg"}
        }
      ]
    }
  ]
}

Thinking (Extended Thinking)

Enable extended thinking to let the model reason through complex problems before responding. Pass a thinking object in the request body:

json
{
  "model": "claude-sonnet-4.5",
  "max_tokens": 16000,
  "thinking": {
    "type": "enabled",
    "budget_tokens": 10000
  },
  "messages": [
    {"role": "user", "content": "What is the derivative of x^3 * sin(x)?"}
  ]
}

When thinking is enabled, the response content array may include a block with type: "thinking" containing the model's reasoning, followed by the final type: "text" response. The budget_tokens parameter controls the maximum tokens allocated for the thinking process.