← Home

Claude Messages API

Send prompts to Claude Opus 4.7, Sonnet 4.6 via the Messages API. OpenAI-compatible. Code examples, request/response format, streaming support.

Updated: July 25, 2026.

Endpoint and headers

Claude API Tech supports the Anthropic-compatible Messages API. Send a POST request to the endpoint below and keep the API key on your server.

POST
https://api.llm-gate.tech/v1/messages
HeaderValue
x-api-keyYour Claude API Tech key
anthropic-versionAPI version, such as 2023-06-01
content-typeapplication/json

OpenAI-compatible API

For clients built around the OpenAI format, use the compatible endpoint: https://api.llm-gate.tech/v1/chat/completions

Your first Claude API request

A minimal request includes model, max_tokens, and a messages array. The tabs show the same request in cURL, Python, and TypeScript.

curl https://api.llm-gate.tech/v1/messages \  --header "x-api-key: $CLAUDE_API_KEY" \  --header "anthropic-version: 2023-06-01" \  --header "content-type: application/json" \  --data '{    "model": "claude-sonnet-4-6",    "max_tokens": 512,    "messages": [      {"role": "user", "content": "Explain SSE in one paragraph"}    ]  }'

Request body format

FieldRequiredPurpose
modelYesThe exact ID of an available Claude model.
max_tokensYesMaximum number of tokens to generate.
messagesYesConversation history with user and assistant messages.
systemNoInstructions that apply from the start of the request.
streamNoSet true to receive a streaming SSE response.
toolsNoTools that the model is allowed to call.

Streaming

Set stream: true in the request body to receive Server-Sent Events. See the Streaming API page for details.

Message roles and format

The Messages API is stateless. To continue a conversation, include the required history again in every request.

  • useran instruction or message from the user.
  • assistanta previous Claude response or stored conversation turn.
  • systemuse the top-level system field for instructions that apply from the beginning.
  • contentcan be a string or an array of text, image, tool_use, and tool_result blocks.

The Messages API is stateless

The API does not remember a previous call. Store history in your application, remove unnecessary old turns, and keep the full array within the model's context window.

Messages API response format

A successful response contains a content array, a stop_reason, and actual token usage under usage.

JSON
{
  "id": "msg_...",
  "type": "message",
  "role": "assistant",
  "content": [
    {"type": "text", "text": "SSE is a one-way HTTP stream..."}
  ],
  "model": "claude-sonnet-4-6",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 18,
    "output_tokens": 42
  }
}
  • content — response blocks; generated text is usually in a type: text block.
  • stop_reason — why generation ended, such as end_turn, max_tokens, or tool_use.
  • usage.input_tokens and usage.output_tokens — the tokens consumed by the request.