invalid_api_key

The message text is shown in the example below.

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

When it happens

The key is not one Syntic issued, or it is inactive.

Example

{
  "error": {
    "type": "authentication_error",
    "code": "invalid_api_key",
    "message": "The API key is invalid.",
    "param": null,
    "request_id": "req_6f1c2a9e0b7d4c3a8e5f1b2d"
  }
}

How to fix it

  • Copy the key again from the Console; keys start with sk_live_.
  • Check for whitespace or a newline at the end of the value.
  • Make sure you are not sending a publishable key or an Admin key to an inference endpoint.

Detect it in code

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