400
/v1/messages 报错:use the top-level 'system' parameter
Anthropic 格式里,系统提示词要放在顶层的 system 字段,不能作为 messages 里的一条。
报错原文2026-10-23 实测
在 messages 里放了 role=system 的消息
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "the upstream rejected this request as invalid (our request id: <请求ID>) — upstream said: messages.0: use the top-level 'system' parameter for the initial system prompt; the directive-only form (content: [] with output_config) is accepted at any position; retrying the same payload will fail the same way — check the payload (most often a tool/function JSON Schema the upstream rejects). quote OUR request id to support"
}
}原因
OpenAI 格式里系统提示词是 messages 里 role=system 的一条;Anthropic 格式则是单独的 system 字段,messages 里只能有 user 和 assistant。我们按 OpenAI 的习惯把 system 写进 messages,上游明确要求改用顶层 system 参数。
排查步骤
- 把 role=system 的那条从 messages 里拿出来,内容放进顶层 system 字段。
- messages 里只保留 user 和 assistant,并且第一条是 user。
- 如果不想处理两套格式,就统一用 OpenAI 兼容的 /v1/chat/completions,由网关负责转换。
正确写法
{
"model": "claude-haiku-5-5",
"max_tokens": 1024,
"system": "回答简洁,用简体中文。",
"messages": [{"role": "user", "content": "什么是词元?"}]
}