Native Format

Claude Messages API

Call Claude models using Anthropic Messages native format.

POSThttps://zx1.deepwl.net/v1/messages
Request
curl -X POST https://zx1.deepwl.net/v1/messages \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '
{
  "model": "claude-sonnet-4-20250514",
  "max_tokens": 1024,
  "system": "You are a rigorous technical advisor.",
  "messages": [
    {
      "role": "user",
      "content": "Explain why an API gateway needs rate limiting."
    }
  ]
}'
Response
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-4-20250514",
  "content": [
    {
      "type": "text",
      "text": "API gateway rate limiting can protect upstream services, prevent sudden traffic from exhausting resources, and provide stable service quality for different users."
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 32,
    "output_tokens": 45
  }
}

The Claude Messages API preserves Anthropic's native request structure and is suitable for migrating existing Claude SDK-based services or services using native prompt structures. Requests will be routed into the Claude relay format and dispatched to the corresponding upstream based on the channel.

Request Headers

Authorizationstring必填

Authentication header. Uses a Bearer token, e.g. Bearer YOUR_API_KEY.

x-api-keystring

Claude native authentication header, can be used instead of Authorization, e.g. YOUR_API_KEY.

anthropic-versionstring

Claude native version header, used together with x-api-key, e.g. 2023-06-01.

Content-Typestring必填

Request content type, must be application/json.

Request Body

modelstring必填

Claude model name, e.g. claude-sonnet-4-20250514.

max_tokensinteger必填

Maximum number of output tokens. Required by the official API; generation stops when this limit is reached (stop_reason is max_tokens).

messagesarray<object>必填

Array of conversation messages. Roles must alternate between user and assistant.

rolestring必填

Message role: user or assistant.

contentstring | array<object>必填

Message content. Can be a plain string or an array of content blocks. Common block types: text, image (with a base64 or url source), document, tool_use, tool_result, thinking.

systemstring | array<object>

System prompt. Claude does not use system role messages; instead, system instructions are passed through this field. When passed as an array, elements are text content blocks that can be combined with cache_control for prompt caching.

streamboolean

Whether to enable SSE streaming output. Defaults to false.

temperaturenumber

Sampling temperature, range 0 to 1, defaults to 1.0. Lower values produce more deterministic output. Anthropic recommends adjusting either temperature or top_p, but not both.

top_pnumber

Nucleus sampling parameter. Avoid adjusting it together with temperature.

top_kinteger

Top-K sampling parameter. Only samples from the top K most probable tokens.

stop_sequencesarray<string>

Custom stop sequences. The model stops after generating any of these sequences; the returned text does not include the sequence itself.

toolsarray<object>

List of tool definitions.

namestring必填

Tool name.

descriptionstring

Description of what the tool does, helping the model decide when to call it.

input_schemaobject必填

JSON Schema for the tool parameters, typically { "type": "object", "properties": {...}, "required": [...] }.

tool_choiceobject

Controls the tool selection strategy.

typestring必填

auto (model decides whether to call, default), any (must call some tool), tool (force a specific tool), none (disable tool use).

namestring

When type is tool, the name of the tool to force.

disable_parallel_tool_useboolean

Set to true to prevent the model from calling multiple tools in parallel within one response.

thinkingobject

Extended thinking configuration. Only available on models with thinking capability.

typestring必填

enabled to turn thinking on, disabled to turn it off.

budget_tokensinteger

Token budget for thinking. Must be less than max_tokens.

metadataobject

Request metadata.

user_idstring

A stable identifier for the end user (preferably an irreversible ID or hash), used for abuse detection.

service_tierstring

Service capacity tier: auto (default; uses priority capacity when available, falling back to standard), standard_only (standard capacity only).

output_configobject

Structured output configuration. Pass { "type": "json_schema", "schema": {...} } in format to force the response to conform to the given JSON Schema.

context_managementobject

Context management configuration. The edits array defines context editing strategies (e.g. automatically clearing old tool calls and results) to control the context window in long conversations.

mcp_serversarray<object>

List of MCP connector servers. Each item includes type (always url), name, url, and optionally authorization_token and tool_configuration (with enabled, allowed_tools).

containerstring

Container ID. Pass a container identifier returned by a previous response to reuse the code execution container across requests.

inference_geostring

Inference geography restriction, e.g. "us" to run inference only in the United States.

Request Examples

Response Examples

Response Fields

idstring

The message ID.

typestring

Object type, always message.

rolestring

Message role, always assistant.

modelstring

The model that generated the response.

contentarray<object>

Array of content blocks.

typestring

Content block type, e.g. text.

textstring

The text content generated by the model.

stop_reasonstring

Stop reason, e.g. end_turn.

usageobject

Token usage statistics.

input_tokensinteger

Number of input tokens.

output_tokensinteger

Number of output tokens.