400
tools 定义被拒:upstream_rejected_request … name should have at least 1 character
工具(function)定义不合规,上游模型服务商拒绝了请求。最常见的是缺 name,或 parameters 不是合法的 JSON Schema。
报错原文2026-10-23 实测
function 定义里缺了 name
{
"error": {
"message": "the upstream rejected this request as invalid (our request id: <请求ID>) — upstream said: tools.0.custom.name: String should have at least 1 character; 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",
"type": "invalid_request_error",
"param": null,
"code": "upstream_rejected_request"
}
}原因
我们故意只写了 description、没写 name,网关转发给上游后,上游返回 name 至少要有 1 个字符。网关把上游的原话放在了 upstream said 后面。这类报错的关键信息都在这句话里:它会指出是第几个工具的哪个字段有问题,比如 tools.0 就是第一个工具。
每个工具至少要有:
- type: "function"
- function.name:只用字母、数字、下划线、短横线
- function.parameters:一个 type 为 object 的 JSON Schema
排查步骤
- 读 upstream said 后面的内容,定位到具体的工具序号和字段。
- 检查每个工具都有 name,并且命名合法。
- parameters 用 JSON Schema 校验工具检查一遍;required 里列出的字段必须在 properties 里存在。
- 同一个请求重试结果也一样(报错里也这么写了),改好请求体再发。
正确写法
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询城市天气",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}]补充
报错里的 our request id 联系服务商时要带上。