curl --request POST \
--url https://api.example.com/v1/messages \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <x-api-key>' \
--header 'anthropic-version: <anthropic-version>' \
--data '
{
"max_tokens": 123,
"model": "<string>",
"messages": [
{
"content": {}
}
],
"top_p": 123,
"top_k": 123,
"stop_sequences": [
"<string>"
],
"tool_choice": {},
"cache_control": {
"type": "<string>",
"ttl": "<string>"
},
"inference_geo": "<string>",
"output_config": {
"effort": "<string>",
"format": {
"schema": [
[
[
{}
]
]
],
"type": "<string>"
}
},
"service_tier": "<string>",
"system": {},
"temperature": 123,
"stream": true,
"thinking": {
"budget_tokens": 123,
"type": "<string>",
"display": "<string>"
},
"tools": [
{
"input_schema": [
[
[
{}
]
]
],
"allowed_callers": [
"<string>"
],
"cache_control": {
"type": "<string>",
"ttl": "<string>"
},
"defer_loading": true,
"eager_input_streaming": true,
"input_examples": [
{
"key": {}
}
],
"name": "<string>",
"description": "<string>",
"type": "<string>",
"strict": true
}
],
"metadata": {
"user_id": "<string>"
},
"container": "<string>"
}
'import requests
url = "https://api.example.com/v1/messages"
payload = {
"max_tokens": 123,
"model": "<string>",
"messages": [{ "content": {} }],
"top_p": 123,
"top_k": 123,
"stop_sequences": ["<string>"],
"tool_choice": {},
"cache_control": {
"type": "<string>",
"ttl": "<string>"
},
"inference_geo": "<string>",
"output_config": {
"effort": "<string>",
"format": {
"schema": [[[{}]]],
"type": "<string>"
}
},
"service_tier": "<string>",
"system": {},
"temperature": 123,
"stream": True,
"thinking": {
"budget_tokens": 123,
"type": "<string>",
"display": "<string>"
},
"tools": [
{
"input_schema": [[[{}]]],
"allowed_callers": ["<string>"],
"cache_control": {
"type": "<string>",
"ttl": "<string>"
},
"defer_loading": True,
"eager_input_streaming": True,
"input_examples": [{ "key": {} }],
"name": "<string>",
"description": "<string>",
"type": "<string>",
"strict": True
}
],
"metadata": { "user_id": "<string>" },
"container": "<string>"
}
headers = {
"anthropic-version": "<anthropic-version>",
"X-Api-Key": "<x-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'anthropic-version': '<anthropic-version>',
'X-Api-Key': '<x-api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
max_tokens: 123,
model: '<string>',
messages: [{content: {}}],
top_p: 123,
top_k: 123,
stop_sequences: ['<string>'],
tool_choice: {},
cache_control: {type: '<string>', ttl: '<string>'},
inference_geo: '<string>',
output_config: {effort: '<string>', format: {schema: [[[{}]]], type: '<string>'}},
service_tier: '<string>',
system: {},
temperature: 123,
stream: true,
thinking: {budget_tokens: 123, type: '<string>', display: '<string>'},
tools: [
{
input_schema: [[[{}]]],
allowed_callers: ['<string>'],
cache_control: {type: '<string>', ttl: '<string>'},
defer_loading: true,
eager_input_streaming: true,
input_examples: [{key: {}}],
name: '<string>',
description: '<string>',
type: '<string>',
strict: true
}
],
metadata: {user_id: '<string>'},
container: '<string>'
})
};
fetch('https://api.example.com/v1/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'max_tokens' => 123,
'model' => '<string>',
'messages' => [
[
'content' => [
]
]
],
'top_p' => 123,
'top_k' => 123,
'stop_sequences' => [
'<string>'
],
'tool_choice' => [
],
'cache_control' => [
'type' => '<string>',
'ttl' => '<string>'
],
'inference_geo' => '<string>',
'output_config' => [
'effort' => '<string>',
'format' => [
'schema' => [
[
[
[
]
]
]
],
'type' => '<string>'
]
],
'service_tier' => '<string>',
'system' => [
],
'temperature' => 123,
'stream' => true,
'thinking' => [
'budget_tokens' => 123,
'type' => '<string>',
'display' => '<string>'
],
'tools' => [
[
'input_schema' => [
[
[
[
]
]
]
],
'allowed_callers' => [
'<string>'
],
'cache_control' => [
'type' => '<string>',
'ttl' => '<string>'
],
'defer_loading' => true,
'eager_input_streaming' => true,
'input_examples' => [
[
'key' => [
]
]
],
'name' => '<string>',
'description' => '<string>',
'type' => '<string>',
'strict' => true
]
],
'metadata' => [
'user_id' => '<string>'
],
'container' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Api-Key: <x-api-key>",
"anthropic-version: <anthropic-version>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/messages"
payload := strings.NewReader("{\n \"max_tokens\": 123,\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": {}\n }\n ],\n \"top_p\": 123,\n \"top_k\": 123,\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"tool_choice\": {},\n \"cache_control\": {\n \"type\": \"<string>\",\n \"ttl\": \"<string>\"\n },\n \"inference_geo\": \"<string>\",\n \"output_config\": {\n \"effort\": \"<string>\",\n \"format\": {\n \"schema\": [\n [\n [\n {}\n ]\n ]\n ],\n \"type\": \"<string>\"\n }\n },\n \"service_tier\": \"<string>\",\n \"system\": {},\n \"temperature\": 123,\n \"stream\": true,\n \"thinking\": {\n \"budget_tokens\": 123,\n \"type\": \"<string>\",\n \"display\": \"<string>\"\n },\n \"tools\": [\n {\n \"input_schema\": [\n [\n [\n {}\n ]\n ]\n ],\n \"allowed_callers\": [\n \"<string>\"\n ],\n \"cache_control\": {\n \"type\": \"<string>\",\n \"ttl\": \"<string>\"\n },\n \"defer_loading\": true,\n \"eager_input_streaming\": true,\n \"input_examples\": [\n {\n \"key\": {}\n }\n ],\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"type\": \"<string>\",\n \"strict\": true\n }\n ],\n \"metadata\": {\n \"user_id\": \"<string>\"\n },\n \"container\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("anthropic-version", "<anthropic-version>")
req.Header.Add("X-Api-Key", "<x-api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/messages")
.header("anthropic-version", "<anthropic-version>")
.header("X-Api-Key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"max_tokens\": 123,\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": {}\n }\n ],\n \"top_p\": 123,\n \"top_k\": 123,\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"tool_choice\": {},\n \"cache_control\": {\n \"type\": \"<string>\",\n \"ttl\": \"<string>\"\n },\n \"inference_geo\": \"<string>\",\n \"output_config\": {\n \"effort\": \"<string>\",\n \"format\": {\n \"schema\": [\n [\n [\n {}\n ]\n ]\n ],\n \"type\": \"<string>\"\n }\n },\n \"service_tier\": \"<string>\",\n \"system\": {},\n \"temperature\": 123,\n \"stream\": true,\n \"thinking\": {\n \"budget_tokens\": 123,\n \"type\": \"<string>\",\n \"display\": \"<string>\"\n },\n \"tools\": [\n {\n \"input_schema\": [\n [\n [\n {}\n ]\n ]\n ],\n \"allowed_callers\": [\n \"<string>\"\n ],\n \"cache_control\": {\n \"type\": \"<string>\",\n \"ttl\": \"<string>\"\n },\n \"defer_loading\": true,\n \"eager_input_streaming\": true,\n \"input_examples\": [\n {\n \"key\": {}\n }\n ],\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"type\": \"<string>\",\n \"strict\": true\n }\n ],\n \"metadata\": {\n \"user_id\": \"<string>\"\n },\n \"container\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["anthropic-version"] = '<anthropic-version>'
request["X-Api-Key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"max_tokens\": 123,\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": {}\n }\n ],\n \"top_p\": 123,\n \"top_k\": 123,\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"tool_choice\": {},\n \"cache_control\": {\n \"type\": \"<string>\",\n \"ttl\": \"<string>\"\n },\n \"inference_geo\": \"<string>\",\n \"output_config\": {\n \"effort\": \"<string>\",\n \"format\": {\n \"schema\": [\n [\n [\n {}\n ]\n ]\n ],\n \"type\": \"<string>\"\n }\n },\n \"service_tier\": \"<string>\",\n \"system\": {},\n \"temperature\": 123,\n \"stream\": true,\n \"thinking\": {\n \"budget_tokens\": 123,\n \"type\": \"<string>\",\n \"display\": \"<string>\"\n },\n \"tools\": [\n {\n \"input_schema\": [\n [\n [\n {}\n ]\n ]\n ],\n \"allowed_callers\": [\n \"<string>\"\n ],\n \"cache_control\": {\n \"type\": \"<string>\",\n \"ttl\": \"<string>\"\n },\n \"defer_loading\": true,\n \"eager_input_streaming\": true,\n \"input_examples\": [\n {\n \"key\": {}\n }\n ],\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"type\": \"<string>\",\n \"strict\": true\n }\n ],\n \"metadata\": {\n \"user_id\": \"<string>\"\n },\n \"container\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"stop_reason": "<string>",
"stop_sequence": "<string>",
"stop_details": {
"type": "<string>",
"category": "<string>",
"explanation": "<string>"
},
"id": "<string>",
"type": "<string>",
"role": "<string>",
"content": [
{}
],
"model": "<string>",
"container": {
"expires_at": "<string>",
"id": "<string>"
},
"usage": {
"input_tokens": 123,
"output_tokens": 123,
"cache_creation_input_tokens": 123,
"cache_read_input_tokens": 123,
"cache_creation": {
"ephemeral_5m_input_tokens": 123,
"ephemeral_1h_input_tokens": 123
},
"inference_geo": "<string>",
"output_tokens_details": {
"thinking_tokens": 123
},
"server_tool_use": {
"web_search_requests": 123,
"web_fetch_requests": 123
},
"service_tier": "<string>"
}
}Claude 格式
创建 Claude 消息,兼容 Anthropic Messages 协议,支持流式和非流式响应
curl --request POST \
--url https://api.example.com/v1/messages \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <x-api-key>' \
--header 'anthropic-version: <anthropic-version>' \
--data '
{
"max_tokens": 123,
"model": "<string>",
"messages": [
{
"content": {}
}
],
"top_p": 123,
"top_k": 123,
"stop_sequences": [
"<string>"
],
"tool_choice": {},
"cache_control": {
"type": "<string>",
"ttl": "<string>"
},
"inference_geo": "<string>",
"output_config": {
"effort": "<string>",
"format": {
"schema": [
[
[
{}
]
]
],
"type": "<string>"
}
},
"service_tier": "<string>",
"system": {},
"temperature": 123,
"stream": true,
"thinking": {
"budget_tokens": 123,
"type": "<string>",
"display": "<string>"
},
"tools": [
{
"input_schema": [
[
[
{}
]
]
],
"allowed_callers": [
"<string>"
],
"cache_control": {
"type": "<string>",
"ttl": "<string>"
},
"defer_loading": true,
"eager_input_streaming": true,
"input_examples": [
{
"key": {}
}
],
"name": "<string>",
"description": "<string>",
"type": "<string>",
"strict": true
}
],
"metadata": {
"user_id": "<string>"
},
"container": "<string>"
}
'import requests
url = "https://api.example.com/v1/messages"
payload = {
"max_tokens": 123,
"model": "<string>",
"messages": [{ "content": {} }],
"top_p": 123,
"top_k": 123,
"stop_sequences": ["<string>"],
"tool_choice": {},
"cache_control": {
"type": "<string>",
"ttl": "<string>"
},
"inference_geo": "<string>",
"output_config": {
"effort": "<string>",
"format": {
"schema": [[[{}]]],
"type": "<string>"
}
},
"service_tier": "<string>",
"system": {},
"temperature": 123,
"stream": True,
"thinking": {
"budget_tokens": 123,
"type": "<string>",
"display": "<string>"
},
"tools": [
{
"input_schema": [[[{}]]],
"allowed_callers": ["<string>"],
"cache_control": {
"type": "<string>",
"ttl": "<string>"
},
"defer_loading": True,
"eager_input_streaming": True,
"input_examples": [{ "key": {} }],
"name": "<string>",
"description": "<string>",
"type": "<string>",
"strict": True
}
],
"metadata": { "user_id": "<string>" },
"container": "<string>"
}
headers = {
"anthropic-version": "<anthropic-version>",
"X-Api-Key": "<x-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'anthropic-version': '<anthropic-version>',
'X-Api-Key': '<x-api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
max_tokens: 123,
model: '<string>',
messages: [{content: {}}],
top_p: 123,
top_k: 123,
stop_sequences: ['<string>'],
tool_choice: {},
cache_control: {type: '<string>', ttl: '<string>'},
inference_geo: '<string>',
output_config: {effort: '<string>', format: {schema: [[[{}]]], type: '<string>'}},
service_tier: '<string>',
system: {},
temperature: 123,
stream: true,
thinking: {budget_tokens: 123, type: '<string>', display: '<string>'},
tools: [
{
input_schema: [[[{}]]],
allowed_callers: ['<string>'],
cache_control: {type: '<string>', ttl: '<string>'},
defer_loading: true,
eager_input_streaming: true,
input_examples: [{key: {}}],
name: '<string>',
description: '<string>',
type: '<string>',
strict: true
}
],
metadata: {user_id: '<string>'},
container: '<string>'
})
};
fetch('https://api.example.com/v1/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'max_tokens' => 123,
'model' => '<string>',
'messages' => [
[
'content' => [
]
]
],
'top_p' => 123,
'top_k' => 123,
'stop_sequences' => [
'<string>'
],
'tool_choice' => [
],
'cache_control' => [
'type' => '<string>',
'ttl' => '<string>'
],
'inference_geo' => '<string>',
'output_config' => [
'effort' => '<string>',
'format' => [
'schema' => [
[
[
[
]
]
]
],
'type' => '<string>'
]
],
'service_tier' => '<string>',
'system' => [
],
'temperature' => 123,
'stream' => true,
'thinking' => [
'budget_tokens' => 123,
'type' => '<string>',
'display' => '<string>'
],
'tools' => [
[
'input_schema' => [
[
[
[
]
]
]
],
'allowed_callers' => [
'<string>'
],
'cache_control' => [
'type' => '<string>',
'ttl' => '<string>'
],
'defer_loading' => true,
'eager_input_streaming' => true,
'input_examples' => [
[
'key' => [
]
]
],
'name' => '<string>',
'description' => '<string>',
'type' => '<string>',
'strict' => true
]
],
'metadata' => [
'user_id' => '<string>'
],
'container' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Api-Key: <x-api-key>",
"anthropic-version: <anthropic-version>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1/messages"
payload := strings.NewReader("{\n \"max_tokens\": 123,\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": {}\n }\n ],\n \"top_p\": 123,\n \"top_k\": 123,\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"tool_choice\": {},\n \"cache_control\": {\n \"type\": \"<string>\",\n \"ttl\": \"<string>\"\n },\n \"inference_geo\": \"<string>\",\n \"output_config\": {\n \"effort\": \"<string>\",\n \"format\": {\n \"schema\": [\n [\n [\n {}\n ]\n ]\n ],\n \"type\": \"<string>\"\n }\n },\n \"service_tier\": \"<string>\",\n \"system\": {},\n \"temperature\": 123,\n \"stream\": true,\n \"thinking\": {\n \"budget_tokens\": 123,\n \"type\": \"<string>\",\n \"display\": \"<string>\"\n },\n \"tools\": [\n {\n \"input_schema\": [\n [\n [\n {}\n ]\n ]\n ],\n \"allowed_callers\": [\n \"<string>\"\n ],\n \"cache_control\": {\n \"type\": \"<string>\",\n \"ttl\": \"<string>\"\n },\n \"defer_loading\": true,\n \"eager_input_streaming\": true,\n \"input_examples\": [\n {\n \"key\": {}\n }\n ],\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"type\": \"<string>\",\n \"strict\": true\n }\n ],\n \"metadata\": {\n \"user_id\": \"<string>\"\n },\n \"container\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("anthropic-version", "<anthropic-version>")
req.Header.Add("X-Api-Key", "<x-api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1/messages")
.header("anthropic-version", "<anthropic-version>")
.header("X-Api-Key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"max_tokens\": 123,\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": {}\n }\n ],\n \"top_p\": 123,\n \"top_k\": 123,\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"tool_choice\": {},\n \"cache_control\": {\n \"type\": \"<string>\",\n \"ttl\": \"<string>\"\n },\n \"inference_geo\": \"<string>\",\n \"output_config\": {\n \"effort\": \"<string>\",\n \"format\": {\n \"schema\": [\n [\n [\n {}\n ]\n ]\n ],\n \"type\": \"<string>\"\n }\n },\n \"service_tier\": \"<string>\",\n \"system\": {},\n \"temperature\": 123,\n \"stream\": true,\n \"thinking\": {\n \"budget_tokens\": 123,\n \"type\": \"<string>\",\n \"display\": \"<string>\"\n },\n \"tools\": [\n {\n \"input_schema\": [\n [\n [\n {}\n ]\n ]\n ],\n \"allowed_callers\": [\n \"<string>\"\n ],\n \"cache_control\": {\n \"type\": \"<string>\",\n \"ttl\": \"<string>\"\n },\n \"defer_loading\": true,\n \"eager_input_streaming\": true,\n \"input_examples\": [\n {\n \"key\": {}\n }\n ],\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"type\": \"<string>\",\n \"strict\": true\n }\n ],\n \"metadata\": {\n \"user_id\": \"<string>\"\n },\n \"container\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["anthropic-version"] = '<anthropic-version>'
request["X-Api-Key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"max_tokens\": 123,\n \"model\": \"<string>\",\n \"messages\": [\n {\n \"content\": {}\n }\n ],\n \"top_p\": 123,\n \"top_k\": 123,\n \"stop_sequences\": [\n \"<string>\"\n ],\n \"tool_choice\": {},\n \"cache_control\": {\n \"type\": \"<string>\",\n \"ttl\": \"<string>\"\n },\n \"inference_geo\": \"<string>\",\n \"output_config\": {\n \"effort\": \"<string>\",\n \"format\": {\n \"schema\": [\n [\n [\n {}\n ]\n ]\n ],\n \"type\": \"<string>\"\n }\n },\n \"service_tier\": \"<string>\",\n \"system\": {},\n \"temperature\": 123,\n \"stream\": true,\n \"thinking\": {\n \"budget_tokens\": 123,\n \"type\": \"<string>\",\n \"display\": \"<string>\"\n },\n \"tools\": [\n {\n \"input_schema\": [\n [\n [\n {}\n ]\n ]\n ],\n \"allowed_callers\": [\n \"<string>\"\n ],\n \"cache_control\": {\n \"type\": \"<string>\",\n \"ttl\": \"<string>\"\n },\n \"defer_loading\": true,\n \"eager_input_streaming\": true,\n \"input_examples\": [\n {\n \"key\": {}\n }\n ],\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"type\": \"<string>\",\n \"strict\": true\n }\n ],\n \"metadata\": {\n \"user_id\": \"<string>\"\n },\n \"container\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"stop_reason": "<string>",
"stop_sequence": "<string>",
"stop_details": {
"type": "<string>",
"category": "<string>",
"explanation": "<string>"
},
"id": "<string>",
"type": "<string>",
"role": "<string>",
"content": [
{}
],
"model": "<string>",
"container": {
"expires_at": "<string>",
"id": "<string>"
},
"usage": {
"input_tokens": 123,
"output_tokens": 123,
"cache_creation_input_tokens": 123,
"cache_read_input_tokens": 123,
"cache_creation": {
"ephemeral_5m_input_tokens": 123,
"ephemeral_1h_input_tokens": 123
},
"inference_geo": "<string>",
"output_tokens_details": {
"thinking_tokens": 123
},
"server_tool_use": {
"web_search_requests": 123,
"web_fetch_requests": 123
},
"service_tier": "<string>"
}
}功能特性
- 支持流式(SSE)和非流式两种响应模式
- 支持多模态内容(文本、图片等)
- 支持工具调用(Tool Use)
- 支持思考/推理模式配置
- 支持缓存控制优化
使用场景
适用于需要与 Claude 系列模型进行对话交互的场景,包括:- 单轮或多轮对话
- 结构化输出(JSON Schema)
- 工具调用与函数执行
- 代码执行与容器复用
认证方式
在请求头中携带Authorization 字段,格式为 Bearer YOUR_API_KEY。
anthropic-version,例如 2023-06-01。快速示例
import requests
url = "https://api.haitoken.ai/v1/messages"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
"anthropic-version": "2023-06-01"
}
data = {
"model": "claude-sonnet-4-0",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "你好,请介绍一下自己"}
]
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
const response = await fetch('https://api.haitoken.ai/v1/messages', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
'anthropic-version': '2023-06-01'
},
body: JSON.stringify({
model: 'claude-sonnet-4-0',
max_tokens: 1024,
messages: [
{ role: 'user', content: '你好,请介绍一下自己' }
]
})
});
const data = await response.json();
console.log(data);
curl -X POST 'https://api.haitoken.ai/v1/messages' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-H 'anthropic-version: 2023-06-01' \
-d '{
"model": "claude-sonnet-4-0",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "你好,请介绍一下自己"}
]
}'
请求体
最大输出 token 数(必填)
模型名称,如 claude-sonnet-4-0、claude-opus-4-0 等
消息列表
Show child attributes
Show child attributes
核采样,0-1
Top-K 采样
停止序列
工具选择配置,可以是 String 或 ClaudeToolChoice 对象
顶层缓存控制配置 自动对请求中最后一个可缓存块应用 cache_control 标记
Show child attributes
Show child attributes
推理地理区域 指定推理处理的地理区域。如未指定,使用工作区的 default_inference_geo
输出配置 配置模型输出的格式选项,如 effort 级别和结构化输出格式
Show child attributes
Show child attributes
服务层级 决定使用优先容量(如可用)还是标准容量 可选值: "auto" / "standard_only"
系统指令,可以是 String 或 List
采样温度,0.0-1.0
是否启用流式输出
思考/推理模式配置
Show child attributes
Show child attributes
工具定义列表
Show child attributes
Show child attributes
元数据
Show child attributes
Show child attributes
容器标识符,用于跨请求复用容器(代码执行工具)
响应
Claude Messages API 非流式响应 参考:https://platform.claude.com/docs/en/api/messages/create
停止原因: end_turn / max_tokens / stop_sequence / tool_use / pause_turn / refusal message_start 事件中始终输出(即使为 null)
命中的停止序列 (可为 null) message_start 事件中始终输出(即使为 null)
拒绝停止详情 当模型因安全策略拒绝时返回的结构化信息
Show child attributes
Show child attributes
消息 ID (msg_ 前缀)
对象类型,始终 "message"
角色,始终 "assistant"
响应内容块列表
模型名称(实际完成任务的模型名称)
容器信息 代码执行工具的容器标识,用于跨请求复用
Show child attributes
Show child attributes
用量统计
Show child attributes
Show child attributes