创建消息
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'anthropic/claude-sonnet-4',
max_tokens: 512,
stream: false,
messages: [{role: 'user', content: 'What time is it in America/New_York right now?'}],
tools: [{type: 'gateway:datetime', parameters: {timezone: 'America/New_York'}}],
tool_choice: {type: 'auto'}
})
};
fetch('https://api.phaseo.app/v1/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.phaseo.app/v1/messages"
payload = {
"model": "anthropic/claude-sonnet-4",
"max_tokens": 512,
"stream": False,
"messages": [
{
"role": "user",
"content": "What time is it in America/New_York right now?"
}
],
"tools": [
{
"type": "gateway:datetime",
"parameters": { "timezone": "America/New_York" }
}
],
"tool_choice": { "type": "auto" }
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)curl --request POST \
--url https://api.phaseo.app/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "anthropic/claude-sonnet-4",
"max_tokens": 512,
"stream": false,
"messages": [
{
"role": "user",
"content": "What time is it in America/New_York right now?"
}
],
"tools": [
{
"type": "gateway:datetime",
"parameters": {
"timezone": "America/New_York"
}
}
],
"tool_choice": {
"type": "auto"
}
}
'package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.phaseo.app/v1/messages"
payload := strings.NewReader("{\n \"model\": \"anthropic/claude-sonnet-4\",\n \"max_tokens\": 512,\n \"stream\": false,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"What time is it in America/New_York right now?\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"gateway:datetime\",\n \"parameters\": {\n \"timezone\": \"America/New_York\"\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"auto\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.phaseo.app/v1/messages")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"anthropic/claude-sonnet-4\",\n \"max_tokens\": 512,\n \"stream\": false,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"What time is it in America/New_York right now?\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"gateway:datetime\",\n \"parameters\": {\n \"timezone\": \"America/New_York\"\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"auto\"\n }\n}")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.phaseo.app/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([
'model' => 'anthropic/claude-sonnet-4',
'max_tokens' => 512,
'stream' => false,
'messages' => [
[
'role' => 'user',
'content' => 'What time is it in America/New_York right now?'
]
],
'tools' => [
[
'type' => 'gateway:datetime',
'parameters' => [
'timezone' => 'America/New_York'
]
]
],
'tool_choice' => [
'type' => 'auto'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}require 'uri'
require 'net/http'
url = URI("https://api.phaseo.app/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"anthropic/claude-sonnet-4\",\n \"max_tokens\": 512,\n \"stream\": false,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"What time is it in America/New_York right now?\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"gateway:datetime\",\n \"parameters\": {\n \"timezone\": \"America/New_York\"\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"auto\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"type": "<string>",
"role": "assistant",
"model": "<string>",
"content": [
{
"type": "text",
"text": "<string>",
"cache_control": {
"type": "<string>",
"ttl": "<string>",
"scope": "<string>"
},
"source": {
"type": "<string>",
"media_type": "<string>",
"data": "<string>",
"url": "<string>"
},
"id": "<string>",
"name": "<string>",
"input": {},
"tool_use_id": "<string>",
"content": "<string>"
}
],
"stop_reason": "<string>",
"stop_sequence": "<string>",
"usage": {
"input_tokens": 123,
"output_tokens": 123
}
}Anthropic Messages
创建消息
/v1/messages 上兼容 Anthropic 的 Messages 端点。
POST
/
messages
创建消息
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'anthropic/claude-sonnet-4',
max_tokens: 512,
stream: false,
messages: [{role: 'user', content: 'What time is it in America/New_York right now?'}],
tools: [{type: 'gateway:datetime', parameters: {timezone: 'America/New_York'}}],
tool_choice: {type: 'auto'}
})
};
fetch('https://api.phaseo.app/v1/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.phaseo.app/v1/messages"
payload = {
"model": "anthropic/claude-sonnet-4",
"max_tokens": 512,
"stream": False,
"messages": [
{
"role": "user",
"content": "What time is it in America/New_York right now?"
}
],
"tools": [
{
"type": "gateway:datetime",
"parameters": { "timezone": "America/New_York" }
}
],
"tool_choice": { "type": "auto" }
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)curl --request POST \
--url https://api.phaseo.app/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "anthropic/claude-sonnet-4",
"max_tokens": 512,
"stream": false,
"messages": [
{
"role": "user",
"content": "What time is it in America/New_York right now?"
}
],
"tools": [
{
"type": "gateway:datetime",
"parameters": {
"timezone": "America/New_York"
}
}
],
"tool_choice": {
"type": "auto"
}
}
'package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.phaseo.app/v1/messages"
payload := strings.NewReader("{\n \"model\": \"anthropic/claude-sonnet-4\",\n \"max_tokens\": 512,\n \"stream\": false,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"What time is it in America/New_York right now?\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"gateway:datetime\",\n \"parameters\": {\n \"timezone\": \"America/New_York\"\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"auto\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.phaseo.app/v1/messages")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"anthropic/claude-sonnet-4\",\n \"max_tokens\": 512,\n \"stream\": false,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"What time is it in America/New_York right now?\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"gateway:datetime\",\n \"parameters\": {\n \"timezone\": \"America/New_York\"\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"auto\"\n }\n}")
.asString();<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.phaseo.app/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([
'model' => 'anthropic/claude-sonnet-4',
'max_tokens' => 512,
'stream' => false,
'messages' => [
[
'role' => 'user',
'content' => 'What time is it in America/New_York right now?'
]
],
'tools' => [
[
'type' => 'gateway:datetime',
'parameters' => [
'timezone' => 'America/New_York'
]
]
],
'tool_choice' => [
'type' => 'auto'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}require 'uri'
require 'net/http'
url = URI("https://api.phaseo.app/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"anthropic/claude-sonnet-4\",\n \"max_tokens\": 512,\n \"stream\": false,\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"What time is it in America/New_York right now?\"\n }\n ],\n \"tools\": [\n {\n \"type\": \"gateway:datetime\",\n \"parameters\": {\n \"timezone\": \"America/New_York\"\n }\n }\n ],\n \"tool_choice\": {\n \"type\": \"auto\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"type": "<string>",
"role": "assistant",
"model": "<string>",
"content": [
{
"type": "text",
"text": "<string>",
"cache_control": {
"type": "<string>",
"ttl": "<string>",
"scope": "<string>"
},
"source": {
"type": "<string>",
"media_type": "<string>",
"data": "<string>",
"url": "<string>"
},
"id": "<string>",
"name": "<string>",
"input": {},
"tool_use_id": "<string>",
"content": "<string>"
}
],
"stop_reason": "<string>",
"stop_sequence": "<string>",
"usage": {
"input_tokens": 123,
"output_tokens": 123
}
}/v1/messages 接受 Anthropic Messages API 请求正文,并返回 Anthropic 格式的响应。
流式传输
设置stream: true 即可接收 Anthropic 格式的服务器发送事件(message_start、content_block_*、message_delta、message_stop)。
说明
- 支持 Anthropic 工具调用字段。
stream: true也适用于工具调用循环。对于 Gateway 管理的服务器工具,Phaseo 可能会处理上游工具调用轮次、继续循环,再重新发出合成流。- 也可以直接在
tools中使用 Anthropic 原生网页搜索工具格式,例如type: "web_search_20250305"。 X-Phaseo-Strictness标头用于控制如何处理不支持的参数。
服务器工具
/v1/messages 还支持以下由 Gateway 管理的服务器工具:
gateway:datetimephaseo:web_searchphaseo:web_fetchphaseo:advisorphaseo:image_generation
提供商原生网页搜索
如果兼容的 Anthropic 模型和提供商组合支持原生网页搜索,也可以直接传入原生工具定义:curl https://api.phaseo.app/v1/messages \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4",
"max_tokens": 512,
"messages": [
{ "role": "user", "content": "Find the latest Anthropic web search guidance." }
],
"tools": [
{
"type": "web_search_20250305",
"name": "web_search",
"max_uses": 3,
"allowed_domains": ["docs.anthropic.com"]
}
],
"tool_choice": { "type": "tool", "name": "web_search" }
}'
web_search_options。
日期和时间示例
curl https://api.phaseo.app/v1/messages \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4",
"max_tokens": 512,
"stream": false,
"messages": [
{ "role": "user", "content": "What time is it in America/New_York right now?" }
],
"tools": [
{
"type": "gateway:datetime",
"parameters": { "timezone": "America/New_York" }
}
],
"tool_choice": { "type": "auto" }
}'
usage.server_tool_use.* 计数器会记录对应的调用。授权
Bearer 令牌身份验证
请求体
application/json
Minimum array length:
1Show child attributes
Show child attributes
必填范围:
x >= 1在兼容的文本 API 上选择受支持的路由或定价等级。
可用选项:
standard, default, fast, ultrafast, priority, flex, batch 必填范围:
0 <= x <= 1必填范围:
0 <= x <= 1必填范围:
x >= 1兼容 Anthropic 的工具,以及由网关管理的服务器工具。
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
- Option 7
Show child attributes
Show child attributes
Anthropic 工具选择对象或字符串。也接受由网关管理的服务器工具名称,并由网关进行改写。
用于可观测性统计的唯一标识符,可将相关请求(例如对话或代理工作流)归为一组。
Maximum string length:
256Show child attributes
Show child attributes
可选的提供商专用选项。
Show child attributes
Show child attributes
网关调试控制项。这些标志绝不会转发给提供商。
Show child attributes
Show child attributes
用于网关选择的提供商路由偏好设置。
Show child attributes
Show child attributes
最后修改于 2026年10月2日