Messages

Send user and assistant messages. Receive a message made of content blocks.

POST/anthropic/v1/messages

Create a message

Use your Anthropic key in x-api-key and select claude-haiku-4-5-20251001. Keep earlier user and assistant messages in the conversation array.

curl · whole response

curl "https://proxy.litechat.ai/anthropic/v1/messages" \
  -H "x-api-key: $BUILD_ANTHROPIC_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  --data '{
    "model": "claude-haiku-4-5-20251001",
    "messages": [{"role": "user", "content": "Say hello in one sentence."}],
    "max_tokens": 128,
    "thinking": {"type": "disabled"}
  }'

Read content blocks

Inspect each block in content. A text block carries answer text; other block types can carry thinking or tool calls. Read stop_reason before marking the answer complete.

Illustrative whole response

{
  "id": "msg_example",
  "type": "message",
  "role": "assistant",
  "model": "claude-haiku-4-5-20251001",
  "content": [{"type": "text", "text": "Hello! How can I help?"}],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {"input_tokens": 12, "output_tokens": 8}
}

Example values are synthetic. end_turn finishes the turn, max_tokens indicates truncation, and tool_use requests a backend action.

Common parameters

messages and system
Use user and assistant roles in the messages array. Put system instructions in the separate system field.
max_tokens and thinking
Set an output limit. Thinking can be enabled or disabled. Numeric thinking budgets are unsupported. Preserve thinking blocks and tool history when continuing a tool turn.
tools
Declare functions with an input schema. Your backend executes the requested function and sends its result with the same tool-use ID. Use automatic tool choice with thinking.
output_config.format
JSON Schema output is validated in full before it is sent. Remote schema references are unsupported. Schema conversion cannot be combined with stop sequences or log probability controls.

Streaming

Add "stream": true to the request body above and pass --no-buffer to curl. SSE carries message and indexed content-block events. Text updates use content_block_delta with a text_delta. A block ending is not the message ending: check the stop reason and message_stop. Handle stream errors and interruptions.

See the Anthropic Messages streaming guide.

← Getting startedBack to top ↑