API referenceError code index403public_key_rejected

public_key_rejected

The message text is shown in the example below.

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

When it happens

A pk_live_ publishable key was used. Only secret keys may call /v1.

Example

{
  "error": {
    "type": "permission_error",
    "code": "public_key_rejected",
    "message": "A publishable key cannot call this endpoint. Use a secret API key.",
    "param": null,
    "request_id": "req_6f1c2a9e0b7d4c3a8e5f1b2d"
  }
}

How to fix it

  • Call the API from your server with a secret key, and keep the secret key out of browsers and apps.

Detect it in code

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