{"article":{"title":"Testing failures","breadcrumb":["Operations","Testing failures"],"body":"**What this solves**: Let you drill all kinds of failure scenarios without actually burning through your quota or waiting for a real outage.\n\nMock (drill) doesn't actually hit upstream. It makes Tare return errors that match the **shape** of a real failure, following a specified script.\n\n### Why you need it\n\nThe hardest branch to create on your own in a drill is the error branch. To really hit quota exhaustion, you'd have to spend all the money first; to really encounter an upstream failure, you can only wait for it to happen on its own, at a time you don't get to pick.\n\nAttach a fixed scenario to a key, and requests made with that key return the simulated result directly, without actually reaching upstream. Not a single token is spent, and you don't have to wait for a real outage to occur.\n\n### When to use Mock\n\n- Before launch, verify how the client handles rate limiting, arrears, and quota exhaustion.\n- Verify the error copy that support or the frontend shows to end users.\n- Verify that retry logic only retries errors that should be retried.\n- Verify that monitoring and alerts can recognize failures.\n\n### Suggested drill order\n\n1. Start with a normal Mock response (`SUCCESS`) to confirm the call path is controllable.\n2. Drill 429 and confirm the client reads `Retry-After`.\n3. Drill quota exhaustion and arrears, and confirm it doesn't blindly retry.\n4. Drill all upstreams down, and confirm both the frontend and alerts can recognize it.\n5. Drill a DLP block, and confirm sensitive content isn't still being sent upstream.\n\n### Details\n\n#### Attaching a scenario\n\nConsole path: **API Keys** → the flask icon on a key.\n\nYou can also call the API directly:\n\n```bash\ncurl -X PUT https://tare.jamerly.ai/v1/mocks/{apiKeyId} \\\n  -H \"Authorization: Bearer $TARE_KEY\" -H \"Content-Type: application/json\" \\\n  -d '{\"scenario\":\"UPSTREAM_TIMEOUT\",\"enabled\":true}'\n```\n\n> [!WARNING]\n> **The scope is only the key you name, not the whole account.** When operating with management credentials, you can only touch the keys they own. Using a dedicated key for a drill won't turn your colleagues' production traffic into fake data.\n\n#### Scenario list\n\n`GET /v1/mocks/scenarios` gives the full list; **read it from here, don't hard-code it in the client**, because the list may grow:\n\n| Scenario | What it simulates |\n|---|---|\n| `KEY_CREDIT_EXHAUSTED` | This key's own spend limit is used up |\n| `BUDGET_EXHAUSTED` | The account's monthly budget is used up |\n| `ACCOUNT_BALANCE_INSUFFICIENT` | The account balance is exhausted |\n| `RATE_LIMITED` | Requests too frequent |\n| `UPSTREAM_TIMEOUT` | Upstream never responds |\n| `UPSTREAM_ERROR` | Upstream returns 5xx |\n| `INVALID_KEY` | The credential is rejected |\n| `MODEL_NOT_FOUND` | The requested model doesn't exist |\n| `BAD_REQUEST` | Malformed request |\n| `CONTENT_FILTERED` | Blocked by content policy |\n| `SUCCESS` | Normal response, with content specified by **you** (see below) |\n\nEvery failure scenario returns an error of exactly the same shape Tare would give if it really happened. The point is to make your code take **the actual branch**, not an approximation of it.\n\n#### `SUCCESS`: a fixed response, not a failure\n\nThis is the only non-failure scenario. Set `responseBody` to the complete JSON you want; it is replayed as-is. Plain text is wrapped into a normal completion. Optionally add `delayMs` to simulate latency. Good for testing the happy path: you get a stable, predictable output instead of a real model's varying answer.\n\n#### Expiry\n\nA drill is supposed to be temporary: if you don't set `expiresAt`, by default it expires **4 hours** after being enabled, and there's no \"permanent\" option.\n\n> [!NOTE]\n> A drill nobody remembers enabling, sitting on a credential that quietly became a production key, is far worse than the hassle of turning it on again.\n\n#### What it doesn't affect\n\n- **Calls on other keys are unaffected.** A drill is a property attached to a key, not account-level.\n- **Not a single token is consumed**; a drill never actually reaches upstream.\n- **Turning it off or deleting it takes effect from the next call**; calls already in flight are unaffected.\n\n#### A drill still leaves traces, and may be billed\n\nA drill call **always writes a usage record**, marked `MOCKED`, so whichever scenario it is, it doesn't count toward your success-rate statistics (a `SUCCESS` scenario won't push it up, and a failure scenario won't pull it down).\n\nIt goes through **the same billing path as a real call**: token usage is always 0, but if the channel this model uses has a per-call minimum charge, that minimum charge is still collected. This call also has to pass the same three gates — balance, key limit, budget — as a real call. A key that has already exhausted its quota can't dodge the checks by turning on a drill and picking up a routing fee along the way.\n\n> [!WARNING]\n> **Turning the drill on and off also leaves traces.** Someone will eventually ask you to explain what happened during the period when production traffic quietly started returning fake data. See [Audit Trail](audit-trail) for details.\n\n### Next steps\n\n- To see the real meaning of each error code: read [Error codes](errors).\n- To learn how quota and budget are configured: read [Rate limits and quotas](limits).\n- To know where changes on the account are recorded: read [Audit Trail](audit-trail).\n"}}