Yama // API

API Authentication

How to authenticate against the Yama chat backend API (v1).

The API uses a two-tier authentication model:

TierWhoCredentialUsed for
TenantYour backend (server-to-server)X-Api-Key + X-Api-SecretProvisioning & minting user tokens
UserAn end-user's client (chat widget)Authorization: Bearer <jwt>Acting as a user (e.g. sending messages)

1. Tenant authentication

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-KeyYour public tenant identifier (e.g. pk_…).
X-Api-SecretYour secret (e.g. sk_…). Never expose it to a browser.
The secret travels over HTTPS on each request and is verified against a bcrypt digest server-side. It is never logged (request logs redact it as [FILTERED]).

2. Mint a user token

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.

3. User authentication

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"
}

Errors

StatusWhenBody
401Missing/invalid credentials, invalid or expired JWT{ "error": "Invalid API credentials" }
404Unknown user external_id for the tenant{ "error": "Not found" }