invalid_request
The message text is shown in the example below.
| HTTP status | 400 |
type | invalid_request_error |
| Retry? | No, not unchanged |
| Status | In the public catalog (error-envelope.ts) |
| Extra fields | none |
When it happens
model is present but not a non-empty string; include_unavailable on GET /v1/models is not true or false; or the model service refused the request as malformed, most often because tool messages do not line up (a tool message whose tool_call_id matches no earlier call).
Example
{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "The request was rejected. Check the message format, tool definitions and parameters.",
"param": null,
"request_id": "req_6f1c2a9e0b7d4c3a8e5f1b2d"
}
}How to fix it
- Send
modelas a string fromGET /v1/models. - After a tool call, send exactly one
toolmessage pertool_calls[].id, in the same request that includes the assistant message carrying those calls. - Do not drop the assistant message that contains
tool_callswhen you trim history.
Detect it in code
err = resp.json().get("error", {})
if resp.status_code == 400 and err.get("code") == "invalid_request":
log.warning("%s (%s)", err["message"], err["request_id"]) # fix the request; do not retry unchangedRelated
Was this page helpful?