API referenceError code index405method_not_allowed

method_not_allowed

The message text is shown in the example below.

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

When it happens

/v1/chat/completions was called with a method other than POST, or /v1/models with one other than GET or HEAD. The Allow header lists accepted methods.

Example

{
  "error": {
    "type": "invalid_request_error",
    "code": "method_not_allowed",
    "message": "This method is not allowed on this endpoint.",
    "param": null,
    "request_id": "req_6f1c2a9e0b7d4c3a8e5f1b2d"
  }
}

How to fix it

  • Use the method shown on the endpoint’s reference page.

Detect it in code

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