# Error

> Errors: every refusal the API makes, as a typed class that says what to do next.

The server renders every refusal as `{"error": {"type", "message", "next_step", ...details}}`; `type` picks the class here (the same names
and HTTP statuses the API uses). Extra keys land in `details` and read as
attributes: `err.connect_url`, `err.existing_id`.

## noclick.Error

```python
class Error(Exception)
```

Base class for every NoClick platform error.

| Attribute | Type | Description |
| --- | --- | --- |
| `type` | `str` |  |
| `http_status` | `int | None` |  |
| `message` | `str` |  |
| `next_step` | `str | None` |  |
| `details` | `dict[str, Any]` |  |
| `status` |  |  |
| `request_id` | `str | None` |  |
| `attempts` | `int | None` |  |

## noclick.Offer

```python
class Offer
```

One way past a refusal for money: a link a person opens to pay, no sign-in needed.
Paying stays that person's act; hand them `url`.

| Attribute | Type | Description |
| --- | --- | --- |
| `kind` | `str` | `plan` (a plan that includes what was refused), `funds` (an amount added to the balance) or `topup` (a monthly add-on, on the older plans). |
| `label` | `str` | What it buys, in words: `the Plus plan, billed monthly`. |
| `price_usd` | `float` |  |
| `url` | `str` |  |
| `expires_at` | `Any` | When the link stops working; refused again before then, the same link comes back. |
| `operation` | `Operation` | The `payment` operation the link settles: `wait()` returns once it's paid, and raises `OperationExpired` if it never is. |

## noclick.InvalidRequest

```python
class InvalidRequest(Error)
```

The request is malformed or a value is out of range; `field` names the argument when there is one.

Error type `invalid_request`, HTTP 400.

## noclick.Unauthenticated

```python
class Unauthenticated(Error)
```

No key was sent, or the key or session token isn't valid (revoked, expired, or not a platform key).

Error type `unauthenticated`, HTTP 401.

## noclick.PaymentRequired

```python
class PaymentRequired
```

Your account can't pay for this: `balance_usd` is what's left and
`required_usd` what the call needs, in US dollars. `offers` are links a
person opens to add funds or change plan; retry once one is paid. A model
provider's account out of funds (your own key) raises it too, with `reason`
`"provider_out_of_funds"`. A deployed app's paid call names the app in
`project` and `project_id` (invite-only beta):

```python
except noclick.PaymentRequired as short:
    for offer in short.offers:
        print(offer.label, offer.price_usd, offer.url)
```

Error type `payment_required`, HTTP 402.

| Attribute | Type | Description |
| --- | --- | --- |
| `balance_usd` | `float | None` |  |
| `required_usd` | `float | None` |  |

## noclick.PlanRequired

```python
class PlanRequired
```

The account's plan doesn't allow this: plans cap some resources. `offers`
are links to the plans that do.

Error type `plan_required`, HTTP 402.

## noclick.PriceExceeded

```python
class PriceExceeded(Error)
```

It would cost more than the ceiling you set (`max_monthly_usd` on `PhoneNumber.buy`).

Error type `price_exceeded`, HTTP 402.

## noclick.ApprovalRequired

```python
class ApprovalRequired(Error)
```

Policy wants a person to approve this call first. A `Human.approve`
request is already out; wait on it, then retry with `approval_id=`:

```python
except noclick.ApprovalRequired as pending:
    if pending.operation.wait():
        noclick.run("gmail.send_email_message", args, approval_id=pending.approval_id)
```

`approve_url` is set only when the approver is the one the call is made for. `operation` is
`None` only when a user's session, or a key pinned to them, makes a call someone else approves.

A call NoClick holds for the account's owner (a purchase, a deletion that can't be undone, a
change from an agent or a connected app) waits on the owner instead, who approves it from the link
NoClick sends them (`sent_to` says where). NoClick makes the call itself once they do: wait on
`operation` for its answer, and don't retry it:

```python
except noclick.ApprovalRequired as held:
    print(held.operation.wait()["response"])
```

Error type `approval_required`, HTTP 402.

| Attribute | Type | Description |
| --- | --- | --- |
| `approval_id` | `str | None` |  |
| `approve_url` | `str | None` | The page where the approver answers. |
| `operation` | `Operation | None` | The approval as an operation: `.wait()` returns `True` once approved. `None` when the call's credential can't read it: a user's session, or a key pinned to them, for a call someone else approves.  A call NoClick holds for the account's owner (a purchase, a deletion that can't be undone, a raised limit, a change from an agent or a connected app) is the held call itself instead (`operation_id`): NoClick makes the call once they approve, so there's nothing to retry, and `.wait()` returns `{"status", "response"}`, the call's HTTP status and its answer. It raises `noclick.PolicyDenied` if they decline, and `noclick.Expired` if nobody answers in time. |

## noclick.SpendCapExceeded

```python
class SpendCapExceeded(Error)
```

A monthly spend cap (`scope`: key, user, agent, ...) is used up. A deployed app's paid
call names the app in `project` and `project_id`, with `scope` `project` when it's
the app's own `budget_usd_per_month`.

Error type `spend_cap_exceeded`, HTTP 402.

| Attribute | Type | Description |
| --- | --- | --- |
| `cap` | `float | None` |  |
| `spent` | `float | None` |  |
| `scope` | `str | None` |  |

## noclick.SpendingPaused

```python
class SpendingPaused(Error)
```

You paused this user's spending (`user.pause_spending()`), so nothing that costs
money runs for them until `user.resume_spending()`. `message` and `next_step`
are for you; `user_message` and `action` (a `(label, url)` pair, or `None`) are
what you asked NoClick to tell the user, to show them as they are; `since` is when
you paused them:

```python
except noclick.SpendingPaused as paused:
    show_banner(paused.user_message, paused.action)
```

Error type `spending_paused`, HTTP 402.

| Attribute | Type | Description |
| --- | --- | --- |
| `user_message` | `str | None` |  |
| `action` | `tuple[str, str] | None` |  |
| `since` | `Any` |  |

## noclick.PermissionDenied

```python
class PermissionDenied(Error)
```

The key or session lacks the scope, or the user it acts for can't do this (another user's object, a suspended user).

Error type `permission_denied`, HTTP 403.

## noclick.PolicyDenied

```python
class PolicyDenied(Error)
```

Your policy (`noclick.Policy`) forbids this tool.

Error type `policy_denied`, HTTP 403.

## noclick.NotFound

```python
class NotFound(Error)
```

Nothing by that id or name in this account, or owned by the user the call acts for.

Error type `not_found`, HTTP 404.

## noclick.Conflict

```python
class Conflict(Error)
```

It already exists (`existing_id` names it), or another call holds it, like a conversation mid-turn.
An edit of a workflow's graph checked against a version it has moved on from (`if_version`) carries the
workflow as it stands: its `version` and `graph` (a `noclick.WorkflowGraph`), to decide again from.

Error type `conflict`, HTTP 409.

| Attribute | Type | Description |
| --- | --- | --- |
| `graph` | `Any` | The workflow's graph as it stands, on a refused edit of it (`None` on any other conflict). |
| `existing_id` | `str | None` |  |
| `version` | `int | None` | The version kept, on a refused edit of a workflow's graph or of your channel sections. |

## noclick.NotAvailable

```python
class NotAvailable(Error)
```

Not available here: a feature the account doesn't have yet (phone numbers), or a sandbox that has stopped.

Error type `not_available`, HTTP 409.

## noclick.ActionRequired

```python
class ActionRequired(Error)
```

Something has to be set up first, such as an agent answering a number before it can place calls.

Error type `action_required`, HTTP 409.

## noclick.AnswerRequired

```python
class AnswerRequired(Error)
```

A workflow build waits on an answer, and `question` (a `BuildQuestion`) says what. Answer it with
`build.answer(...)` where `question.answerable_from_code`; otherwise send a person to
`question.answer_url`. Then `build.wait()` again: it waits through a question it has raised.

Error type `answer_required`.

| Attribute | Type | Description |
| --- | --- | --- |
| `question` | `Any` |  |

## noclick.NeedsConnection

```python
class NeedsConnection
```

The connection has no account connected yet; send the person `connect_url`.

Error type `needs_connection`, HTTP 424.

## noclick.CredentialDisconnected

```python
class CredentialDisconnected
```

The connection's account was revoked or stopped working; send the person
`connect_url` to reconnect it (same name).

Error type `credential_disconnected`, HTTP 424.

## noclick.QuotaExceeded

```python
class QuotaExceeded(Error)
```

An account limit is reached (live sandboxes, background commands, inboxes); retrying later won't help.

Error type `quota_exceeded`, HTTP 429.

## noclick.PlanLimitReached

```python
class PlanLimitReached(Error)
```

An agent's turn its model connection's Claude or ChatGPT plan turned down at its limit: `connection`,
`window` (`five_hour`, `weekly`...), when it's back (`resets_at`) and what the agent did (`then`: it
`switched` to another connection and carried on, or is `waiting_until` the reset, or `asked` the owner to
allow a paid key).

Error type `plan_limit_reached`, HTTP 429.

| Attribute | Type | Description |
| --- | --- | --- |
| `connection` | `str | None` |  |
| `window` | `str | None` |  |
| `resets_at` | `str | None` |  |
| `then` | `dict[str, Any] | None` |  |

## noclick.RateLimited

```python
class RateLimited(Error)
```

Too many requests, or a send cap reached (emails, inbox replies); `retry_after` says when to try again.

Error type `rate_limited`, HTTP 429.

## noclick.UpstreamError

```python
class UpstreamError(Error)
```

A service NoClick relays to refused the call or failed. A refusal, such as an integration's
service answering a run with an error, comes in its own words, its HTTP status in
`upstream_status`, and answers 424: it isn't retried, since sending the same call again won't
help. A failure (a model's provider down, a service that didn't answer) answers 503 and is
retried; once retries run out, retrying in a moment usually works. Where it matters, as for a
database's statements, `applied` says whether the call took effect:

```python
except noclick.UpstreamError as err:
    if err.applied is False:  # it didn't run, so sending it again is safe
        db.execute(sql, params)
```

Error type `upstream_error`, HTTP 503.

| Attribute | Type | Description |
| --- | --- | --- |
| `applied` | `bool | None` | `False` when NoClick knows the call didn't take effect (a read, or a write the service never ran), so sending it again is safe; `True` when it did; `None` when NoClick can't tell, as for a write a database never answered (the message says so): check before sending it again. |
| `upstream_attempts` | `int | None` | How many times NoClick sent the call to the service before giving up. |

## noclick.RequestTimeout

```python
class RequestTimeout(Error, TimeoutError)
```

The work outlasted what one request may wait (about 90 seconds); it answers 503. The client
doesn't retry it, since the work may still be going on: an agent's turn goes on
and lands in its conversation (`operation_id` and `conversation` say where).

Error type `request_timeout`, HTTP 503.

## noclick.ServerError

```python
class ServerError(Error)
```

A 5xx the server could not describe as a platform error.

Error type `server_error`.

## noclick.APIConnectionError

```python
class APIConnectionError(Error)
```

The API could not be reached, even after retries.

Error type `connection_error`.

## noclick.OperationFailed

```python
class OperationFailed(Error)
```

An operation finished `failed` without a more specific error type.

Error type `operation_failed`.

## noclick.OperationCanceled

```python
class OperationCanceled(Error)
```

The operation was canceled before it finished.

Error type `operation_canceled`.

## noclick.Expired

```python
class Expired(Error)
```

A request or operation expired before anyone acted on it.

Error type `expired`, HTTP 410.

## noclick.OperationTimeout

```python
class OperationTimeout(Error, TimeoutError)
```

`Operation.wait(timeout=...)` ran out before the operation finished.

Error type `operation_timeout`.

## noclick.WebhookSignatureError

```python
class WebhookSignatureError(Error)
```

A webhook delivery's `NoClick-Signature` doesn't match its body, or its timestamp is too old.
Raised by `Webhook.verify` in your receiver; answer it with a 400 and drop the delivery.

Error type `webhook_signature_invalid`.

## noclick.OperationExpired

Another name for `Expired`.
