Messages API
The Messages API is the main way to work with Claude models through codexkey. You send a structured list of messages and get the model's message back.
Endpoint
POST https://api.codexkey.online/v1/messagesAuthentication
Include your API key in the x-api-key header:
x-api-key: sk_cdx_YOUR_KEYRequest body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | The model ID to use (e.g. claude-sonnet-5). |
max_tokens | integer | Yes | Upper limit on the number of tokens in the reply. |
messages | array | Yes | Array of messages. Each has a role ("user" or "assistant") and content (a string or an array of content blocks). |
system | string | No | System prompt that sets the model's behavior. |
temperature | number | No | Sampling temperature between 0 and 1. Default: 1. |
top_p | number | No | Nucleus sampling parameter. Default: 0.999. |
stream | boolean | No | If true, the response is a stream of Server-Sent Events. Default: false. |
thinking | object | No | Enable extended thinking. See Thinking below. |
Response
| Field | Type | Description |
|---|---|---|
id | string | Unique message ID (e.g. msg_01XFDUDYJgAACzvnptvVoYEL). |
type | string | Always "message". |
role | string | Always "assistant". |
content | array | Array of content blocks; each block has a type ("text") and text. |
model | string | The model that generated the response. |
stop_reason | string | Why the model stopped: "end_turn", "max_tokens", or "stop_sequence". |
usage | object | Token consumption: input_tokens and output_tokens. |
Example
Request
curl https://api.codexkey.online/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-5",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello, Claude!"}
]
}'Response
{
"id": "msg_01XFDUDYJgAACzvnptvVoYEL",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Hello! How can I help you today?"
}
],
"model": "claude-sonnet-5",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 12,
"output_tokens": 10
}
}Streaming
Pass stream: true in the request body and the response comes back as a stream of Server-Sent Events (SSE). The event format is described on the Streaming page.
curl --no-buffer https://api.codexkey.online/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-5-5",
"max_tokens": 1024,
"stream": true,
"messages": [{"role": "user", "content": "Hello"}]
}'Vision (image blocks)
For models with vision, send multimodal content: text together with image blocks (a URL example is below).
{
"model": "claude-sonnet-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)
Extended thinking gives the model time to work through a hard problem before it answers. Turn it on with a thinking object in the request body:
{
"model": "claude-sonnet-5",
"max_tokens": 16000,
"thinking": {
"type": "enabled",
"budget_tokens": 10000
},
"messages": [
{"role": "user", "content": "What is the derivative of x^3 * sin(x)?"}
]
}With thinking on, the content array of the response can include a type: "thinking" block with the model's reasoning, followed by the final type: "text" block. The budget_tokens parameter caps the tokens spent on thinking.