Claude Messages API Application and Usage

To send Claude messages from an MCP-compatible client, call the Messages interface through AI Chat MCP’s aichat_create_message. Use application credentials with permission to access this interface. AI Chat MCP Integration Guide

The Messages API uses the Anthropic Messages request and response format, providing a unified interface for messages, system prompts, content blocks, tool calls, thinking controls, and streaming events. Select a model available through this endpoint using model; clients continue to use the same Messages data structures.

This article explains how to apply for, call, and process responses from the Messages API.

Grok

Submit grok-4.7, grok-4.5, grok-4, or grok-3 to POST /v1/messages. Set max_tokens to limit the output for the current response, and read plain text from the returned content array:

{"model": "grok-4.7", "max_tokens": 256, "messages": [{"role": "user", "content": "只回复 OK"}]}

Charges are calculated based on the model in the request. When the combined number of standard input, cache read, and cache write tokens for grok-4.7 reaches 200,000, the long-context rate applies to the call.

Gemini 3.8 Flash and Gemini 4

For model, you can select gemini-3.8-flash, gemini-4-argon, gemini-4-carbon, gemini-4-hydrogen, or gemini-4-neon.

Send the following JSON to POST https://api.acedata.cloud/v1/messages. Read the text field of content blocks with type: "text" in the returned content array, as well as usage.input_tokens and usage.output_tokens. For multi-turn conversations, pass the history in messages.

{"model": "gemini-3.8-flash", "max_tokens": 1024, "messages": [{"role": "user", "content": "只回复 OK"}]}

Set "stream": true to receive Messages events one at a time until message_stop. When using function tools, retain the complete returned content unchanged as the assistant message for the next turn, then add a tool_result to the user message, setting its tool_use_id to the id of the corresponding tool_use block.

GPT-6.2 Astra and GPT-6.2 Sol

For model, you can select gpt-6.2-astra or gpt-6.2-sol. Text and image input and text output are supported; tools and results are submitted in the Messages tools, tool_use, and tool_result formats. Supported reasoning levels are low, medium, high, xhigh, and max; none and minimal are not supported. The parameter format is subject to this interface’s definition. Standard input, cache reads, cache writes, and output are billed separately; when the combined input and cache total exceeds 272,000 tokens, long-context pricing applies to the entire request.

Claude Fable 5.2

Use the full model ID claude-fable-5-2. This model is suitable for complex reasoning and long-running tasks; when native thinking content blocks and tool interactions are needed, use Messages. Adaptive thinking remains enabled; omit temperature, top_p, and top_k, use auto for tool selection, and do not force a specific tool. max_tokens covers both thinking and final text. The Responses and Count Tokens interfaces are not currently available for this model.

Based on the current largest package (142,800 Credits / $13,584), Fable 5.2 standard input costs $3.20 per million tokens, and output costs $16 per million tokens; cache reads cost $0.08 per million tokens, and 5-minute / 1-hour cache writes cost $4 / $6.40 per million tokens, respectively. The above prices are 40% of the official standard API unit prices (60% cheaper); for other packages and additional account discounts, refer to the model pricing page and your bill.

GPT-6.1 Terra

Use model: "gpt-6.1-terra" to call this model through this interface. Requests still use the Messages-format messages and max_tokens, and the returned text and usage also follow this interface’s structure. Check current pricing and account availability when switching models; separately reported cache read and creation tokens are billed separately.

Application Process

To use the Claude Messages API, first obtain your API Token from the Ace Data Cloud console and keep it for later use.

If you have not logged in or registered, you will be automatically redirected to the login page to register and log in, and will be returned to the current page automatically afterward.

A general application’s API Key can be used for services enabled for the account; a dedicated application’s Key can be used within that application’s service scope. Check the Key’s permissions, validity period, and limits, and confirm that the application balance is sufficient to pay for the request. Available trial credits are subject to what is shown in your account; if the balance is insufficient, click the “Recharge” button.

📘 Full documentation: Claude Messages API →

Basic Usage

The request path for the Claude Messages API is /v1/messages, consistent with the official Anthropic API. Compatible model requests accepted by the platform are billed according to that model’s input, output, and cache usage; Messages input tokens do not include separately reported cache read and creation tokens, which are billed separately. Charges are subject to the current model prices in the console and the response’s usage.cost.

We need to provide at least three required parameters:

  • model: Enter the full model ID from this interface’s model list. When switching models, continue to use the Messages request fields and response structure; see the corresponding model’s API and pricing pages for the model list, context limits, and prices.
  • messages: An array of input messages. Each message contains a role and content, with role supporting user and assistant.
  • max_tokens: The maximum number of output tokens, used to limit the length of a single response.

Common optional parameters:

  • system: The system prompt, used to define the model’s behavior and role.
  • temperature: Generation randomness, between 0 and 1; higher values produce more varied responses.
  • stream: Whether to use a streaming response; set to true to receive the response incrementally.
  • stop_sequences: Custom stop sequences; the model stops generating when it encounters this text.
  • top_p: The nucleus sampling parameter, used with temperature to control generation randomness.
  • top_k: Sample only from the K highest-probability options.
  • tools: Tool definitions, used to let the model call external functions.
  • tool_choice: Controls how the model uses the provided tools.
  • cache_control: Automatically creates a cache breakpoint at the last cacheable content block in the request; it can also be specified on a particular content block. Tool calls consistently use tools[].input_schema, tool_choice, tool_use, and tool_result; tool_choice.disable_parallel_tool_use: true prohibits parallel tool calls in the same turn. Thinking control uses thinking and output_config.effort, and structured output uses output_config.format. max_tokens is the output budget for this request and will not be automatically increased by the platform; thinking and the response body share this budget.

Parameter values and feature limitations are subject to the API and model documentation; when handling parameter errors, read the specific error fields and reasons.

cURL Example

curl -X POST 'https://api.acedata.cloud/v1/messages' \
  -H 'accept: application/json' \
  -H 'authorization: Bearer {token}' \
  -H 'content-type: application/json' \
  -d '{
    "model": "claude-fable-5-1",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "Hello, Claude"
      }
    ]
  }'

Structured Output

Use output_config.format to specify a JSON Schema; the response still uses Messages content blocks:

{
  "output_config": {
    "format": {
      "type": "json_schema",
      "schema": {
        "type": "object",
        "properties": {"answer": {"type": "string"}},
        "required": ["answer"],
        "additionalProperties": false
      }
    }
  }
}

Python Example

import requests

url = "https://api.acedata.cloud/v1/messages"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "model": "claude-fable-5-1",
    "max_tokens": 1024,
    "messages": [
        {"role": "user", "content": "Hello, Claude"}
    ]
}

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

After the call, the result is as follows:

{
  "id": "msg_013Zva2CMHLNnXjNJJKqJ2EF",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hi! My name is Claude. How can I help you today?"
    }
  ],
  "model": "claude-opus-4-8",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 12,
    "output_tokens": 15
  }
}

Response field descriptions:

  • id: The unique identifier for this message.
  • type: Always message.
  • role: Always assistant.
  • content: An array of response content, with each element containing a type (such as text) and the corresponding content.
  • model: The name of the model that processed the request.
  • stop_reason: The reason for stopping. Stable values include end_turn, max_tokens, stop_sequence, tool_use, pause_turn (the current assistant content can be sent back unchanged to continue), refusal, and model_context_window_exceeded.
  • stop_sequence: If stopped because of a custom stop sequence, displays the matching stop sequence text.
  • stop_details: When stop_reason is refusal, may contain the refusal category and explanation.
  • usage: Token usage statistics. input_tokens is uncached input; cache_creation_input_tokens and cache_read_input_tokens are cache writes and reads, respectively; output_tokens is the total number of output tokens. If output_tokens_details.thinking_tokens is returned, its value is a subset of output_tokens; do not add it again when calculating totals or costs. This detail may be null or omitted when no authoritative count is available.
  • usage.cache_creation: Optional cache-write TTL breakdown, containing ephemeral_5m_input_tokens and ephemeral_1h_input_tokens. When the object is present, the sum of the two equals cache_creation_input_tokens; a null or omitted field means that no TTL breakdown is available for the current response and must not be interpreted as 0.
  • usage.cost: A non-streaming response may contain a quota consumption object recorded by Ace Data Cloud, where amount is the actual amount consumed for this request, currency is the unit of measurement, and list_amount is the amount before discounts (if available). The official cache-read base price for Fable 5.1 is $0.25 per million tokens, and the base prices for 5-minute and 1-hour cache writes are $12.50 and $20 per million tokens, respectively; actual platform prices are calculated according to plan discounts.

System Prompt

The Claude Messages API supports setting a system prompt through the system field to define the model's behavior, role, and context.

Python Example

import requests

url = "https://api.acedata.cloud/v1/messages"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "system": "你是一位专业的中文翻译助手,请将用户输入的英文翻译成中文。",
    "messages": [
        {"role": "user", "content": "The quick brown fox jumps over the lazy dog."}
    ]
}

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

By setting the system prompt, you can precisely control Claude's role and behavior.

Streaming Response

The API also supports streaming responses; set the stream parameter to true to receive results incrementally, which is ideal for displaying text character by character on a web page.

Python Example

import requests

url = "https://api.acedata.cloud/v1/messages"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "stream": True,
    "messages": [
        {"role": "user", "content": "Hello, Claude"}
    ]
}

response = requests.post(url, json=payload, headers=headers, stream=True)
for line in response.iter_lines():
    if line:
        print(line.decode("utf-8"))

Streaming responses are returned in Server-Sent Events (SSE) format, with each line prefixed by event: or data:. Streaming event types include:

  • message_start: The message starts, containing basic message information and the model name.
  • content_block_start: A content block starts.
  • content_block_delta: An incremental update to a content block, containing a newly generated text fragment.
  • content_block_stop: A content block ends.
  • message_delta: A message-level incremental update, containing stop_reason and final usage information. The authoritative value of output_tokens_details.thinking_tokens should only be read from the last message_delta.usage; do not accumulate it across events.
  • message_stop: The message ends.

The output is as follows:

event: message_start
data: {"type":"message_start","message":{"id":"msg_01XFDUDYJgAACzvnptvVoYEL","type":"message","role":"assistant","content":[],"model":"claude-sonnet-4-20250514","stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"output_tokens":0}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! My name is"}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" Claude. How can I help you today?"}}

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"output_tokens":15}}

event: message_stop
data: {"type":"message_stop"}

As you can see, content_block_delta events in the streaming response contain the incrementally generated text. Concatenating all text_delta values gives the complete response.

JavaScript Example

const options = {
  method: "POST",
  headers: {
    accept: "application/json",
    authorization: "Bearer {token}",
    "content-type": "application/json",
  },
  body: JSON.stringify({
    model: "claude-sonnet-4-20250514",
    max_tokens: 1024,
    stream: true,
    messages: [{ role: "user", content: "Hello, Claude" }],
  }),
};

const response = await fetch("https://api.acedata.cloud/v1/messages", options);
const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  console.log(decoder.decode(value));
}

Multi-Turn Conversations

If you want to integrate multi-turn conversation functionality, arrange messages with the user and assistant roles alternately in the messages array, and include the previous conversation history.

Python Example

import requests

url = "https://api.acedata.cloud/v1/messages"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
        {"role": "user", "content": "Hello, my name is Alice."},
        {"role": "assistant", "content": "Hello Alice! Nice to meet you. How can I help you today?"},
        {"role": "user", "content": "What is my name?"}
    ]
}

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

The result is as follows:

{
  "id": "msg_01Y1wfQmd89g968TVbFu57Yc",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Your name is Alice, as you just told me!"
    }
  ],
  "model": "claude-sonnet-4-20250514",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 40,
    "output_tokens": 14
  }
}

By passing the complete conversation history in messages, Claude can provide accurate answers based on the context.

Deep Thinking Models

Claude's thinking and thinking summary are two distinct concepts: the model can perform internal reasoning, but the API does not return the raw chain of thought. When the reasoning process needs to be displayed, the API returns a processed summary.

For current models, adaptive thinking is recommended, with output_config.effort used to control the overall reasoning effort:

import requests

url = "https://api.acedata.cloud/v1/messages"
headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}
payload = {
    "model": "claude-opus-5",
    "max_tokens": 16000,
    "thinking": {
        "type": "adaptive",
        "display": "summarized"
    },
    "output_config": {
        "effort": "high"
    },
    "messages": [
        {"role": "user", "content": "What is the sine of 30 degrees?"}
    ]
}

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

The thinking block in the response looks like this:

{
  "type": "thinking",
  "thinking": "The problem asks for a standard trigonometric value...",
  "signature": "opaque-signature"
}
  • display: "summarized" returns a readable thinking summary; it is not the raw chain of thought.
  • display: "omitted" returns thinking: "", but still retains the opaque signature to support subsequent conversation.
  • display: "updates" is an Anthropic beta mode and requires the anthropic-beta: thinking-display-updates-2026-08-18 header. The official definition is to hide the reasoning text and display brief progress updates between tool calls. The platform passes this parameter and the beta request header through unchanged and does not forcibly rewrite it to summarized; the actual output depends on whether the selected model supports it.
  • Messages requests use thinking, output_config, and sampling parameters. Supported values depend on the selected model's documentation; parameter errors are described in the response.
  • The default display value for Fable 5.1, Fable 5, Opus 5, Sonnet 5, Opus 4.8, and Opus 4.7 is omitted; Opus 4.6, Sonnet 4.6, and earlier models that support thinking default to summarized.
  • Display only affects the returned content and streaming latency; it does not disable reasoning or reduce thinking token charges.
  • Whether thinking is enabled by default and the default display value are two separate matters. Opus 5 and Sonnet 5 enable adaptive thinking by default; for Opus 5, omitting thinking is equivalent to adaptive, and omitting output_config.effort is equivalent to high. Opus 4.8, 4.7, and 4.6 require explicit enablement.
  • Thinking and the final text share the max_tokens output budget. If the budget is too small, thinking may consume most of it, leaving the text empty or truncated; increase max_tokens, or use low / medium effort to control reasoning effort.
  • For models that allow thinking to be disabled, you can pass thinking: {"type":"disabled"}. New modes such as between_tools and effort combinations depend on the selected model; the platform does not reject them in advance based on old model-specific rules.
  • A fixed thinking budget can be passed through budget_tokens; newer models typically use thinking.type=adaptive and output_config.effort. Support for a fixed budget or disabling thinking depends on the selected model's current capabilities.
  • For multi-turn conversations and tool calls, the complete thinking block and signature returned by the assistant should be passed back unchanged; do not modify or generate the signature yourself.
  • Parameter pass-through does not mean that every model supports all features. Cross-protocol calls still require conversion, and support for content such as redacted_thinking and any associated errors are determined by the model service that actually handles the request. In streaming requests, summarized produces thinking_delta; omitted does not produce thinking_delta, retaining only the thinking block lifecycle and signature_delta.

Vision Models

Claude supports multimodal input and can process text and images simultaneously. In the Messages API, you can use vision capabilities by setting content to an array and passing in image content blocks.

Using Base64-Encoded Images

import base64
import requests

url = "https://api.acedata.cloud/v1/messages"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

# 读取并编码图片
with open("image.png", "rb") as f:
    image_data = base64.standard_b64encode(f.read()).decode("utf-8")

payload = {
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "image",
                    "source": {
                        "type": "base64",
                        "media_type": "image/png",
                        "data": image_data
                    }
                },
                {
                    "type": "text",
                    "text": "What's in this image?"
                }
            ]
        }
    ]
}

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

Using URL Images

import requests

url = "https://api.acedata.cloud/v1/messages"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "image",
                    "source": {
                        "type": "url",
                        "url": "https://cdn.acedata.cloud/ueugot.png"
                    }
                },
                {
                    "type": "text",
                    "text": "What's in this image?"
                }
            ]
        }
    ]
}

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

cURL Example

curl -X POST 'https://api.acedata.cloud/v1/messages' \
  -H 'accept: application/json' \
  -H 'authorization: Bearer {token}' \
  -H 'content-type: application/json' \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "image",
            "source": {
              "type": "url",
              "url": "https://cdn.acedata.cloud/ueugot.png"
            }
          },
          {
            "type": "text",
            "text": "What'\''s in this image?"
          }
        ]
      }
    ]
  }'

Supported image formats include: image/jpeg, image/png, image/gif, and image/webp.

Documents and PDFs

PDFs use document content blocks and support two stable sources: Base64 and URL. Base64 sources must use application/pdf:

import base64

with open("report.pdf", "rb") as f:
    pdf_data = base64.standard_b64encode(f.read()).decode("utf-8")

payload = {
    "model": "claude-fable-5-1",
    "max_tokens": 1024,
    "messages": [{
        "role": "user",
        "content": [
            {
                "type": "document",
                "source": {
                    "type": "base64",
                    "media_type": "application/pdf",
                    "data": pdf_data
                },
                "title": "Quarterly report"
            },
            {"type": "text", "text": "Summarize this PDF."}
        ]
    }]
}

A URL source is written as {"type":"url","url":"https://example.com/report.pdf"}. document also supports text/plain and content sources composed of text/image blocks; optional fields include title, context, and citations. The Files API's file_id source is a separate beta feature and is not part of this interface's stable contract.

Prompt Caching

Top-level cache_control automatically places the cache breakpoint on the last cacheable block:

payload = {
    "model": "claude-fable-5-1",
    "max_tokens": 1024,
    "cache_control": {"type": "ephemeral", "ttl": "5m"},
    "system": "You are an expert on this reference material.",
    "messages": [{"role": "user", "content": "Summarize the key points."}]
}

When precise control over the location is needed, the same cache_control can also be placed on text, image, document, tool_use, or tool_result content blocks, or on tool definitions. ttl supports 5m (default) and 1h; use usage.cache_creation_input_tokens and usage.cache_read_input_tokens to determine cache writes and hits.

When the response provides usage.cache_creation, ephemeral_5m_input_tokens + ephemeral_1h_input_tokens = cache_creation_input_tokens. If cache_creation is null or omitted, only the total cache writes are available, with no authoritative TTL breakdown; in this case, do not treat either bucket as a known 0, and continue to use the aggregate field for billing and totals.

Example response:

{
  "id": "msg_01NCrxpZmV17bhQJJRQEFEb9",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "This image shows an API request configuration interface for what appears to be an AI chat completion service. The interface includes parameters for model selection, messages, stream mode, and max tokens settings."
    }
  ],
  "model": "claude-sonnet-4-20250514",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 1570,
    "output_tokens": 52
  }
}

Tool Use

The Claude Messages API natively supports tool use, allowing the model to call your predefined tools/functions when needed.

Python Example

import requests

url = "https://api.acedata.cloud/v1/messages"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "tools": [
        {
            "name": "get_weather",
            "description": "Get the current weather in a given location",
            "input_schema": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and state, e.g. San Francisco, CA"
                    }
                },
                "required": ["location"]
            }
        }
    ],
    "messages": [
        {"role": "user", "content": "What's the weather like in San Francisco?"}
    ]
}

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

When the model decides to call a tool, content in the response will contain a content block of type tool_use:

{
  "id": "msg_01Aq9w938a90dw8q",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Let me check the weather in San Francisco for you."
    },
    {
      "type": "tool_use",
      "id": "toolu_01A09q90qw90lq917835lgs",
      "name": "get_weather",
      "input": {
        "location": "San Francisco, CA"
      }
    }
  ],
  "model": "claude-sonnet-4-20250514",
  "stop_reason": "tool_use",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 120,
    "output_tokens": 68
  }
}

Note that stop_reason is tool_use, indicating that the model needs to call a tool. After receiving this result, you need to execute the tool function and return the result to the model as a tool_result:

payload = {
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "tools": [
        {
            "name": "get_weather",
            "description": "Get the current weather in a given location",
            "input_schema": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and state, e.g. San Francisco, CA"
                    }
                },
                "required": ["location"]
            }
        }
    ],
    "messages": [
        {"role": "user", "content": "What's the weather like in San Francisco?"},
        {
            "role": "assistant",
            "content": [
                {"type": "text", "text": "Let me check the weather in San Francisco for you."},
                {"type": "tool_use", "id": "toolu_01A09q90qw90lq917835lgs", "name": "get_weather", "input": {"location": "San Francisco, CA"}}
            ]
        },
        {
            "role": "user",
            "content": [
                {
                    "type": "tool_result",
                    "tool_use_id": "toolu_01A09q90qw90lq917835lgs",
                    "content": "Sunny, 72°F"
                }
            ]
        }
    ]
}

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

The model will generate the final natural language response based on the result returned by the tool.

Differences from the Chat Completion API

Ace Data Cloud offers two Claude API formats, with the following main differences:

The Messages API's usage.input_tokens represents only uncached input, while cache_read_input_tokens and cache_creation_input_tokens are separate billing buckets; the three are calculated separately at their corresponding rates.

Feature Messages API (/v1/messages) Chat Completion API (/v1/chat/completions)
Format Native Anthropic format OpenAI-compatible format
System prompt Separate system field Passed through role: "system" in messages
Response structure content array (supports multiple types) choices array (contains message)
Streaming format SSE events (multiple event types) SSE data lines
Extended thinking Native thinking and output_config.effort Model default policy and compatible parameters
Tool calls Native tools + input_schema OpenAI-compatible tools format
Token statistics output_tokens_details.thinking_tokens completion_tokens_details.reasoning_tokens

If your system is already integrated with an OpenAI-format API, you can use the Chat Completion API to switch seamlessly. If you need to use all of Claude's native capabilities, the Messages API is recommended.

Error Handling

Error responses from the public interface use the Ace Data Cloud platform envelope: error.code is a stable error code, error.message is a description, and trace_id is used to troubleshoot requests. Common HTTP statuses include:

  • 400: Invalid request parameters or protocol content.
  • 401: Invalid, missing, or expired authorization token.
  • 403: Access forbidden, insufficient balance, or quota restrictions.
  • 404: API or model does not exist.
  • 413: Request body too large.
  • 429: Too many requests.
  • 500 / 503 / 504: Service error, temporarily unavailable, or processing timeout.

Error Response Example

{
  "error": {
    "code": "api_error",
    "message": "fetch failed"
  },
  "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}

This error structure is Ace Data Cloud's runtime contract and is not equivalent to the official Anthropic error envelope; please handle it according to the HTTP status and error.code.

Conclusion

Through this document, you have learned how to use the Claude Messages API to access Claude's conversational capabilities in the native Anthropic format. The Messages API supports a wide range of features, including basic conversations, system prompts, streaming responses, multi-turn conversations, extended thinking, vision understanding, PDFs, prompt caching, and tool calls. If you have any questions, please feel free to contact our technical support team.