# Data model

> The tables of the gateway's Postgres schema and what each holds.

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

For agents: Schema sypnia_ai: projects (id, org, settings: direct_models, zero_retention_only), route_versions (project, version, toml, json, created_by, created_at, active), keys (id, project, name, prefix, hash argon2id, scopes, credits_per_day, last_used_at, revoked_at), provider_keys (project, provider, encrypted secret or role ARN + external id, zero_retention), origins, limits (scope kind+id, kind, value), limit_leases, calls (id, project, key_id, task, route_version, case_id, end_user_hash, model, provider, attempts jsonb, input/output/cached tokens, credits, status, error_code, ttft_ms, duration_ms, trace_id, created_at; partitioned by day, dropped after retention), usage_daily (project, day, case, task, key, end_user_hash, model, calls, tokens, credits), stored_bodies (call_id, object key, expires_at), cache_entries (key hash, object key, expires_at), audit (who, what, when).

The gateway keeps everything in one Postgres schema, `sypnia_ai`.

| Table                    | Holds                                                                                                                                                                                           |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `projects`               | each project's settings: whether model names are allowed directly, the zero-retention rule                                                                                                      |
| `route_versions`         | every version of a project's routes, as written, with who applied it and when                                                                                                                   |
| `keys`                   | keys: name, prefix, a slow hash of the secret (never the secret), scopes, caps, last use, revocation                                                                                            |
| `provider_keys`          | your own provider keys, encrypted, or the AWS role to assume                                                                                                                                    |
| `origins`                | sites allowed to use browser tokens                                                                                                                                                             |
| `limits`, `limit_leases` | the limits, and the leases each copy of the gateway holds                                                                                                                                       |
| `calls`                  | one row per call: task, route version, case, the person's id hashed, model, attempts, tokens, credits, result, timings, trace id. Split by day; days older than the retention are dropped whole |
| `usage_daily`            | totals per day, case, task, key, person and model, kept as long as the organization                                                                                                             |
| `stored_bodies`          | where a kept question and answer are, and when they are deleted                                                                                                                                 |
| `cache_entries`          | the response cache's index and expiry                                                                                                                                                           |
| `audit`                  | route changes, key changes, reads of kept bodies, deletions of people                                                                                                                           |

What a person wrote is never in Postgres: kept bodies and cached answers live encrypted in object storage, and the tables only point to them.
