跳转到主要内容
POST
/
v1
/
messages
curl --request POST \
  --url https://api.foxapi.cc/v1/messages \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "claude-sonnet-4-20250514",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "比较 PostgreSQL 和 MySQL 的主要区别"
    }
  ]
}
'
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help you today?"
    }
  ],
  "model": "<string>",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 25,
    "output_tokens": 150
  }
}

授权

Authorization
string
header
必填

所有接口均需要使用Bearer Token进行认证

使用时在请求头中添加:

Authorization: Bearer YOUR_API_KEY

请求体

application/json
model
string
必填

模型名称,如 claude-sonnet-4-20250514

示例:

"claude-sonnet-4-20250514"

messages
object[]
必填

对话消息列表

max_tokens
integer
必填

最大生成token数(必填)

system

系统提示词

temperature
number

采样温度 (0-1)

必填范围: 0 <= x <= 1
top_p
number

核采样参数 (0-1)

必填范围: 0 <= x <= 1
top_k
integer

Top-K 采样参数

stream
boolean
默认值:false

是否流式返回响应

stop_sequences
string[]

停止序列

tools
object[]

可用工具列表

tool_choice
object

工具选择策略

metadata
object

请求元数据

响应

Claude Messages API 响应

id
string

唯一消息ID

示例:

"msg_abc123"

type
enum<string>

对象类型

可用选项:
message
role
enum<string>

角色

可用选项:
assistant
content
object[]

内容块列表

model
string

使用的模型

stop_reason
enum<string>

生成停止原因

可用选项:
end_turn,
max_tokens,
stop_sequence,
tool_use
示例:

"end_turn"

usage
object

用量统计