messages_required

The message text is shown in the example below.

HTTP status400
typeinvalid_request_error
Retry?No, not unchanged
StatusIn the public catalog (error-envelope.ts)
Extra fieldsnone

When it happens

messages is missing, is not an array, or is an empty array.

Example

{
  "error": {
    "type": "invalid_request_error",
    "code": "messages_required",
    "message": "The request must include a non-empty messages array.",
    "param": null,
    "request_id": "req_6f1c2a9e0b7d4c3a8e5f1b2d"
  }
}

How to fix it

  • Send at least one message. A system prompt alone is not enough; add a user turn.
  • Check that the variable holding your conversation was not reset before the call.

Detect it in code

err = resp.json().get("error", {})
if resp.status_code == 400 and err.get("code") == "messages_required":
    log.warning("%s (%s)", err["message"], err["request_id"])  # fix the request; do not retry unchanged
Was this page helpful?