# Errors and limits

The response envelope, every error code the Core API returns, the rate limits, AI turns and voice minutes your plan allows, how to send a request again safely, the request size limits, and what a 402 means.

Source: https://docs.omazy.ai/reference/core-api/errors-and-limits/

## The envelope

Every JSON response has the same outer shape.

Success:

```json
{ "success": true, "data": { } }
```

Failure:

```json
{
  "success": false,
  "error": { "code": "BAD_REQUEST", "message": "messages is required" }
}
```

`code` is the part to write an `if` about. It is stable. `message` is a
sentence for a person, it names the field or the rule that failed, and it gets
reworded when somebody improves it. Log the message. Branch on the code.

Three responses on this API are not this envelope:

- `POST /voice/speak` answers with audio on success.
- `POST /ai/complete` with `"stream": true` answers with Server-Sent Events.
- A call outcome or voice job posted to your `callback_url` is a plain JSON
  object.

In all three, a request refused before the work starts still gets the JSON
error envelope.

Every response carries a request id, a refused one included:

```http
X-Request-Id: req_4b09ccab08ad46afb5556107d238f6a1
```

Log it next to the error. If you need to tell us about a failed call, that id
finds it. You can send your own `X-Request-Id` and it is kept, as long as it is
at most 128 characters of letters, digits, `-`, `_`, `.` and `:`. One id then
follows a request through your system and ours.

## Error codes

| Status | Code | Means | What to do |
|---|---|---|---|
| `400` | `BAD_REQUEST` | The request is malformed, breaks a limit, or breaks a rule | Read `message`, fix the request. Do not retry unchanged |
| `401` | `UNAUTHORIZED` | The token is missing, malformed, revoked, expired or wrong | Fix the `Authorization` header, or [rotate](/reference/core-api/authentication/#expiry-and-rotation) an expired token |
| `402` | `PAYMENT_REQUIRED` | A spend budget that covers this call is used up | See [What a 402 means](#what-a-402-means) |
| `402` | `PLAN_LIMIT_REACHED` | The workspace has used the AI turns or the voice minutes its plan includes for the period | See [Your plan's AI turns](#your-plans-ai-turns) and [Your plan's voice minutes](#your-plans-voice-minutes). Retrying will not help |
| `402` | `SUBSCRIPTION_PAUSED` | The workspace's subscription is paused | Resume the subscription. Retrying will not help |
| `403` | `WORKSPACE_INACTIVE` | The workspace is suspended or closed | Nothing to fix in the request. Talk to whoever owns the workspace |
| `403` | `FORBIDDEN` | The token lacks the scope, the model is not available to your workspace, or a bound token belongs to a different user | Read `message`. Retrying will not help |
| `403` | `MODEL_NOT_AVAILABLE` | The model you asked to set on the agent is not on your plan | Pick one of `models` in [Agent settings](/reference/core-api/agent-settings/) |
| `404` | `NOT_FOUND` | No such customer, conversation, app, call or job in this workspace | Check the id and the `app` |
| `409` | `CONFLICT` | The conversation is already bound to another user | Do not retry. See [Data and messages](/reference/core-api/data-and-messages/#bind-a-signed-in-users-token-to-their-chat) |
| `409` | `IDEMPOTENCY_IN_PROGRESS` | A request with the same `Idempotency-Key` is still running. Nothing ran for this one | Wait as long as `Retry-After` says, then send it again |
| `422` | `MODEL_NOT_SERVING` | The model you asked to set on the agent did not answer a test call. Nothing changed | Read `message` for the reason. Try again later or pick another model |
| `422` | `IDEMPOTENCY_KEY_REUSED` | The `Idempotency-Key` was first sent with a different request. Nothing ran | Use a new key for a new request. See [Sending a request again](#sending-a-request-again) |
| `429` | `RATE_LIMIT_EXCEEDED` | Your token passed its rate limit, or the model provider is rate-limiting | Wait, then retry with backoff |
| `500` | `INTERNAL_ERROR` | Something failed on our side | Retry once, then tell us |
| `501` | `UPSTREAM_UNAVAILABLE` | The feature behind this route is not enabled on this deployment | Tell us. Retrying will not help |
| `501` | `NOT_IMPLEMENTED` | Stored session credentials are not enabled on this deployment | Tell us. Retrying will not help |
| `502` | `UPSTREAM_REJECTED` | A provider refused or failed the call, or your MCP server could not verify a token | Retry once. If it persists, check the request |
| `503` | `UPSTREAM_UNAVAILABLE` | Knowledge search, speech or telephony is not configured | Tell us |
| `503` | `UPSTREAM_UNAVAILABLE` | The request carried an `Idempotency-Key` and the key could not be checked. Nothing ran | Wait as long as `Retry-After` says, then send it again |
| `503` | `NOT_AVAILABLE` | Knowledge documents are not available on this deployment yet | Tell us. Retrying will not help |
| `504` | `UPSTREAM_UNAVAILABLE` | The work did not finish inside the time allowed | Retry, with a smaller request if you can |

`UPSTREAM_UNAVAILABLE` arrives under three statuses, and they mean different
things. Under `504` it is a timeout and a retry is reasonable. Under `501` and
`503` something is switched off, and no number of retries will switch it on.
This is the one place on this API where the status tells you more than the
code.

One `503` is the exception: a request sent with an `Idempotency-Key` whose key
could not be checked. It carries `Retry-After`, nothing ran, and sending it
again is the right thing to do.

Two codes carry more than one meaning, and the `message` tells them apart.

**`403 FORBIDDEN`** is `missing scope: <scope>` when the token may not use the
route, and `"<model>" is not available on this workspace's plan` when a
completion named a model your workspace may not run. Binding a session
credential adds a third: the token you sent belongs to a different user than
the one you named.

**`429 RATE_LIMIT_EXCEEDED`** is `this install made more than 600 AI calls in
10 minutes; slow down` when your own token is over its limit (the number
follows your plan and the words follow the bucket: `knowledge calls`,
`call placements`), and `the model
provider is rate-limiting; retry shortly` when the provider behind the model is.
Both want the same response from you, which is to wait.

A `404` deserves a second look before you go hunting for a deleted record. It
is also what you get for an id that exists in a different workspace, and for a
call or job that belongs to a different app than the one the request ran
against.

The platform-wide list of codes is on
[Error codes](/reference/platform/error-codes/). The Core API returns only the
ones above.

## Before any route runs

Two refusals come from the workspace, not from the request. They apply to
every route, `GET /whoami` and the MCP server included, and nothing is spent.

- **`403 WORKSPACE_INACTIVE`**: the workspace was suspended or closed.
- **`402 SUBSCRIPTION_PAUSED`**: its subscription is paused.

A change to a workspace's standing can take up to 30 seconds to show.

## Rate limits

Every plan can use the Core API, the free plan included. The plan decides how
fast. Limits are counted per token, over a sliding window of `10` minutes, and
the size of each bucket is ten times the plan's calls per minute.

| Bucket | Limit | Routes |
|---|---|---|
| AI and speech | The plan's rate, per 10 minutes | `POST /ai/complete`, `POST /agent/turn`, `POST /voice/speak`, `POST /voice/transcribe`, `POST /voice/jobs` |
| Knowledge | The plan's rate, per 10 minutes | `POST /knowledge/search`, and the `GET` routes under `/knowledge` |
| Knowledge writes | The plan's rate, per 10 minutes | `POST`, `PATCH` and `DELETE` on `/knowledge/documents`, `POST /knowledge/import`, `POST /knowledge/sources` and its crawl |
| Settings | The plan's rate, per 10 minutes | `GET` and `PATCH /agent/settings` |
| Call placement | `30` requests per 10 minutes, on every plan | `POST /voice/calls` |

The free plan allows `60` calls a minute, so a token on it has `600` requests
per 10 minutes in each of the first four buckets. Larger plans allow up to
`2400` calls a minute. [`GET /whoami`](/reference/core-api/data-and-messages/#who-am-i)
reports your workspace's number as `plan.rate_per_minute`, and every response
from a limited route carries the bucket's size in `X-RateLimit-Limit`.

A change of plan shows within a minute.

The five routes in the first row share one count. A burst of transcriptions
leaves less room for completions in the same ten minutes. Knowledge is counted
on its own, so a storm of searches cannot stop live turns, and the reverse.

A tool call on the [MCP server](/reference/core-api/mcp/) spends the bucket of
the route it runs. MCP is not a second allowance.

Every response from a limited route says where you stand:

```http
X-RateLimit-Limit: 600
X-RateLimit-Remaining: 587
X-RateLimit-Reset: 0
```

`X-RateLimit-Reset` is the number of seconds until a place frees in that
bucket. It is `0` while places are free. A `429` also carries `Retry-After`
with the same number.

The remaining routes, including `GET /voice/calls/{ref}`, `GET /voice/jobs/{id}`
and everything on [Data and messages](/reference/core-api/data-and-messages/),
have no per-token limit of this kind.

Things worth knowing about how the count works:

- **It slides.** There is no reset on the hour. Each request holds its place for
  ten minutes and then stops counting.
- **Refused requests count.** A request that passes authentication and then
  fails validation with a `400` still used a place. A loop that sends the same
  broken request will rate-limit itself.
- **A request turned away with `429` does not count.** Waiting does clear it.
- **Wait as long as `Retry-After` says.** After a full window that can be
  minutes. Add some randomness so your workers do not all return at once.

The rate limit is a guard against a runaway loop, not the thing that governs
cost. Your plan's AI turns, its voice minutes and your workspace's budget do
that.

## Your plan's AI turns

A plan includes a number of AI turns for each billing period. A completion or
an agent turn that the API answers uses one. It is the same allowance your
widget and console conversations use, so a workspace has one number to watch,
whichever way its AI is reached.

| Counts as one AI turn | Does not count |
|---|---|
| `POST /ai/complete`, whole or streamed | A request that was refused or failed |
| `POST /agent/turn` | Knowledge search, speech, calls, voice jobs, and the data routes |
| The `ai_complete` and `agent_turn` tools over MCP | Listing tools, `whoami` |

`GET /whoami` says where the workspace stands:

```json
"plan": {
  "sku": "free",
  "rate_per_minute": 60,
  "ai_turns": { "used": 412, "limit": 6000, "resets_at": "2026-12-07T10:40:52Z" }
}
```

A `limit` of `-1` means the plan does not cap AI turns.

When the allowance is used up, those two routes answer:

```json
{
  "success": false,
  "error": {
    "code": "PLAN_LIMIT_REACHED",
    "message": "this workspace has used its plan's AI turns for the period (6601 of 6000); it resets on 2026-12-07"
  }
}
```

The status is `402`. There is a margin: the API keeps answering until the
workspace is 10% past the number its plan includes, and a plan with overage
turned on is not stopped at all. Every other route keeps working, so a product
can still search its knowledge base and read its data while it tells its owner.

It clears when the period resets or the workspace moves to a larger plan.
Retrying does not help. Treat it as you treat `PAYMENT_REQUIRED`: stop calling,
and tell whoever owns the workspace.

## Your plan's voice minutes

A plan also includes a number of voice minutes for each billing period. They
are the same minutes a phone call to your agent uses.

| Draws on voice minutes | How much |
|---|---|
| `POST /voice/speak`, `POST /voice/transcribe` | The length of the audio, rounded up to a whole minute, at least one a request |
| `POST /voice/jobs` | The length of the recording, when the job finishes |
| `POST /voice/calls` | The length of the call, when it ends |

`GET /whoami` reports them next to the AI turns:

```json
"voice_minutes": { "used": 37, "limit": 2000, "resets_at": "2026-12-07T10:40:52Z" }
```

When they are used up, those four routes answer `402 PLAN_LIMIT_REACHED`, with
a message that names voice minutes. Unlike AI turns there is no margin: the
minutes are a cost paid to a carrier and a speech provider, so the routes stop
at the number the plan includes. A workspace that has agreed to overage billing
with a credit limit is not stopped. Reading a call or a job that already exists
keeps working, and so does every route that is not voice.

Minutes are counted when the audio is known, not when the request arrives. A
call or a job accepted with a minute left still runs to its end.

## Sending a request again

Sometimes the answer does not reach you: a timeout, a dropped connection, a
restart on your side. For a read, send the request again. For a request that
changes something that is not safe on its own, because a second call placement
rings the phone a second time.

Give the request a name with an `Idempotency-Key` header and it becomes safe to
repeat. The first request that succeeds is remembered for `24` hours. A repeat
with the same key gets that answer back and runs nothing.

```sh
curl https://mw.omazy.ai/api/v1/core/voice/calls \
  -H "Authorization: Bearer $OMAZY_CORE_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: delivery-48213-confirm" \
  -d '{ "to": "+447700900123", "purpose": "confirmation", "consent_basis": "transaction",
        "opening": "Hello, this is Nordwell calling about your delivery tomorrow." }'
```

A replayed answer has the same status and body as the first, and one more
header:

```http
Idempotent-Replayed: true
```

The routes that take a key:

| Route | Without a key, a repeat |
|---|---|
| `POST /voice/calls` | Places a second call |
| `POST /conversations/{id}/messages` | Posts the message twice |
| `POST /channels/linkedin/publish` | Publishes twice |
| `POST /agent/turn` | Runs the turn again, and any tool it fires |
| `POST /voice/jobs` | Starts a second job |
| `POST /knowledge/documents`, `POST /knowledge/import` | Adds a second document when anything differs |
| `POST /knowledge/sources`, `POST /knowledge/sources/{id}/crawl` | Starts a second crawl |

Other routes ignore the header. Reads, `PATCH`, `PUT` and `DELETE` give the
same result however often they run, and a completion changes nothing.

The rules:

- **The key is yours to choose.** `1` to `255` printable ASCII characters with
  no spaces. A UUID works. So does an id you already have, such as an order
  number with the step it belongs to.
- **One key, one request.** The same key with a different body, path or query
  is refused with `422 IDEMPOTENCY_KEY_REUSED`.
- **Only success is remembered.** A request that was refused or failed frees
  its key, so the retry runs. You do not need a new key after a `400`, a `429`
  or a `502`.
- **A repeat during the first is told to wait.** While the first request is
  still running, a repeat answers `409 IDEMPOTENCY_IN_PROGRESS` with
  `Retry-After`. Nothing runs twice.
- **A key is never skipped.** If the key cannot be checked, the request is
  refused with a `503` and `Retry-After` before anything runs.
- **Keys belong to a token.** Two tokens can use the same key without meeting.
- **A replay costs a place in the rate bucket and nothing else.** A replayed
  agent turn does not use a second AI turn.

A file uploaded as a form (`multipart/form-data`) is matched on its path and
query only, because a form's body differs each time it is built. Everything
else is matched on the exact body.

On the [MCP server](/reference/core-api/mcp/#arguments) the key is an argument
of the tool, `idempotency_key`. The [client libraries](/reference/core-api/client-libraries/)
take a key and then retry the request for you.

## Request limits

| Route | Limit |
|---|---|
| `POST /ai/complete` | `200` messages, `64` tools, `400000` bytes of text in total |
| `POST /ai/complete` | `max_tokens` default `1024`, at most `8192`. `temperature` from `0` to `2` |
| `POST /knowledge/search` | `query` at most `2000` bytes. `top_k` default `8`, at most `20` |
| `POST /knowledge/documents` | `title` at most `300` characters, `content` at most `2` MB, `data` at most `256` KB |
| `POST /knowledge/import` | A file of at most `20` MB, `filename` at most `255` characters |
| `POST /knowledge/sources` | `max_pages` at most `200`, `max_depth` at most `4` |
| `GET /knowledge/documents`, `GET /knowledge/export` | `limit` default `50`, at most `200` |
| `POST /agent/turn` | `message` at most `8000` bytes. `history` at most `200` turns |
| `POST /voice/speak` | `text` at most `2000` characters |
| `POST /voice/transcribe` | Audio at most `8` MB |
| `POST /voice/calls` | `opening` and `goal` at most `500` bytes each, `purpose` at most `80`, `variables` at most `32` keys, `script` at most `16` KB |
| `POST /conversations/{id}/messages` | `1` to `12` blocks |
| `POST /channels/linkedin/publish` | `text` at most `3000` characters |

Where a limit says bytes, the text is measured as UTF-8. English is one byte a
character. Bangla, Arabic, Chinese and most other scripts take two or three, so
they reach a byte limit well before the same number of characters.

Going over a limit is a `400 BAD_REQUEST`, with one exception: a `top_k` above
`20` is quietly lowered to `20`.

| Work | Time allowed |
|---|---|
| A completion, or an agent turn | `120` seconds |
| A knowledge search, speech in either direction, or accepting a call | `60` seconds |
| Reading or writing knowledge documents, an upload, an export | `90` seconds |

Set your own HTTP client's timeout a little above these, not below. A client
that gives up at 30 seconds on an agent turn will abandon answers that were
about to arrive, and the tokens are spent either way.

## What a 402 means

Three codes arrive with a `402`. `SUBSCRIPTION_PAUSED` is about the
subscription and `PLAN_LIMIT_REACHED` is about the plan's AI turns or voice
minutes. Both are described above. The third is about money already allotted:

```json
{
  "success": false,
  "error": { "code": "PAYMENT_REQUIRED", "message": "the workspace's AI budget is spent" }
}
```

The call was refused before it reached a model provider, because a spend budget
that covers it has been used up or AI spending has been paused. Nothing was
charged for the refused call.

It is not a problem with your request, and it is not a rate limit. Sending it
again a minute later gets the same answer. It clears when the budget period
rolls over or somebody raises the budget.

What to do in code: stop calling, and say so. A job that retries a `402` in a
loop achieves nothing, and a product that shows a generic error leaves its own
team guessing. Surface it to whoever owns the workspace's spending, who can see
where it went under Usage and Spend in the
[LLM Gateway](/reference/llm-gateway/).

On a streamed completion a spent budget arrives as an `error` frame, not as a
`402` status, because the stream has already begun. See
[Streaming](/reference/core-api/completions/#streaming).
