# How it works

> From your app's call to the model's answer, and the record that says what it cost.

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

For agents: Call path: app → POST https://ai.api.sypnia.com/v1/chat/completions (model: "task:<name>" or a catalog id; headers Sypnia-Case, Sypnia-End-User) → key check → route resolved (model, fallbacks, params, safety) → limits checked (project, key, case, end user, task) → estimate reserved from credits (max output tokens) → redaction/moderation → provider (OpenRouter or Bedrock), stream back → actual usage charged, reservation released → span exported to Telemetry (gen_ai.* attributes + sypnia.case, credits) → call record (metadata 90 days; bodies only if opted in).

### 1. Your app asks for a task

Your server calls `POST https://ai.api.sypnia.com/v1/chat/completions` with `"model": "task:write"` (or the id of a model), the messages, and two headers that say who and what: `Sypnia-Case: publish-bread-of-the-day` and, when a person of your app is behind it, `Sypnia-End-User`.

### 2. The route decides

The gateway checks the key and reads the project's route for `write`: which model, which fallbacks, the instructions the route always adds, the safety options and the limits.

### 3. Limits and credits are checked first

Requests and tokens per minute, and the caps in credits of the project, the key, the case and the person, are checked. The most the call can cost (its input plus its longest possible answer) is reserved from your credits. If any check fails, the call stops here with a clear error and costs nothing.

### 4. The provider answers

Redaction and content checks run if the route has them. The call goes to the model through OpenRouter or Amazon Bedrock, and the answer streams back to your app as it is written. If the model fails or is too slow, the next model of the route takes over.

### 5. It is charged and recorded

The real tokens are priced and charged, the rest of the reservation goes back to your balance, and the call becomes a span in the trace of its use case in Telemetry: model, tokens, time, cost in credits. What was asked and answered is not kept unless you turned that on.

## Where things live

| Thing                              | Where                                                                                                     |
| ---------------------------------- | --------------------------------------------------------------------------------------------------------- |
| The API                            | `https://ai.api.sypnia.com/v1` **\[Cloud]**, or your gateway's address **\[Engine]**                      |
| The MCP server                     | `https://mcp.ai.sypnia.com` **\[Cloud]**, or `<your gateway>/mcp` **\[Engine]**                           |
| The console                        | `ai.app.sypnia.com`, and the AI panel of each project in [App](https://app.docs.sypnia.com/) **\[Cloud]** |
| Routes, keys, limits, call records | the gateway's Postgres                                                                                    |
| What was asked and answered        | nowhere, unless a route turns it on; then encrypted in object storage for the days you chose              |
| Traces                             | your project's [Telemetry](https://telemetry.docs.sypnia.com/), or any OpenTelemetry endpoint             |
