> For the complete documentation index, see [llms.txt](https://k-ai.gitbook.io/knowledge-ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://k-ai.gitbook.io/knowledge-ai/reference/errors.md).

# Errors & status codes

## HTTP status codes

| Code | Meaning               | When you'll see it                                                                          |
| ---- | --------------------- | ------------------------------------------------------------------------------------------- |
| 200  | OK                    | Successful request, payload in `response`.                                                  |
| 201  | Created               | Resource created.                                                                           |
| 400  | Bad Request           | Invalid request body or missing required field.                                             |
| 401  | Unauthorized          | Missing or invalid credentials.                                                             |
| 403  | Forbidden             | Credentials valid but not authorised for this resource (e.g. instance not visible to user). |
| 404  | Not Found             | Resource (instance, document, conflict) does not exist.                                     |
| 409  | Conflict              | State-machine violation (e.g. trying to close an already-managed conflict).                 |
| 422  | Unprocessable Entity  | Request body validates but is semantically wrong (e.g. answer length exceeds limit).        |
| 429  | Too Many Requests     | Rate limit hit (auth: 5 logins/min/IP).                                                     |
| 500  | Internal Server Error | Unexpected server failure. Exponential backoff retry recommended.                           |
| 502  | Bad Gateway           | Upstream component (LLM router, vector store) unreachable.                                  |
| 503  | Service Unavailable   | Service in maintenance or degraded; respect the `Retry-After` header.                       |

## Error body shape

All three APIs return `{"detail": "<message>"}` on error. The success wrapper `{"response": ...}` is only present on 2xx.

```json
{
  "detail": "Instance not found"
}
```

## Per-API specifics

### Instance API — `api.kai-studio.ai`

* `401` — wrong `instance-id` or `api-key` header.
* `404` — instance unknown to the platform.

### Retrieval API — `api-retrieval.kai-studio.ai`

* `401` — token expired or revoked.
* `403` — instance access denied (group RBAC).
* `422` — query length or pagination parameter violation.

### Audit API — `api-audit.kai-studio.ai`

* `409` — conflict already managed or ignored.
* `422` — workflow-state mismatch (e.g. answering a conflict that is in `MANAGED` state).

## OAuth-specific errors

OAuth 2.1 endpoints return standard error responses defined in [RFC 6749 §5.2](https://www.rfc-editor.org/rfc/rfc6749#section-5.2):

| Error code               | Meaning                                                                                          |
| ------------------------ | ------------------------------------------------------------------------------------------------ |
| `invalid_request`        | Required parameter missing, included twice, or malformed.                                        |
| `invalid_client`         | Client authentication failed (unknown `client_id` or bad client secret).                         |
| `invalid_grant`          | Authorization code, refresh token, or resource-owner credential is invalid, expired, or revoked. |
| `unauthorized_client`    | Client is not authorised to use the requested grant type.                                        |
| `unsupported_grant_type` | The grant type is not supported by the authorisation server.                                     |
| `invalid_scope`          | Requested scope is invalid, unknown, malformed, or exceeds the granted scope.                    |

See the [OAuth 2.1](/knowledge-ai/authentication/oauth.md) page for the full authentication flow.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://k-ai.gitbook.io/knowledge-ai/reference/errors.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
