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

# Errors, envelopes and retries

> Every code the API returns, what it means, and which ones are worth retrying.

## The two response shapes

A **collection** always returns the same five fields, whichever collection it is:

```json theme={null}
{ "object": "list", "resource": "invoices", "data": [ … ], "has_more": true, "next_cursor": "eyJ…" }
```

A **single record** returns the resource name and one object. Note that `data` is an
object here, not an array:

```json theme={null}
{ "object": "invoices", "data": { "id": "9c2a…", "status": "paid", … } }
```

An **error** is always this, and never an HTML page:

```json theme={null}
{ "error": { "code": "invalid_query", "message": "vendor is not a filter on invoices. Accepted: limit, cursor, updated_since, vendor_id, status, business_unit." } }
```

Branch on `error.code`, not on the message. The codes are stable; the messages are
written for a person reading a log and may be reworded.

## Every code

| Status | Code | What happened | Retry? |
| - | - | - | - |
| `400` | `invalid_query` | A filter was not recognised, a value was malformed, or the cursor was not one this API issued. The message says which. | No. Fix the request. |
| `400` | `invalid_id` | The id in the path is not a valid id for that resource. | No. Fix the request. |
| `401` | `missing_credential` | No key was sent, or the `Authorization` header was not in the form `Bearer <key>`. | No. Send a key. |
| `401` | `invalid_credential` | The key is unknown, or it has been revoked. | No. Issue a new key. |
| `404` | `not_found` | No record with that id. | No. |
| `404` | `unknown_resource` | There is no collection by that name. | No. Check the spelling against the reference. |
| `405` | `method_not_allowed` | The request used a method other than `GET`. The API is read-only. | No. Use `GET`. |
| `429` | | Too many requests. **Not returned today**; reserved in case a rate limit is added. | Yes, after `Retry-After`. |
| `500` | `internal_error` | Something unexpected went wrong on our side. | Yes, with backoff. |
| `502` | `read_failed` | Vensight could not read its own data. The fault is on our side. | Yes, with backoff. |
| `503` | `not_yet_provisioned` | Vensight is mid-deploy and the database is catching up. Carries `Retry-After: 30`. | Yes, after `Retry-After`. |
| `503` | `unavailable` | The API cannot reach its database right now. When this happens while checking your key, the response carries `Retry-After: 10`. | Yes, after `Retry-After`, otherwise with backoff. |

> [!NOTE]
>
> **An unknown or revoked key gives the identical answer**, so probing never confirms
> that a key used to exist. If you have just rotated a key and are seeing
> `invalid_credential`, you are almost certainly still sending the old one.

> [!WARNING]
>
> **An unknown filter is refused, not ignored.** Sending `?vendor=` where the API expects
> `?vendor_id=` returns `400` rather than quietly returning every record, so a sync job
> cannot pull unfiltered data for a month without anyone noticing.

## Which failures deserve a retry

**`429`, `500`, `502` and `503`.** Everything else is a request that will fail the same way however
many times you send it, and retrying a `401` in a loop just fills the access log.

When a response carries `Retry-After`, wait that many seconds. Otherwise back off: 1, 2, 4,
8 seconds and so on.

`503 not_yet_provisioned` is worth handling properly. It means a Vensight deploy is in
flight and the database is a few seconds behind the code. It is brief, not an outage, and
the next attempt after `Retry-After` almost always succeeds. Treating it as a hard failure
is how a nightly job appears to break on the one night someone shipped a change.

```python Python theme={null}
import time, requests

RETRY = {429, 500, 502, 503}

def get(url, **kw):
    for attempt in range(5):
        r = requests.get(url, timeout=30, **kw)
        if r.status_code not in RETRY:
            return r                                   # success, or a real refusal
        wait = int(r.headers.get("Retry-After", 2 ** attempt))
        time.sleep(wait)
    r.raise_for_status()
```

```typescript TypeScript theme={null}
const RETRY = new Set([429, 500, 502, 503]);

async function get(url: string, init: RequestInit = {}): Promise<Response> {
  let res: Response | undefined;
  for (let attempt = 0; attempt < 5; attempt++) {
    res = await fetch(url, init);
    if (!RETRY.has(res.status)) return res;           // success, or a real refusal
    const wait = Number(res.headers.get("Retry-After") ?? 2 ** attempt);
    await new Promise((r) => setTimeout(r, wait * 1000));
  }
  throw new Error(`Gave up after 5 attempts: ${res!.status}`);
}
```

```bash curl theme={null}
# --retry covers 429, 502 and 503 and honours Retry-After.
curl --retry 5 --retry-max-time 120 "$BASE/vendors" \
  -H "Authorization: Bearer $VENSIGHT_KEY"
```

## Headers on every response

| Header | |
| - | - |
| `X-Vensight-Api-Version` | `1`. The version you are talking to. See [Versioning](https://docs.vensight.ai/versioning.md). |
| `X-Response-Time-Ms` | How long Vensight spent on the request. Useful when a loader looks slow and you need to know whose end it is. |
| `Cache-Control` | `no-store`, always. Do not cache responses in a shared layer: one key's response served to another request would show data to someone who should not see it. |

On a `401` you also get `WWW-Authenticate: Bearer realm="Vensight API"`, so a standard
HTTP client can tell what kind of credential is wanted.

## Rate limits

**There is no published rate limit, and none is enforced today.** That describes the API
as it is now rather than a promise, so build as though one will arrive: keep `limit` at
200 for backfills so you make fewer requests, retry `429` as above, and prefer
`updated_since` or a webhook over polling a whole collection on a short interval.

If you expect a very high volume, [get in touch](https://docs.vensight.ai/support.md) before you build.

## Your requests are logged

Every call is recorded with the key that made it, the path, the query string, the status,
the row count, the duration and the address it came from. Calls refused for a missing or
unknown key are recorded too, without a key, since there is none to name.

> [!NOTE]
>
> **There is no screen for this log yet.** The records are being written, and the Vensight
> team can pull them on request, but nothing in the product displays them today. To audit
> what a key has been doing, [ask us](https://docs.vensight.ai/support.md).

Because the query string is recorded, **never put a credential in a URL**. The API refuses
a key sent that way for exactly this reason.


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