Skip to content
POST/v1/messages

Messages

该接口面向 Anthropic SDK/调用习惯,平台会将 Messages 请求适配到统一模型路由、计费、权限和 Responses 执行链路。非流式返回 Anthropic message 结构;流式模式返回 `message_start`、`content_block_delta`、`message_stop` 等 SSE 事件。

基础信息

鉴权Authorization: Bearer sk-... 或 x-api-key: sk-...
请求类型application/json
响应类型application/json 或 text/event-stream

请求参数

Header

字段
类型
必填
位置
说明
x-api-key
string
header
Anthropic 风格 API Key 请求头。也可以继续使用 `Authorization: Bearer sk-...`。
示例:"sk-xxx"
anthropic-version
string
header
Anthropic SDK 常用版本头,平台允许透传。
示例:"2023-06-01"
anthropic-beta
string
header
Anthropic beta 功能开关头,多个值可用逗号分隔。
示例:"prompt-caching-2024-07-31"

Body

字段
类型
必填
位置
说明
model
string
body
平台统一模型 ID。
示例:"claude-4.5-sonnet"
max_tokens
integer
body
最大输出 token 数,对应平台内部 `max_output_tokens`。
示例:512
messages
array<object>
body
Anthropic 风格消息数组。`content` 可以是字符串,也可以是 text/image 内容块数组。
示例:[{"role":"user","content":"请用一句话介绍千云开发者文档中心。"}]
role
string
body
消息角色,例如 user / assistant。
示例:"user"
content
array<object>
body
消息内容。文本可直接传字符串;多模态可传内容块数组。
示例:[{"type":"text","text":"你好"}]
system
string
body
系统级指令,可传字符串或 text 内容块数组。
示例:"使用简洁中文回答。"
stream
boolean
body
是否使用 SSE 流式输出。
示例:false
temperature
number
body
采样温度。
示例:0.7
top_p
number
body
Top-p 采样。
示例:1
top_k
integer
body
Top-k 采样参数。
示例:40
stop_sequences
array<string>
body
停止序列数组。
示例:["</end>"]
metadata
object
body
调用元数据,官方支持 user_id 等信息。
示例:{"user_id":"user_123"}
container
string
body
可复用上下文容器标识,用于延续工具结果等上下文。
示例:"container_123"
mcp_servers
array<object>
body
MCP 服务器配置数组。
service_tier
string
body
服务层级,例如 auto 或 standard_only。
示例:"auto"
thinking
object
body
扩展思考配置。
示例:{"type":"enabled","budget_tokens":1024}
type
string
body
thinking 开关,常见值 enabled / disabled。
示例:"enabled"
budget_tokens
integer
body
启用 thinking 时的 token 预算。
示例:1024
tools
array<object>
body
工具定义数组,兼容 Anthropic tool use。
示例:[{"name":"get_weather","description":"Get weather","input_schema":{"type":"object","properties":{"location":{"type":"string"}},"required":["location"]}}]
name
string
body
工具名称。
示例:"get_weather"
description
string
body
工具描述。
示例:"Get weather"
input_schema
object
body
JSON Schema 输入参数定义。
cache_control
object
body
工具定义缓存控制。
示例:{"type":"ephemeral"}
tool_choice
object
body
工具选择策略。
示例:{"type":"auto"}
type
string
body
auto / any / tool / none。
示例:"auto"
name
string
body
type=tool 时指定工具名称。
示例:"get_weather"
disable_parallel_tool_use
boolean
body
是否禁用并行工具调用。
示例:false
context_management
object
body
上下文管理配置。
示例:{"clear_function_results":true}

请求示例

json
{
  "model": "claude-4.5-sonnet",
  "max_tokens": 512,
  "system": "使用简洁中文回答。",
  "messages": [
    {
      "role": "user",
      "content": "请用一句话介绍千云开发者文档中心。"
    }
  ],
  "stream": false
}

响应示例

json
{
  "id": "msg_resp_123",
  "type": "message",
  "role": "assistant",
  "model": "claude-4.5-sonnet",
  "content": [
    {
      "type": "text",
      "text": "千云开发者文档中心提供统一模型接入、调试与管理说明。"
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 26,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0,
    "output_tokens": 24,
    "service_tier": "auto"
  }
}

响应字段

字段
类型
必填
位置
说明
id
string
body
消息 ID。
示例:"msg_resp_123"
type
string
body
对象类型。
示例:"message"
role
string
body
消息角色。
示例:"assistant"
model
string
body
模型 ID。
示例:"claude-4.5-sonnet"
content
array<object>
body
输出内容块。
type
string
body
内容块类型。
示例:"text"
text
string
body
文本内容块。
示例:"千云开发者文档中心提供统一模型接入。"
source
object
body
内容块来源。
id
string
body
工具调用或思考块 ID。
name
string
body
工具名称。
input
object
body
工具输入。
tool_use_id
string
body
对应的 tool_use ID。
signature
string
body
思考签名。
citations
array<object>
body
引用信息。
cache_control
object
body
缓存控制。
stop_reason
string
body
停止原因。
示例:"end_turn"
stop_sequence
string
body
触发停止的序列。
usage
object
body
用量统计。
input_tokens
integer
body
输入 token 数。
示例:26
cache_creation_input_tokens
integer
body
缓存创建 token 数。
示例:0
cache_read_input_tokens
integer
body
缓存读取 token 数。
示例:0
output_tokens
integer
body
输出 token 数。
示例:24
service_tier
string
body
实际服务层级。
示例:"auto"

错误码

HTTPcode说明
400invalid_request_error请求体结构不合法、缺少 `model` / `max_tokens` / `messages` 等必填参数。
401authentication_error缺少或传错 API Key。
403permission_error当前 API Key 没有访问该模型的权限。
429rate_limit_error触发网关或上游限流。
502api_error平台计费、路由或上游渠道调用失败。

在线调试

Playground · 浏览器直连网关

Messages

兼容 Anthropic Messages 协议,支持 `x-api-key` 接入与 `stream=true` 的 SSE 返回。

提示:Anthropic SDK 可使用 `x-api-key`;平台也兼容 `Authorization: Bearer sk-...`。

提示:将 `stream` 设为 `true` 时,响应会切换为 Anthropic Messages SSE。

json
尚未发起请求。
bash
curl --location --request POST 'https://api.harnmodel.com/v1/messages' \
  --header 'Authorization: Bearer sk-xxx' \
  --header 'Content-Type: application/json' \
  --data '{}'

多语言示例

bash
curl --location --request POST 'https://api.harnmodel.com/v1/messages' \
  --header 'Authorization: Bearer sk-xxx' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "claude-4.5-sonnet",
    "max_tokens": 512,
    "system": "使用简洁中文回答。",
    "messages": [
      {
        "role": "user",
        "content": "请用一句话介绍千云开发者文档中心。"
      }
    ],
    "stream": false
  }'

千云开发者中心仅维护中文第一版文档;接口口径以当前后端实现为准。