> ## Documentation Index
> Fetch the complete documentation index at: /llms.txt
> Use this file to discover all available pages before exploring further.

# Errors

> Understand how Playto API formats error responses.

Every API error on the `/v1` endpoints renders as a single, stable JSON shape so integrators can branch on it programmatically. The one exception is a URL that does not exist, which returns an HTML page (see [Errors that are not JSON](#errors-that-are-not-json)).

```json
{
  "error": {
    "type": "invalid_request_error",
    "code": "validation_error",
    "message": "One or more fields are invalid.",
    "details": {
      "customer_email": ["Enter a valid email address."]
    }
  }
}
```

### Error Fields

**type** `string`

The broad category of the error. Common types include:

* `invalid_request_error`
* `authentication_error`
* `permission_error`
* `not_found_error`
* `conflict_error`
* `rate_limit_error`
* `api_error`

**code** `string`

A short string providing a specific machine code for the error. Useful for programmatic branching (e.g. `resource_not_found`, `idempotency_conflict`, `validation_error`). Branch on `code`, not on `message`.

**message** `string`

A human-readable summary of the error.

**details** `object`

Optional. Present on validation errors (`type=invalid_request_error`, `code=validation_error`) and on `409` `duplicate_reference_id` errors. On a validation error it contains keys matching the request fields that failed validation, with arrays of error strings. On `duplicate_reference_id` it contains `invoice_id`, the `id` of the existing invoice.

**retry\_after** `integer`

Optional. Present on `429` responses (`code=rate_limited`). The number of seconds to wait before you try again. It is the same number as the `Retry-After` header.

### Examples

```json 404 Not found
{
  "error": {
    "type": "not_found_error",
    "code": "resource_not_found",
    "message": "Invoice not found."
  }
}
```

```json 422 Void a paid invoice
{
  "error": {
    "type": "invalid_request_error",
    "code": "invoice_already_paid",
    "message": "A paid invoice cannot be voided."
  }
}
```

```json 401 Missing API key
{
  "error": {
    "type": "authentication_error",
    "code": "not_authenticated",
    "message": "Authentication credentials were not provided."
  }
}
```

```json 429 Rate limited
{
  "error": {
    "type": "rate_limit_error",
    "code": "rate_limited",
    "message": "Request was throttled. Expected available in 42 seconds.",
    "retry_after": 42
  }
}
```

## Error codes

| HTTP status | `type` | `code` | Meaning | What to do |
| - | - | - | - | - |
| `400` | `invalid_request_error` | `validation_error` | A field is missing or invalid: a bad email, an unsupported currency, an amount that is not a whole number or is outside the range for its currency, or a missing required field. `details` lists each failing field. | Fix the fields named in `details` and send the request again. |
| `400` | `api_error` | `error` | The request body could not be parsed, for example malformed JSON. `message` says what went wrong. | Send valid JSON with `Content-Type: application/json`. |
| `401` | `authentication_error` | `not_authenticated` | The `X-API-KEY` header is missing. | Send your key in `X-API-KEY` on every request. |
| `401` | `authentication_error` | `authentication_failed` | The key is not recognised, or it was revoked or replaced (`Invalid or inactive API Key`). It also covers a key from the other environment: a test key on production (`Test keys are not accepted on the production API...`) or a live key on sandbox (`Live keys are not accepted on the sandbox API...`). | Use the key that matches the base URL, or generate a new key in the dashboard. |
| `403` | `permission_error` | `permission_denied` | Your account is not KYC-approved yet (`Playto Pay is available once your KYC has been verified and approved.`). Applies to products, invoices and customers. Transactions do not need KYC approval. | Complete KYC verification in the dashboard. |
| `403` | `permission_error` | `partner_terms_not_signed` | You have not signed the current Master Service Partner Agreement. Applies to the same endpoints as `permission_denied`. | Review and sign the agreement in the dashboard. |
| `403` | `permission_error` | `use_service_orders` | Creating products and invoices through the API is switched off (`Payment links, plans and invoices can no longer be created. Create a service order instead.`). Reading them still works. | Create a service order in the dashboard instead. |
| `404` | none (HTML page) | none | The path does not exist. The usual cause is a missing trailing slash. See [Errors that are not JSON](#errors-that-are-not-json). | Add the trailing slash, for example `/v1/products/`. |
| `404` | `not_found_error` | `resource_not_found` | No product, invoice, customer or transaction with that id on your account. `message` names the resource, for example `Invoice not found.` Sandbox and production are separate, so an id from one does not exist in the other. | Check the id, the key and the base URL. |
| `405` | `invalid_request_error` | `method_not_allowed` | The HTTP method is not supported on that URL, for example `DELETE /v1/products/{id}/`. | Check the method on that endpoint's page. |
| `406` | `api_error` | `error` | The `Accept` header asks for a format the API cannot return. | Send `Accept: application/json`, or leave the header out. |
| `409` | `conflict_error` | `idempotency_conflict` | A problem with the `Idempotency-Key`: it was already used with a different request, a request with that key is still being processed, or the key is longer than 255 characters. `message` says which. | Use a new key for a different request. If the first request is still processing, wait and retry with the same key. See [Idempotency](/api-reference/idempotency.md). |
| `409` | `conflict_error` | `duplicate_reference_id` | You tried to create an invoice with a `reference_id` that another invoice on your account already uses. A paid, expired or voided invoice still counts. `details.invoice_id` is the `id` of that invoice. | Fetch it with `GET /v1/invoices/{id}/`, or send a different `reference_id` if this is a new invoice. See [Create Invoice](/api-reference/invoices/create.md#param-reference-id). |
| `415` | `api_error` | `error` | The `Content-Type` is not one the API reads. JSON, form-encoded and multipart bodies are accepted. | Send `Content-Type: application/json`. |
| `422` | `invalid_request_error` | `invoice_already_paid` | You tried to void an invoice that has been paid. | A paid invoice cannot be voided. Nothing to retry. |
| `429` | `rate_limit_error` | `rate_limited` | More requests in a minute than a limit allows: 300 for your account, or 10 on `POST /v1/webhooks/test/`. The response has a `Retry-After` header, and the same number in `retry_after`, giving the seconds to wait. | Wait the number of seconds in `Retry-After`, then retry. Slow down or back off when you see this. |
| `500` | `api_error` | `internal_error` | An unexpected error on our side. The cause is not returned. | Retry. Requests that fail are not stored against an `Idempotency-Key`, so it is safe to reuse the same key. If it keeps happening, contact [support@playto.so](mailto:support@playto.so). |

> [!NOTE]
>
> Read the wait time from the `Retry-After` header (in seconds) and back off: wait at least that long before you send the next request, and slow down so you do not hit the limit again.

## Errors that are not JSON

Endpoint paths end with `/`, and the API does not redirect a path that is missing it. `GET /v1/products` and `POST /v1/products` (no trailing slash) return an **HTML** `404 Not Found` page, not a JSON error. The same happens for any path that does not exist. If your client always parses error bodies as JSON, check the HTTP status and the `Content-Type` first.

```html 404
<!doctype html>
<html lang="en">
<head>
  <title>Not Found</title>
</head>
<body>
  <h1>Not Found</h1><p>The requested resource was not found on this server.</p>
</body>
</html>
```
