too_many_messages

The message text is shown in the example below.

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

When it happens

messages holds more than 500 entries.

Example

{
  "error": {
    "type": "invalid_request_error",
    "code": "too_many_messages",
    "message": "The request has too many messages.",
    "param": null,
    "request_id": "req_6f1c2a9e0b7d4c3a8e5f1b2d",
    "max_messages": 500
  }
}

How to fix it

  • Summarise older turns into one message, or keep only the most recent part of the conversation.

Detect it in code

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