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

# Errors

> Error envelopes for v1 and v2, the mapping between them, HTTP status codes and the full error code table.

Every error response is JSON and carries the request id (see [Request IDs](https://docs.oktivo.com/api-reference/request-ids.md)). Use the HTTP status for control flow and the `code` for the specific reason. Do not parse `message`; its wording can change.

## v2 envelope

```json theme={null}
{
  "success": false,
  "requestId": "3f1c2c0e-6a41-4e0b-9f0e-1f2d6f1b8a77",
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Request validation failed",
    "details": [
      { "in": "body", "path": "phone", "message": "must be in E.164 format (e.g. +14155551234)" }
    ]
  }
}
```

| Field | Description |
| - | - |
| `success` | Always `false`. |
| `requestId` | Same value as the `X-Request-ID` response header. |
| `error.code` | Stable machine-readable code. |
| `error.message` | Human-readable summary. |
| `error.details` | Optional. For validation errors, a list of `{ in, path, message }` where `in` is `body`, `query` or `params`. Other errors may carry extra context, for example `retryAfterSec`. |

Successful v2 responses use `{ "success": true, "requestId", "timestamp", "data", "meta"? }`. See [Stack traces](#stack-traces) for what server errors expose.

## v1 envelope

v1 error bodies keep every field they had before and add three: `requestId`, `code` and `errorInfo`. Nothing was removed or renamed.

```json theme={null}
{
  "success": false,
  "message": "Validation failed",
  "errors": [
    { "field": "phone", "message": "phone is required" }
  ],
  "code": "VALIDATION_ERROR",
  "requestId": "3f1c2c0e-6a41-4e0b-9f0e-1f2d6f1b8a77",
  "errorInfo": {
    "code": "VALIDATION_ERROR",
    "message": "Validation failed",
    "details": [
      { "field": "phone", "message": "phone is required" }
    ]
  }
}
```

| Field | Description |
| - | - |
| `success` | Always `false`. |
| `message` | Legacy human-readable summary. Same text as `errorInfo.message`. |
| `code` | Stable machine-readable code. Same value as `errorInfo.code`. A code the handler set always wins; otherwise the code comes from the HTTP status (see the table). |
| `requestId` | Same value as the `X-Request-ID` response header. |
| `errorInfo` | The standard error object: `{ code, message, details? }`. |
| `errors` | Legacy field-level validation errors (`field`, `message`). Also copied to `errorInfo.details`. |
| `error` | Legacy string on webhook, campaign-webhook and log routes. See [frozen fields](https://docs.oktivo.com/api-reference/versioning.md#frozen-legacy-fields). |

`errorInfo.details` is, in this order: the `errors` array, a nested error `details`, an object with the extra context the route returned (`available`, `required`, `reason`, `requiredFeatures`, `validEventTypes`), or a legacy top-level `details` value. It is omitted when there is none.

An out-of-credits call returns the extra fields next to the standard ones:

```json theme={null}
{
  "success": false,
  "message": "Insufficient credits",
  "available": 1,
  "required": 5,
  "code": "ERROR",
  "requestId": "3f1c2c0e-6a41-4e0b-9f0e-1f2d6f1b8a77",
  "errorInfo": {
    "code": "INSUFFICIENT_CREDITS",
    "message": "Insufficient credits",
    "details": { "available": 1, "required": 5 }
  }
}
```

A v1 `402` has no specific code today, so it carries the fallback `ERROR`. Branch on the HTTP status for it.

> [!NOTE]
>
> `errorInfo` is the v1 spelling of v2's `error`. v1 cannot put an object under `error` because several v1 routes already return `error` as a string and existing integrations read it.

Other v1 details:

* Per-item errors inside a successful `POST /calls/bulk` response (`results[].error`) are not error envelopes. They keep their `{ code, message }` shape, where `code` is an HTTP-style number.
* The tracking endpoint (`/track`) returns a nested `error: { code, message }` object, and `errorInfo` is copied from it.
* A webhook test delivery that reaches your URL but fails returns `200` with `success: false`. It is a result, not an error envelope, so it has no `errorInfo`.
* Responses that are not JSON objects (arrays, files, streams, redirects, `track.js`) are never wrapped.

## Mapping v1 `errorInfo` to v2 `error`

| v1 | v2 | Notes |
| - | - | - |
| `errorInfo.code` | `error.code` | Same catalog. v1 uses `UNAUTHENTICATED` where v2 uses `UNAUTHORIZED`. |
| `errorInfo.message` | `error.message` | Same meaning. |
| `errorInfo.details` | `error.details` | v1 validation details are `{ field, message }`. v2 details are `{ in, path, message }`. |
| `requestId` | `requestId` | Identical. |
| `message`, `errors`, `error` (string) | not present | Legacy v1 fields. See [frozen fields](https://docs.oktivo.com/api-reference/versioning.md#frozen-legacy-fields). |
| HTTP `400` for validation | HTTP `422` for validation | The only status that differs for the same outcome. |

A client that reads `errorInfo.code` and `errorInfo.message` first, and falls back to `message`, works on v1 responses from before and after this change. The dashboard does this.

## HTTP status codes

| Status | v2 | v1 |
| - | - | - |
| 400 | `BAD_REQUEST` for a malformed JSON body | Validation errors, malformed requests |
| 401 | `UNAUTHORIZED` | Missing or invalid token |
| 402 | `INSUFFICIENT_CREDITS` | Insufficient credits |
| 403 | `FORBIDDEN` and specific codes | Feature not available for the account, contact on DND |
| 404 | `NOT_FOUND` and specific codes | Resource not found |
| 409 | `CONFLICT` and specific codes | Conflict with the resource state |
| 413 | `PAYLOAD_TOO_LARGE` | `PAYLOAD_TOO_LARGE` |
| 422 | Validation errors (`VALIDATION_ERROR` and specific codes), idempotency key reuse | Idempotency key reuse only |
| 429 | `RATE_LIMITED`, `SCHEDULE_LIMIT_REACHED` | `RATE_LIMITED` |
| 500 | `INTERNAL_ERROR` | `INTERNAL_ERROR` |
| 503 | `SERVICE_UNAVAILABLE`, `VOICE_UNAVAILABLE`, `CALL_FAILED`, `NOT_READY` | `SERVICE_UNAVAILABLE` |

## Error code table

One catalog serves both versions. A code never changes its meaning, and new codes can be added at any time (see [Versioning](https://docs.oktivo.com/api-reference/versioning.md)). Handle unknown codes by falling back to the HTTP status.

| Code | Status | Returned by | Meaning |
| - | - | - | - |
| `BAD_REQUEST` | 400 | v1, v2 | The request is malformed or cannot be processed. |
| `VALIDATION_ERROR` | 400, 422 | v1, v2 | One or more fields failed validation. See details/errors. |
| `UNAUTHENTICATED` | 401 | v1 | Credentials are missing or could not be verified. |
| `UNAUTHORIZED` | 401 | v2 | v2 spelling of an authentication failure. |
| `FORBIDDEN` | 403 | v1, v2 | The caller is authenticated but not allowed to do this. |
| `NOT_FOUND` | 404 | v1, v2 | The resource does not exist for this account. |
| `METHOD_NOT_ALLOWED` | 405 | v1 | The HTTP method is not supported on this path. |
| `CONFLICT` | 409 | v1, v2 | The request conflicts with the current state of the resource. |
| `PAYLOAD_TOO_LARGE` | 413 | v1, v2 | The request body exceeds the size limit. |
| `UNSUPPORTED_MEDIA_TYPE` | 415 | v1 | The Content-Type is not supported. |
| `UNPROCESSABLE_ENTITY` | 422 | v1 | The request is well formed but semantically invalid. |
| `RATE_LIMITED` | 429 | v1, v2 | Too many requests. Honor the Retry-After header. |
| `INTERNAL_ERROR` | 500 | v1, v2 | Unexpected server error. Quote the requestId when contacting support. |
| `UPSTREAM_ERROR` | 502 | v1 | A service this API depends on returned an error. |
| `SERVICE_UNAVAILABLE` | 503 | v1, v2 | A dependency is temporarily unavailable. Retry later. |
| `UPSTREAM_TIMEOUT` | 504 | v1 | A service this API depends on timed out. |
| `ERROR` | 4xx | v1 | Fallback for any 4xx status that has no more specific code. |
| `INVALID_TOKEN` | 401 | v1 | The API token is invalid, revoked or its owner no longer exists. |
| `TOKEN_EXPIRED` | 401 | v1 | The API token has expired. |
| `ACCOUNT_SUSPENDED` | 401 | v1 | The token owner's account is suspended. |
| `FEATURE_ACCESS_DENIED` | 403 | v1, v2 | The feature is not enabled for the organization or the user. |
| `INVALID_IDEMPOTENCY_KEY` | 400 | v1, v2 | The Idempotency-Key header is malformed. |
| `IDEMPOTENCY_KEY_REUSED` | 422 | v1, v2 | The Idempotency-Key was already used with a different request. |
| `IDEMPOTENCY_IN_PROGRESS` | 409 | v1, v2 | A request with this Idempotency-Key is still being processed. |
| `INSUFFICIENT_CREDITS` | 402 | v1, v2 | The account balance cannot cover the operation. |
| `CONTACT_ON_DND` | 403 | v1, v2 | The number is on the do-not-disturb list. |
| `AGENT_NOT_FOUND` | 404 | v2 | The agent does not exist for this account. |
| `CALL_FAILED` | 503 | v2 | The call could not be placed. |
| `CALL_NOT_CANCELLABLE` | 409 | v2 | The call is already in progress or finished and cannot be cancelled. |
| `INVALID_CALLER_ID` | 422 | v2 | The caller id (did) is not an active outbound number of the account. |
| `SCHEDULE_LIMIT_REACHED` | 429 | v1, v2 | The account reached its limit of scheduled calls. |
| `TOO_MANY_ITEMS` | 422 | v2 | The bulk request contains more items than allowed. |
| `VOICE_UNAVAILABLE` | 503 | v2 | The voice service is not available right now. |
| `QUEUED_CALL_NOT_FOUND` | 404 | v2 | The queued call does not exist. |
| `EVENT_NOT_FOUND` | 404 | v2 | The event does not exist. |
| `INVALID_EVENT_TYPE` | 422 | v2 | An event type is not part of the event catalog. |
| `INVALID_EVENT_GROUP` | 422 | v2 | An event group is not part of the event catalog. |
| `WEBHOOK_NOT_FOUND` | 404 | v2 | The webhook endpoint does not exist. |
| `WEBHOOK_LIMIT_REACHED` | 409 | v2 | The account reached its limit of webhook endpoints. |
| `INVALID_WEBHOOK_URL` | 422 | v2 | The webhook URL is not allowed. |
| `INVALID_AGENT_IDS` | 422 | v2 | One or more agent ids do not belong to the account. |
| `DELIVERY_NOT_FOUND` | 404 | v2 | The webhook delivery does not exist. |
| `DUPLICATE_LEAD_EMAIL` | 409 | v1, v2 | A lead with this email already exists. |
| `DUPLICATE_LEAD_SOURCE` | 409 | v1, v2 | A lead with this source reference already exists. |
| `NOT_READY` | 503 | v2 | `GET /api/v2/health/ready` only: the database is not reachable. |

When a v1 handler sets no specific code, the code is derived from the status: 400 `BAD_REQUEST` (`VALIDATION_ERROR` when the message is "Validation failed"), 401 `UNAUTHENTICATED`, 402 `INSUFFICIENT_CREDITS`, 403 `FORBIDDEN`, 404 `NOT_FOUND`, 405 `METHOD_NOT_ALLOWED`, 409 `CONFLICT`, 413 `PAYLOAD_TOO_LARGE`, 415 `UNSUPPORTED_MEDIA_TYPE`, 422 `UNPROCESSABLE_ENTITY`, 429 `RATE_LIMITED`, 502 `UPSTREAM_ERROR`, 503 `SERVICE_UNAVAILABLE`, 504 `UPSTREAM_TIMEOUT`, any other 5xx `INTERNAL_ERROR`, any other 4xx `ERROR`.

Items inside a v2 bulk call response carry their own `error: { code, message }` (for example `INSUFFICIENT_CREDITS` or `INTERNAL_ERROR`); see the migration guide.

## Stack traces

Error responses never include a stack trace unless the operator of the deployment explicitly sets `EXPOSE_STACK_TRACES=true`. `NODE_ENV` has no effect on this. The flag is meant for local debugging only. Unexpected `4xx` errors that are not caused by your input return the generic message `Bad request`, and `5xx` errors return `Internal server error`.

## Handling errors

* Retry `429` and `503` after the `Retry-After` header, with backoff. Retry `500` only with an `Idempotency-Key` (see [Idempotency](https://docs.oktivo.com/api-reference/idempotency.md)).
* Do not retry other `4xx` responses without changing the request.
* Quote `requestId` when you contact support.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.