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
| Header | Value |
|---|---|
| x-api-key | Your Claude API Tech key |
| anthropic-version | API version, such as 2023-06-01 |
| content-type | application/json |
OpenAI-compatible API
For clients built around the OpenAI format, use the compatible endpoint:
https://api.llm-gate.tech/v1/chat/completionsYour 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
| Field | Required | Purpose |
|---|---|---|
| model | Yes | The exact ID of an available Claude model. |
| max_tokens | Yes | Maximum number of tokens to generate. |
| messages | Yes | Conversation history with user and assistant messages. |
| system | No | Instructions that apply from the start of the request. |
| stream | No | Set true to receive a streaming SSE response. |
| tools | No | Tools 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.
user— an instruction or message from the user.assistant— a previous Claude response or stored conversation turn.system— use the top-level system field for instructions that apply from the beginning.content— can 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.