Skip to main content
POST
/
v1
/
messages
Create Message
curl --request POST \
  --url https://api.example.com/v1/messages \
  --header 'Content-Type: application/json' \
  --header 'X-Api-Key: <x-api-key>' \
  --header 'anthropic-version: <anthropic-version>' \
  --data '
{
  "max_tokens": 123,
  "model": "<string>",
  "messages": [
    {
      "content": {}
    }
  ],
  "top_p": 123,
  "top_k": 123,
  "stop_sequences": [
    "<string>"
  ],
  "tool_choice": {},
  "cache_control": {
    "type": "<string>",
    "ttl": "<string>"
  },
  "inference_geo": "<string>",
  "output_config": {
    "effort": "<string>",
    "format": {
      "schema": [
        [
          [
            {}
          ]
        ]
      ],
      "type": "<string>"
    }
  },
  "service_tier": "<string>",
  "system": {},
  "temperature": 123,
  "stream": true,
  "thinking": {
    "budget_tokens": 123,
    "type": "<string>",
    "display": "<string>"
  },
  "tools": [
    {
      "input_schema": [
        [
          [
            {}
          ]
        ]
      ],
      "allowed_callers": [
        "<string>"
      ],
      "cache_control": {
        "type": "<string>",
        "ttl": "<string>"
      },
      "defer_loading": true,
      "eager_input_streaming": true,
      "input_examples": [
        {
          "key": {}
        }
      ],
      "name": "<string>",
      "description": "<string>",
      "type": "<string>",
      "strict": true
    }
  ],
  "metadata": {
    "user_id": "<string>"
  },
  "container": "<string>"
}
'
{
  "stop_reason": "<string>",
  "stop_sequence": "<string>",
  "stop_details": {
    "type": "<string>",
    "category": "<string>",
    "explanation": "<string>"
  },
  "id": "<string>",
  "type": "<string>",
  "role": "<string>",
  "content": [
    {}
  ],
  "model": "<string>",
  "container": {
    "expires_at": "<string>",
    "id": "<string>"
  },
  "usage": {
    "input_tokens": 123,
    "output_tokens": 123,
    "cache_creation_input_tokens": 123,
    "cache_read_input_tokens": 123,
    "cache_creation": {
      "ephemeral_5m_input_tokens": 123,
      "ephemeral_1h_input_tokens": 123
    },
    "inference_geo": "<string>",
    "output_tokens_details": {
      "thinking_tokens": 123
    },
    "server_tool_use": {
      "web_search_requests": 123,
      "web_fetch_requests": 123
    },
    "service_tier": "<string>"
  }
}
This endpoint is compatible with the Anthropic Claude Messages protocol for creating conversation messages.

Features

  • Supports both streaming (SSE) and non-streaming response modes
  • Supports multimodal content (text, images, etc.)
  • Supports tool use
  • Supports thinking/reasoning mode configuration
  • Supports cache control optimization

Use cases

Suitable for scenarios requiring interaction with Claude models, including:
  • Single-turn or multi-turn conversations
  • Structured output (JSON Schema)
  • Tool calling and function execution
  • Code execution and container reuse

Authentication

Include the Authorization header in the format Bearer YOUR_API_KEY.
The Claude format endpoint also requires the anthropic-version header, e.g. 2023-06-01.

Quick example

import requests

url = "https://api.haitoken.ai/v1/messages"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
    "anthropic-version": "2023-06-01"
}
data = {
    "model": "claude-sonnet-4-0",
    "max_tokens": 1024,
    "messages": [
        {"role": "user", "content": "Hello, please introduce yourself"}
    ]
}

response = requests.post(url, json=data, headers=headers)
print(response.json())

Headers

anthropic-version
string
required
Example:

"2023-06-01"

X-Api-Key
string
required
Example:

"YOUR_API_KEY"

Body

application/json
max_tokens
integer
required

Maximum number of output tokens (required)

model
string
required

Model name, e.g. claude-sonnet-4-0, claude-opus-4-0, etc.

messages
object[]
required

List of messages

top_p
number

Nucleus sampling, 0-1

top_k
integer

Top-K sampling

stop_sequences
string[]

Stop sequences

tool_choice
object

Tool choice configuration, can be a String or ClaudeToolChoice object

cache_control
object

Top-level cache control configuration Automatically applies a cache_control marker to the last cacheable block in the request

inference_geo
string

Inference geographic region Specifies the geographic region for inference processing. If not specified, uses the workspace's default_inference_geo

output_config
object

Output configuration Configures model output format options, such as effort level and structured output format

service_tier
string

Service tier Determines whether to use priority capacity (if available) or standard capacity Possible values: "auto" / "standard_only"

system
object

System instruction, can be a String or List

temperature
number

Sampling temperature, 0.0-1.0

stream
boolean

Whether to enable streaming output

thinking
object

Thinking/reasoning mode configuration

tools
object[]

List of tool definitions

metadata
object

Metadata

container
string

Container identifier, used for cross-request container reuse (code execution tool)

Response

200 - application/json

Claude Messages API non-streaming response Reference: https://platform.claude.com/docs/en/api/messages/create

stop_reason
string

Stop reason: end_turn / max_tokens / stop_sequence / tool_use / pause_turn / refusal Always output in the message_start event (even when null)

stop_sequence
string

Stop sequence that was matched (can be null) Always output in the message_start event (even when null)

stop_details
object

Refusal stop details Structured information returned when the model refuses due to safety policy

id
string

Message ID (msg_ prefix)

type
string

Object type, always "message"

role
string

Role, always "assistant"

content
object[]

List of response content blocks

model
string

Model name (the actual model that completed the task)

container
object

Container information Container identifier for the code execution tool, used for cross-request reuse

usage
object

Usage statistics