# Errors

Every non-2xx response from a `/v2/*` route has the same shape, the error
envelope. `code` is a value you can dispatch on, `hint` says what to do
next, and `suggestions` carries nearest-ref candidates so a mistyped ref
can be corrected in one step.

```json
{
  "code": "unknown_entity_refs",
  "message": "Unknown entity refs: make:teslla",
  "hint": "Resolve free text to refs at GET /v2/entities/resolve?q=teslla",
  "refs": ["make:teslla"],
  "suggestions": [
    {
      "invalid": "make:teslla",
      "nearest": [{ "ref": "make:tesla", "name": "Tesla" }],
      "resolve": "/v2/entities/resolve?domain=make&q=teslla"
    }
  ]
}
```

## Unknown refs are named, not guessed

A well-formed ref that the registry does not recognize always returns a 400
that names it. Suggestions are advisory and are never applied for you. You
will not get a fuzzy-matched result or an empty set for a bad ref.

## The envelope

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `code` | string | yes | Error code to branch on. Well-known codes: invalid_request, invalid_filters, invalid_ref, invalid_vin, invalid_nano_refs, version_sunset, unknown_entity_refs, unknown_entity_domain, unknown_spec_attributes, not_found, conflict, unauthorized, forbidden, rate_limited, insufficient_credits, internal_error, unavailable. New codes may be added; fall back to message and hint for codes you do not know. |
| `message` | string | yes | Readable description naming the offending input |
| `hint` | string | no | What to do next, e.g. "Resolve free text at GET /v2/entities/resolve" |
| `docs_url` | string | no | URL of a Markdown page explaining this error code and how to fix it |
| `details` | object[] | no | Field-level validation failures, one per failing path |
| `details[].path` | string | no | The failing field, e.g. "filters.makes.0" |
| `details[].message` | string | yes |  |
| `refs` | string[] | no | The offending refs or attribute ids, verbatim. Set for unknown_entity_refs, unknown_spec_attributes, and invalid_nano_refs. |
| `suggestions` | object[] | no | Nearest-ref candidates per offending input. Advisory only; the API does not apply them. |
| `suggestions[].invalid` | string | yes | The offending input, verbatim |
| `suggestions[].nearest` | object[] | yes | Best candidates, most likely first. Advisory only; the API does not apply them. |
| `suggestions[].nearest[].ref` | string | yes | A known entity ref, e.g. "make:tesla" |
| `suggestions[].nearest[].name` | string | no | Display name, e.g. "Tesla" |
| `suggestions[].resolve` | string | no | Server-relative URL of the resolve call that turns this input into refs, e.g. "/v2/entities/resolve?domain=make&q=teslla" |
| `links` | object | no | Related resources, each a server-relative path. invalid_vin carries {"feedback": "/v2/feedback"}: if you know what the vehicle is, report it there. |
| `requestId` | string | no | This request's id, the same value as the X-Request-Id response header and the id recorded on any credit debit for the request. Quote it when you report a failure or dispute a charge. Set on every error the API serves. |

The code set is **open**. New codes are added over time and are never a
breaking change. Dispatch on the codes you know and fall back on
`message` and `hint`.

## Error codes

| Code | Meaning |
| --- | --- |
| [`invalid_request`](https://cardog.app/docs/errors/invalid_request) | The request body or parameters did not match the operation's schema. |
| [`invalid_filters`](https://cardog.app/docs/errors/invalid_filters) | One or more filters used invalid ref syntax, scalar values, or ranges. |
| [`invalid_ref`](https://cardog.app/docs/errors/invalid_ref) | A path or query parameter did not match the `{domain}:{key}` ref grammar. |
| [`invalid_vin`](https://cardog.app/docs/errors/invalid_vin) | The supplied VIN failed the platform's length or character rules. |
| [`invalid_nano_refs`](https://cardog.app/docs/errors/invalid_nano_refs) | A nano filter did not match the VIN-derived nano key grammar. |
| [`version_sunset`](https://cardog.app/docs/errors/version_sunset) | The `Cardog-Version` header named a dated version that is past its support window. |
| [`unknown_entity_refs`](https://cardog.app/docs/errors/unknown_entity_refs) | The refs were well formed, but the entity registry did not recognize them. |
| [`unknown_entity_domain`](https://cardog.app/docs/errors/unknown_entity_domain) | The domain was well formed, but the entity registry does not serve it. |
| [`unknown_spec_attributes`](https://cardog.app/docs/errors/unknown_spec_attributes) | A `spec.*` filter named an attribute that is not in the current catalog. |
| [`not_found`](https://cardog.app/docs/errors/not_found) | The requested route or resource does not exist. |
| [`conflict`](https://cardog.app/docs/errors/conflict) | The record changed between the read your request was based on and the write. |
| [`unauthorized`](https://cardog.app/docs/errors/unauthorized) | The request did not carry a valid API key, session, or internal credential. |
| [`forbidden`](https://cardog.app/docs/errors/forbidden) | The credential is valid but does not grant access to the requested route group. |
| [`rate_limited`](https://cardog.app/docs/errors/rate_limited) | The credential exhausted the request limit described by the response. |
| [`insufficient_credits`](https://cardog.app/docs/errors/insufficient_credits) | A hard-stop plan has no allowance or prepaid pack balance left. |
| [`internal_error`](https://cardog.app/docs/errors/internal_error) | The server failed while processing a request that the caller cannot repair. |
| [`unavailable`](https://cardog.app/docs/errors/unavailable) | A required platform dependency was temporarily unavailable. |

Open a code for what happened, the next action, and a working corrected
request. Error envelopes link to the page's markdown twin so an agent can
fetch the recovery recipe without parsing HTML.

## HTTP statuses

| Status | When |
| --- | --- |
| 400 | Invalid request — grammar failure or unknown-but-well-formed refs, NAMED in `refs`/`details`, with nearest-ref `suggestions` where computable. Never a fuzzy fallback. |
| 401 | No valid credential (API key, session, or internal token) |
| 402 | Insufficient credits (free-tier hard stop; paid tiers bill overage instead) |
| 403 | The link is invalid or expired (`forbidden`); request `GET /v2/vin/{vin}/window-sticker` again for a fresh one |
| 404 | Resource not found |
| 409 | The record changed since it was read (`conflict`); read it again |
| 413 | The body is larger than the route accepts (`invalid_request`, with the limit in `hint`) |
| 429 | Per-minute rate limit exceeded |
| 500 | Internal error |
| 503 | Temporarily unavailable (`unavailable`); retry with backoff |

---

Previous: [Credits](https://cardog.app/docs/credits.md) (Getting started)
Next: [Versioning](https://cardog.app/docs/versioning.md) (Getting started)
