How to authenticate against the Yama chat backend API (v1).
The API uses a two-tier authentication model:
| Tier | Who | Credential | Used for |
|---|---|---|---|
| Tenant | Your backend (server-to-server) | X-Api-Key + X-Api-Secret | Provisioning & minting user tokens |
| User | An end-user's client (chat widget) | Authorization: Bearer <jwt> | Acting as a user (e.g. sending messages) |
Server-to-server calls are authenticated with your tenant API key and secret, sent as headers. The secret is shown only once, when the tenant is created in the admin back-office — store it securely.
| X-Api-Key | Your public tenant identifier (e.g. pk_…). |
|---|---|
| X-Api-Secret | Your secret (e.g. sk_…). Never expose it to a browser. |
[FILTERED]).Your backend exchanges its tenant credentials for a short-lived JWT scoped to one of your users (identified by the external_id you assigned). The end-user's client then uses this token — it never sees your tenant secret.
POST /api/v1/users/{external_id}/token
# Request curl -X POST https://yama.example.com/api/v1/users/ext-alice/token \ -H "X-Api-Key: pk_xxx" \ -H "X-Api-Secret: sk_xxx" # 201 Created { "token": "eyJhbGciOiJIUzI1Ni␣...", "user": { "id": "6b3e9a1c-8d2f-4f7a-9c1e-2a4b6d8e0f12", "external_id": "ext-alice", "display_name": "Alice" } }
The JWT (HS256) carries the user and tenant ids and expires after 24 hours. Mint a fresh one when it expires.
The end-user's client sends the JWT as a bearer token on every call.
GET /api/v1/me — returns the current user (useful to verify a token).
# Request curl https://yama.example.com/api/v1/me \ -H "Authorization: Bearer eyJhbGciOiJIUzI1Ni␣..." # 200 OK { "id": "6b3e9a1c-8d2f-4f7a-9c1e-2a4b6d8e0f12", "external_id": "ext-alice", "display_name": "Alice", "tenant_id": 7, "status": "connected" }
| Status | When | Body |
|---|---|---|
401 | Missing/invalid credentials, invalid or expired JWT | { "error": "Invalid API credentials" } |
404 | Unknown user external_id for the tenant | { "error": "Not found" } |