API referenceAdvanced usersUpdated
POST/v1/messages

API console

POST/v1/messages
View keys

Requests use the API key you enter and follow standard API billing.

Anthropic Messages

Send a request in the Anthropic Messages format. This page covers direct HTTP calls, with Claude Code setup covered in the related guides.

Before you start

Follow the quickstart to get an API key and select an endpoint that accepts direct HTTP calls. The example sends ICODEEASY_API_KEY in x-api-key and includes anthropic-version. Replace YOUR_MODEL_ID with a model ID supported by your endpoint.

Request example

Set model, cap output with max_tokens, and put the conversation in messages.

bash
curl -sS https://api.icodeeasy.cc/v1/messages \
  -H "x-api-key: $ICODEEASY_API_KEY" \
  -H 'Content-Type: application/json' \
  -H 'anthropic-version: 2023-06-01' \
  --data '{
  "model": "YOUR_MODEL_ID",
  "max_tokens": 256,
  "messages": [
    {
      "role": "user",
      "content": "Say hello."
    }
  ]
}'

Read the response

Read blocks of type text from content[]. Read usage from usage.input_tokens and usage.output_tokens. When present, cache_creation_input_tokens and cache_read_input_tokens count cache writes and reads respectively.

json
{
  "content": [
    {
      "type": "text",
      "text": "Hello!"
    }
  ],
  "stop_reason": "end_turn"
}

Streaming response example

Set stream: true in the request body to receive SSE. Append delta.text from content_block_delta. Read the stop reason from message_delta and confirm completion at message_stop. Treat an SSE error event as a failure even if HTTP already returned 200.

text
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}}

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"output_tokens":4}}

event: message_stop
data: {"type":"message_stop"}

Read streaming usage from message_start.message.usage and later message_delta.usage. Cache fields have the same meaning as in the JSON response.