文本系列
Claude
- 通过 Anthropic Messages API 调用 Claude 模型,同时兼容 OpenAI Chat Completions。
- 主接口为
POST /v1/messages(https://api.apiko.app/v1/messages)。下方模型列表由已发布的 Claude 模型目录生成。
POST
鉴权
二选一:使用 x-api-key 搭配 anthropic-version,或使用 Authorization: Bearer。
将 API Key 放在 Anthropic 请求头
x-api-key: <API_KEY> 中。也接受 Bearer 鉴权:
Authorization: Bearer <API_KEY>。使用 x-api-key 时发送
2023-06-01;Bearer 鉴权也被接受。请求体
application/json
model
enum<string>必填
Claude 模型 ID。使用模型目录返回的 ID。
可选值:
claude-fable-5, claude-fable-5-1, claude-fable-5-2, claude-haiku-4-5, claude-haiku-5-5, claude-opus-4-6, claude-opus-4-7, claude-opus-4-8, claude-opus-5, claude-opus-5-5, claude-sonnet-4-6, claude-sonnet-5, claude-sonnet-5-5示例:
"claude-sonnet-5-5"max_tokens
integer必填
必填的最大输出 token 数。思考 Token 也计入该上限;使用
high 及以上档位时请为回答预留余量。达到上限时响应会被截断。APIKO 会把超过 32,000 的值降为 32,000(免费试用期间为 16,000)。messages
object[]必填
必填的对话消息数组,每项包含 role 和 content。
system
string|object[]
可选的系统指令,用于引导 assistant。
stream
booleandefault:false
设为 true 以通过 Server-Sent Events 接收响应。
temperature
numberrange:0–1
控制随机性;取值范围为 0 到 1。
top_p
numberrange:0–1
控制 nucleus sampling;需要时可用它代替调整 temperature。
top_k
integer
将采样限制在概率最高的 K 个候选 token 内。
stop_sequences
string[]
生成遇到数组中的任一字符串时停止。
thinking
object
控制 extended thinking。须传对象,按模型支持情况选用:
{"type": "disabled"}、{"type": "adaptive"},或 {"type": "enabled", "budget_tokens": N}。传字符串(如 "disabled")会返回 HTTP 400。tools
object[]
声明 assistant 可调用的工具,包括工具名、描述和输入 schema。
tool_choice
object
用 auto、any 或指定工具名控制工具选择。
output_config
object
output_config.effort 设置推理档位:low、medium、high、xhigh 或 max。high 及以上会先思考。低档位思考更少,通常不返回可见的思考内容,但产生的思考仍按输出 Token 计费。每个模型可用的档位见模型目录中该模型的页面;列表之外的取值不会被拒绝,但不保证生效。模型限制
claude-opus-5-5 thinking
adaptive
claude-opus-5-5 接受所有 thinking 取值,但思考由模型自行管理:thinking: disabled 仍可能返回 thinking 块,带 budget_tokens 的 thinking: enabled 也可能不返回。需要思考输出时请使用 thinking: adaptive。claude-haiku-4-5
systemstop_sequencesreasoning_effort
claude-haiku-4-5:system、stop_sequences、reasoning_effort 目前不保证每次生效,依赖前请核对回复。响应
200 - application/json
id
string
本次响应的消息 ID。
type
"message"
响应类型为 message。
role
"assistant"
生成的响应角色为 assistant。
content
object[]
内容块可以是 text、thinking 或 tool_use。
model
string
实际处理请求的模型 ID。
stop_reason
string|null
生成停止原因,例如 end_turn 或 max_tokens。
stop_sequence
string|null
结束生成的匹配 stop sequence;没有时为 null。
usage
object
token 统计包括 input_tokens、cache_creation_input_tokens、cache_read_input_tokens 和 output_tokens。
stream_events
SSE event sequence
典型顺序:message_start、content_block_start、content_block_delta、content_block_stop、message_delta(含 stop_reason 和 usage)、message_stop。
ping 可能出现在任意位置,一个响应也可能包含多个内容块(例如先 thinking 后 text);请按事件类型处理,不要依赖事件位置。错误
HTTP status / error.type
POST /v1/messages 的错误只含 error.type 和 error.message,没有 error.code。通过 Chat Completions 调用时,同类错误带 error.code,例如 insufficient_user_quota(403)或 model_not_found(404)。
400
error.type
invalid_request_error — 请求无效,例如缺少必填字段或取值类型错误。请修正请求,不要原样重试。401
error.type
authentication_error — 缺少 API Key 或 API Key 无效。403
error.type
permission_error — 例如余额不足(Chat Completions 上为 insufficient_user_quota)。充值后再重试。404
error.type
not_found_error,消息为 No available channel for model …(Chat Completions 上为 model_not_found):模型 ID 写错或模型已下线。这不是临时故障,请勿重试;请用 GET /v1/models 核对 ID。503
error.type
同样的消息配 503:模型存在,但此刻没有可用线路。请稍后按指数退避重试,或换一个模型。
Chat Completions 兼容
POST /v1/chat/completions
OpenAI-compatible
现有的 OpenAI 兼容 Chat Completions 接口仍可用于 Claude 模型。
stream
boolean
Chat Completions 流式请求可加入 stream_options.include_usage,在 data: [DONE] 前的最后一个 chunk 获取 usage。
reasoning_effort
enum<string>
Claude 在 Chat Completions 上的推理档位:
none、minimal、low、medium、high、xhigh 或 max;其他取值返回 HTTP 400。它会换算成 Claude 的思考设置:high 及以上先思考,思考内容在 message.reasoning_content 返回。低档位思考更少,通常不返回 reasoning_content,但产生的思考仍按输出 Token 计费并计入 usage.completion_tokens,即使 completion_tokens_details.reasoning_tokens 显示为 0。claude-haiku-4-5 使用思考预算而非推理档位,因此 low 也可能思考;带 reasoning_effort 时,过小的 max_tokens 会被网关调高,输出和费用可能超过你发送的 max_tokens。它的 reasoning_effort 不保证每次生效(见「模型限制」)。