Application Process
To use the Claude Messages API, you can first visit the Claude Messages API page and click the “Acquire” button to obtain the credentials needed for the request:
If you are not logged in or registered, you will be automatically redirected to the login page inviting you to register and log in. After logging in or registering, you will be automatically returned to the current page.
Upon first application, there will be a free quota provided, allowing you to use the API for free.
Basic Usage
The request path for the Claude Messages API is/v1/messages, consistent with the Anthropic official API. We need to provide at least three required parameters:
model: Choose the Claude model to use, such asclaude-opus-4-20250514,claude-sonnet-4-20250514, etc.messages: An array of input messages, each containingrole(role) andcontent(content), whererolesupportsuserandassistant.max_tokens: The maximum number of output tokens, used to limit the length of a single reply.
system: System prompt used to set the model’s behavior and role.temperature: Generation randomness, between 0-1, with higher values resulting in more diverse replies.stream: Whether to use streaming responses; set totruefor a word-by-word return effect.stop_sequences: Custom stop sequences; the model will stop generating when encountering these texts.top_p: Nucleus sampling parameter, used in conjunction with temperature to control generation randomness.top_k: Sample only from the top K options with the highest probabilities.tools: Tool definitions for allowing the model to invoke external functions.tool_choice: Controls how the model uses the provided tools.
cURL Example
Python Example
id: The unique identifier for this message.type: Alwaysmessage.role: Alwaysassistant.content: An array of reply content, with each element containingtype(e.g.,text) and corresponding content.model: The name of the model processing the request.stop_reason: The reason for stopping, possible values includeend_turn(normal end),max_tokens(reached maximum length),stop_sequence(encountered stop sequence),tool_use(tool invocation).stop_sequence: If stopped due to a custom stop sequence, displays the matching stop sequence text.usage: Token usage statistics, includinginput_tokens(number of input tokens) andoutput_tokens(number of output tokens).
System Prompt
The Claude Messages API supports setting a system prompt through thesystem field, used to define the model’s behavior, role, and context.
Python Example
system prompt, you can precisely control Claude’s role and behavior.
Streaming Response
This interface also supports streaming responses; setting thestream parameter to true will provide a step-by-step return effect, which is very suitable for implementing word-by-word display on a webpage.
Python Example
event: and data:. Streaming event types include:
message_start: Message start, containing basic information about the message and model name.content_block_start: Content block start.content_block_delta: Content block incremental update, containing newly generated text segments.content_block_stop: Content block end.message_delta: Message-level incremental update, containingstop_reasonand finalusageinformation.message_stop: Message end.
content_block_delta events in the streaming response contain the progressively generated text content, and by concatenating all text_delta, you can obtain the complete reply.
JavaScript Example
Multi-turn Conversation
If you want to integrate multi-turn conversation functionality, you need to alternate the messages of theuser and assistant roles in the messages array, including the previous conversation history.
Python Example
messages, Claude can provide accurate answers based on the context.
Deep Thinking Model
Claude supports the Extended Thinking feature, which allows the model to perform internal reasoning before responding, improving the accuracy of handling complex questions. When using this feature, thethinking parameter needs to be passed.
Python Example
content array contains two content blocks:
type: "thinking": The model’s internal thought process, showing the reasoning steps.type: "text": The final answer result.
- When using
thinking,max_tokensneeds to be greater thanbudget_tokens, asbudget_tokensis the token budget allocated for the thinking process. - The larger the
budget_tokens, the more space the model has for deeper reasoning, suitable for handling complex questions.
Visual Model
Claude supports multimodal input, allowing it to process both text and images simultaneously. In the Messages API, you can use visual capabilities by settingcontent to an array format and passing in image content blocks.
Using Base64 Encoded Images
Using URL Images
cURL Example
image/jpeg, image/png, image/gif, image/webp.
Example of return result:
Tool Use
The Claude Messages API natively supports tool invocation functionality, allowing the model to call your predefined tools/functions when needed.Python Example
content in the return result will contain a tool_use type content block:
stop_reason is tool_use, indicating that the model needs to call a tool. Upon receiving this result, you need to execute the tool function and return the result in the form of tool_result to the model:
Differences with Chat Completion API
Ace Data Cloud provides two formats of the Claude API, with the main differences as follows:| Feature | Messages API (/v1/messages) | Chat Completion API (/v1/chat/completions) |
|---|---|---|
| Format | Anthropic native format | OpenAI compatible format |
| System Prompt | Independent 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 |
| Deep Thinking | Native thinking parameter | Triggered by special model names (e.g., -thinking suffix) |
| Tool Invocation | Native tools + input_schema | OpenAI compatible functions format |
| Token Statistics | input_tokens / output_tokens | prompt_tokens / completion_tokens |
Error Handling
When calling the API, if an error occurs, the API will return the corresponding error code and message. For example:400 token_mismatched: Bad request, possibly due to missing or invalid parameters.400 api_not_implemented: Bad request, possibly due to missing or invalid parameters.401 invalid_token: Unauthorized, invalid or missing authorization token.429 too_many_requests: Too many requests, you have exceeded the rate limit.500 api_error: Internal server error, something went wrong on the server.

