# API reference

> The AI API: addresses, authentication, the Sypnia headers, errors and limits.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://ai.docs.sypnia.com/api/

For agents: AI API at https://ai.api.sypnia.com/v1 (self-hosted <gateway>/v1). OpenAI-compatible: /chat/completions, /embeddings, /models, /moderations. Auth Authorization: Bearer: secret keys syp_sk_… (project key, or AI keys with scopes call|read|admin; refused with an Origin header), browser tokens syp_ait_… (10 min, browser routes only), Sypnia session/PAT/OAuth tokens (people and agents; agent tokens 403 person_required for routes apply, limits, keys, provider keys). Sypnia headers: Sypnia-Case, Sypnia-End-User, Sypnia-Budget, Sypnia-Store, traceparent. Error shape {error {code, message, type, param, call_id}} (OpenAI-compatible fields + code). Codes: 400 invalid_request/tool_not_allowed/input_not_supported/context_too_long, 401 unauthorized, 402 insufficient_credits/budget_exceeded/spending_limit_reached, 403 forbidden/person_required/secret_key_in_browser/task_not_allowed, 404 not_found/task_not_found/model_not_found, 409 conflict, 413 too_large, 422 content_blocked/output_invalid, 429 rate_limited/end_user_limit (retry-after), 502 provider_key_failed, 503 provider_unavailable.

API: `https://ai.api.sypnia.com/v1` **\[Cloud]**, or your gateway's address followed by `/v1` **\[Engine]**. The model endpoints speak the same language as OpenAI's.

## Authentication

`Authorization: Bearer <key or token>`:

| Credential                           | Who uses it                                    | Can                                                                                                                                                                    |
| ------------------------------------ | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Secret key** `syp_sk_…`            | your servers                                   | the project's own secret key can do everything; a key made for AI has the scopes `call` (model calls), `read` (usage, calls, routes) or `admin` (routes, limits, keys) |
| **Browser token** `syp_ait_…`        | browsers, for one person, 10 minutes           | calls to tasks with `browser: true` only                                                                                                                               |
| **Session, personal or OAuth token** | people and agents, through the CLI, App or MCP | what the person's role allows                                                                                                                                          |

A secret key sent from a browser (the request has an `Origin` header) is refused. Tokens used by agents cannot apply routes, change limits, create keys or add provider keys: those answer `403 person_required`.

## The Sypnia headers

`Sypnia-Case`, `Sypnia-End-User`, `Sypnia-Budget`, `Sypnia-Store` and `traceparent`, described in [Chat and streaming](https://ai.docs.sypnia.com/using/chat-and-streaming). They work on every model endpoint.

## Errors

The shape is OpenAI's, with a Sypnia `code` and the call's id:

```json
{ "error": { "code": "end_user_limit", "type": "rate_limit_error", "message": "This person reached 40 requests today for allergen-answer.", "param": null, "call_id": "call_6f2c…" } }
```

| Status | Codes                                                                            |
| ------ | -------------------------------------------------------------------------------- |
| 400    | `invalid_request`, `tool_not_allowed`, `input_not_supported`, `context_too_long` |
| 401    | `unauthorized`                                                                   |
| 402    | `insufficient_credits`, `budget_exceeded`, `spending_limit_reached`              |
| 403    | `forbidden`, `person_required`, `secret_key_in_browser`, `task_not_allowed`      |
| 404    | `not_found`, `task_not_found`, `model_not_found`                                 |
| 409    | `conflict`                                                                       |
| 413    | `too_large`                                                                      |
| 422    | `content_blocked`, `output_invalid`                                              |
| 429    | `rate_limited`, `end_user_limit` (with `retry-after`)                            |
| 502    | `provider_key_failed`                                                            |
| 503    | `provider_unavailable`                                                           |

A call refused before it reached a model costs nothing. The rate limits of the API itself are in [Limits](https://ai.docs.sypnia.com/reference/limits).

- [Endpoints](/api/endpoints/): Model calls, the catalog, routes, usage, calls, limits, keys, browser tokens and the rest.
