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

# Refused requests: find calls that never started

> Every call request we refuse and every campaign contact we reject is recorded. Read them with GET /v2/account/refusals or in the console, and get an email when one keeps repeating.

A call request we refuse never becomes a call. It has no call id, sends no
webhook and is not in your call list, so if your code doesn't check the answer,
nobody finds out. We record every refusal, group the repeats, and email your
company when one keeps happening.

## What is recorded

* Every `4xx` answer to [`POST /v2/calls`](https://docs.miraiminds.co/v2/calls#errors), on every
  channel. Two answers are left out because neither means a call was lost:
  `409 duplicate_call` (a request with the same `Idempotency-Key` is still in
  flight) and the replay of an answer we already gave for a key.
* Every row in `contacts_rejected` from
  [`POST /v2/campaigns/{id}/contacts`](https://docs.miraiminds.co/v2/campaigns#add-contacts), and from
  contacts you send with [`POST /v2/campaigns`](https://docs.miraiminds.co/v2/campaigns#create-a-campaign).
  Each is recorded with status `400`, code `contact_rejected`, the row's
  `reason` as its message, and the route `POST /v2/campaigns/{id}/contacts`.
  Only rejected rows are recorded on these routes. A request we refuse as a
  whole, such as one with more than 1000 rows, is answered with its error and
  not recorded, so check those answers in your code.

Calls the platform places for you are not recorded: a call-back the agent
promised on a call, the console's test calls and calls on the shared test line.
Each of those has its own record of what happened.

Refusals of the same kind form one group: the same route, status and code, and
the same message apart from its numbers and ids. A variable that was 4,105
characters on one call and 4,230 on the next is one group, and the group shows
the latest message. If 750 calls are refused for the same reason, you see one
group with `count: 750`.

We keep only what tells you what went wrong. Before a message is stored, every
phone number and email address in it becomes `•••`. That is any run of six or
more digits, with or without a leading `+`, and also when spaces, hyphens or
brackets split the digits. The message is then cut at 300 characters. We never
store the request body, its variables or the phone number. The record is kept
for 30 days.

## Read them with the API

```http theme={"system"}
GET /v2/account/refusals?hours=24
```

| Query param | Description |
| :- | :- |
| `hours` | How far back to look, a whole number from 1 to 168 (seven days). Default `24`. Anything else is `400 invalid_request`. |

Refusals are counted by the hour (UTC), so the window starts at the top of its
first hour. At 10:20 UTC, `hours=1` covers everything since 09:00 UTC, a little
more than the last 60 minutes.

Send your secret key, as you do for `POST /v2/calls`. For a
[sub-workspace](https://docs.miraiminds.co/v2/sub-workspaces.md), add its `Mirai-Workspace` header to read
that brand's refusals.

> [tab] cURL
>
> ```bash theme={"system"}
> curl -G https://sandbox.voice.miraiminds.co/v2/account/refusals \
>   -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
>   --data-urlencode "hours=24"
> ```

> [tab] Python
>
> ```python theme={"system"}
> import os, httpx
>
> API = "https://sandbox.voice.miraiminds.co"
> auth = {"Authorization": f"Bearer {os.environ['MIRAI_API_KEY']}"}
>
> r = httpx.get(f"{API}/v2/account/refusals", headers=auth,
>               params={"hours": 24}, timeout=30)
> refusals = r.raise_for_status().json()
> for g in refusals["groups"]:
>     print(g["count"], g["route"], g["status"], g["code"], g["message"])
>     if g["hint"]:
>         print("  fix:", g["hint"])
> ```

> [tab] Node.js
>
> ```javascript theme={"system"}
> const API = "https://sandbox.voice.miraiminds.co";
> const auth = { Authorization: `Bearer ${process.env.MIRAI_API_KEY}` };
>
> const res = await fetch(`${API}/v2/account/refusals?hours=24`, { headers: auth });
> const refusals = await res.json();
> if (!res.ok) throw new Error(`${refusals.error.code}: ${refusals.error.message}`);
> for (const g of refusals.groups) {
>   console.log(g.count, g.route, g.status, g.code, g.message);
>   if (g.hint) console.log("  fix:", g.hint);
> }
> ```

```json title="200 OK" theme={"system"}
{
  "window_hours": 24,
  "total": 756,
  "alert": true,
  "groups": [
    {
      "route": "POST /v2/calls",
      "status": 400,
      "code": "invalid_request",
      "message": "variables[\"calendar\"] is 5210 characters, the maximum is 4096; declare it in the agent's input_schema as an object, an array or a string with maxLength above 4096 to send up to 49152",
      "hint": "Shorten this variable, or declare it in the agent's input_schema as a long string.",
      "agent_id": "agt_01K7Q9F3K7M2N5P9R4T6V8W0XZ",
      "count": 742,
      "first_at": "2026-11-30T12:53:32Z",
      "last_at": "2026-12-01T11:20:01Z"
    },
    {
      "route": "POST /v2/campaigns/{id}/contacts",
      "status": 400,
      "code": "contact_rejected",
      "message": "phone must be an E.164 number",
      "hint": "Send each phone as + then the country code and the number, with no spaces, like +91 and the 10-digit number.",
      "agent_id": "agt_01K7Q9F3K7M2N5P9R4T6V8W0XZ",
      "count": 14,
      "first_at": "2026-12-01T06:02:11Z",
      "last_at": "2026-12-01T09:47:30Z"
    }
  ]
}
```

| Field | Description |
| :- | :- |
| `window_hours` | The `hours` this answer covers. |
| `total` | Every refusal in the window, in all groups. |
| `alert` | `true` when one kind was refused 10 or more times within 60 minutes and again in the last 24 hours. The console shows its banner while this is `true`. |
| `groups` | Up to 20 groups, the largest `count` first. `[]` when nothing was refused. |
| `groups[].route` | The request that was refused: `POST /v2/calls` or `POST /v2/campaigns/{id}/contacts`. |
| `groups[].status` | The HTTP status we answered with. |
| `groups[].code` | The `error.code` we answered with, or `contact_rejected` for a campaign row. |
| `groups[].message` | The latest `error.message` of the group, or the row's `reason`, with phone numbers and email addresses masked. |
| `groups[].hint` | How to fix it, in plain words, for the refusals we know. `""` when we have no hint. |
| `groups[].agent_id` | The agent the request named. `""` when we couldn't tell. |
| `groups[].count` | How many requests were refused this way in the window. |
| `groups[].first_at`, `groups[].last_at` | When the first and the latest of them in the window happened, in UTC. |

`503 refusals_unavailable` means we couldn't read the record just then. Try
again shortly.

## See them in the console

Open **Developers → Refused requests** in the
[sandbox](https://sandbox.voice.miraiminds.co/#/developers) or
[live](https://console.voice.miraiminds.co/#/developers) console. Each row is one
group: when it was last seen, the route, the status, the count, the message, the
fix, and the agent's name when we know it.

When `alert` is `true`, the console shows a banner with how many API calls were
refused in the last 24 hours, the message and fix of the largest group, and a
**See refused requests** link. If you dismiss it, it stays hidden for the rest of
the day.

## Email when a refusal repeats

When one kind of refusal happens 10 times within an hour, we email your
company's owners and billing contacts. The email says what was refused and how
many times, quotes the message with numbers masked, says how to fix it, and
links to **Refused requests** in the console and to this page.

* Only companies that have [gone live](https://docs.miraiminds.co/v2/go-live.md) get these emails. A sandbox
  sees the same record in the API and the console, but gets no email.
* One email a day at most for each kind of refusal. The day runs on India time.
* At most 3 refusal emails a day for one workspace.
* Our support team gets an alert at the same time.

## Alert on refusals in your own code

The email reaches people and comes at most once a day per kind. Your own code
sees every refusal the moment it happens, so alert there too:

* Log `error.code` and `error.message` for every `4xx` from `POST /v2/calls`,
  with your own record id.
* Alert when `4xx` answers pass a small rate, for example 5 in 10 minutes. A
  `400`, `402`, `403`, `404` or `422` keeps coming back until someone changes
  the request, the wallet or the agent, so retrying never clears it.
* Treat a non-empty `contacts_rejected` from a campaign the same way.
* From your monitoring, you can also read `GET /v2/account/refusals?hours=1`
  every few minutes and alert when `total` goes up or `alert` is `true`.

> [tab] Python
>
> ```python theme={"system"}
> import logging, os, httpx
>
> API = "https://sandbox.voice.miraiminds.co"
> auth = {"Authorization": f"Bearer {os.environ['MIRAI_API_KEY']}"}
> log = logging.getLogger("calls")
>
>
> def place_call(record_id: str, payload: dict) -> str | None:
>     r = httpx.post(f"{API}/v2/calls",
>                    headers={**auth, "Idempotency-Key": f"{record_id}-call-1"},
>                    json=payload, timeout=30)
>     if r.status_code == 202:
>         return r.json()["id"]
>
>     err = r.json().get("error", {}) if r.content else {}
>     code, message = err.get("code", "unknown"), err.get("message", r.text)
>     log.error("call refused: %s %s %s (record %s)", r.status_code, code, message, record_id)
>
>     if code == "duplicate_call":
>         return None              # the first request is still in flight
>     if r.status_code == 429:
>         raise RetryLater(r.headers.get("Retry-After", "5"))
>     if 400 <= r.status_code < 500:
>         alert_ops(f"Call for {record_id} refused: {r.status_code} {code}: {message}")
>     r.raise_for_status()
> ```

> [tab] Node.js
>
> ```javascript theme={"system"}
> const API = "https://sandbox.voice.miraiminds.co";
> const auth = { Authorization: `Bearer ${process.env.MIRAI_API_KEY}` };
>
> export async function placeCall(recordId, payload) {
>   const res = await fetch(`${API}/v2/calls`, {
>     method: "POST",
>     headers: {
>       ...auth,
>       "Content-Type": "application/json",
>       "Idempotency-Key": `${recordId}-call-1`,
>     },
>     body: JSON.stringify(payload),
>   });
>   const body = await res.json().catch(() => ({}));
>   if (res.status === 202) return body.id;
>
>   const { code = "unknown", message = res.statusText } = body.error ?? {};
>   console.error("call refused", { status: res.status, code, message, recordId });
>
>   if (code === "duplicate_call") return null; // the first request is still in flight
>   if (res.status === 429) throw new RetryLater(res.headers.get("Retry-After") ?? "5");
>   if (res.status >= 400 && res.status < 500) {
>     await alertOps(`Call for ${recordId} refused: ${res.status} ${code}: ${message}`);
>   }
>   throw new Error(`${res.status} ${code}: ${message}`);
> }
> ```

`RetryLater` and `alert_ops` (`alertOps` in Node.js) stand for your own job queue and alerting.

## Common refusals

| What you see | Why | Fix |
| :- | :- | :- |
| `400 invalid_request`: `variables["…"] is … characters, the maximum is 4096` | One variable is longer than 4,096 characters. | Shorten it, or declare it in the agent's `input_schema` as a long string, an object or an array, for up to 49,152. See [variables](https://docs.miraiminds.co/v2/calls.md#how-long-a-value-can-be). |
| `400 invalid_request`: `to must be an E.164 phone number` | The number has no `+` and country code. | Send `+91` and the 10 digits, such as `+919876543210`. |
| `402 insufficient_balance` | The wallet can't cover one minute of the call. | [Add credit](https://docs.miraiminds.co/v2/wallet.md#top-up). A [campaign](https://docs.miraiminds.co/v2/campaigns.md#pause-reasons) pauses instead, and its contacts keep their place. |
| `404 not_found` | The `agent_id` isn't in this workspace: deleted, mistyped, or from another workspace. | Check the agent id and the base URL. |
| `422 outside_calling_hours` | A call to an Indian number outside 09:00 to 21:00 IST. | Send it after 09:00 IST (`Retry-After` says when), or add the person to an [always-on campaign](https://docs.miraiminds.co/v2/campaigns.md#always-on-campaigns), which waits for its calling hours. |
| `422 do_not_call` | The number is on your [do-not-call list](https://docs.miraiminds.co/v2/dnc.md). | Expected. Don't call the number. |
| `429 rate_limited` | Requests came too fast, or 500 calls are already waiting. | Slow down and honour `Retry-After`, or send the calls through a campaign. |
| `contact_rejected` | One campaign row was refused. The message is the row's reason. | Fix the row and add it again. |

Every error code, with its fix, is on [Errors](https://docs.miraiminds.co/v2/errors.md).

## Related

> [card] [Calls](https://docs.miraiminds.co/v2/calls.md#errors)
>
> Every error `POST /v2/calls` can answer, and how long a variable can be.

> [card] [Direct calls or campaigns](https://docs.miraiminds.co/v2/calls-or-campaigns.md)
>
> When a steady flow of calls belongs in an always-on campaign.

> [card] [Errors](https://docs.miraiminds.co/v2/errors.md)
>
> The error envelope, every code, and the retry rules.

> [card] [Campaigns](https://docs.miraiminds.co/v2/campaigns.md#contacts-are-reported-row-by-row-not-rejected-as-a-batch)
>
> How a campaign reports rejected rows.


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