# Hosted API errors

Source: https://orbitals.principled.app/docs/hosted-api/errors/

Errors come back in this envelope:

```json
{
  "error": "validation_error",
  "message": "Validation error, check the details for more information.",
  "details": [
    {"field": "conversation", "message": "Field required", "type": "missing"}
  ]
}
```

`error` is the code to branch on. `message` is for humans and is omitted for some errors, so `{"error": "unauthorized"}` is a complete body. `details` comes only with `validation_error`, one entry per invalid field, with `field` as a dotted path into the body.

| Status | `error`                       | Meaning                                                                                                                                                                                                         |
| ------ | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400`  | `bad_request`                 | A batch sends both `ai_service_description` and `ai_service_descriptions`, or `ai_service_descriptions` does not match `conversations` in length.                                                               |
| `400`  | `bad_request`                 | ScopeGuard-2 `output_fields` contains an unknown name.                                                                                                                                                          |
| `400`  | `bad_request`                 | Empty `conversation` on ClaimExtractor `extract-conversation`.                                                                                                                                                  |
| `401`  | `unauthorized`                | No `X-API-Key`, or a key that matches no active key: wrong, truncated or revoked.                                                                                                                               |
| `404`  | `not_found`                   | `model` is not a served model (`The specified model was not found.`).                                                                                                                                           |
| `410`  | `scope_guard_v1_deprecated`   | A call to the retired ScopeGuard-1 endpoints (`/orbitals/scope-guard/...`). See [What happened to ScopeGuard-1?](https://orbitals.principled.app/docs/faqs/general/hosted-api/#what-happened-to-scopeguard-v1). |
| `422`  | `validation_error`            | The body does not fit the schema, or `Content-Type: application/json` is missing. See `details`.                                                                                                                |
| `422`  | `api_ai_service_not_provided` | ScopeGuard-2 called with no `ai_service_description`.                                                                                                                                                           |
| `500`  | `internal_server_error`       | Something failed on our side.                                                                                                                                                                                   |

A `5xx` can also arrive without the envelope, as `{"detail": "..."}` or as plain text. When you write to <orbitals@principled-intelligence.com> about an error, quote the `X-Request-ID` header of the response, when present.

From Python, sync clients raise `requests.HTTPError`, with the envelope in `err.response.json()`; async clients raise `aiohttp.ClientResponseError`, without the body.
