> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.rydhm.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.rydhm.ai/_mcp/server.

# Start a voice or text session with the expert in your app

POST https://api.rydhm.ai/v1/engine/sessions
Content-Type: application/json

Returns a LiveKit URL and token; the expert joins the room. Voice is billed as a web voice call, text like chat (per token); both use credits and the concurrent-call cap. A text session’s token cannot publish audio. The page’s client tools and the session’s guide come back too.

A publishable key (Authorization: Bearer rydhm_pk_…), from one of the key’s allowed websites: the Origin header must be on its list. Never a secret API key (401 secret_key_not_allowed). Rate limited per visitor and per key.

Reference: https://docs.rydhm.ai/api-reference/engine/start-session

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Body (application/json)

This endpoint expects an EngineSessionRequest.

- `mode` (enum, required) — voice: talk (the microphone and the expert’s voice). text: type, with no audio either way, billed like chat. One of the bubble’s modes (400 mode_not_available otherwise).
  - Allowed values: `voice`, `text`
- `user` (EngineUser, optional) — Who the page’s user is. id with hash (hex HMAC-SHA256 of id under your workspace’s user-signing secret, computed on your server) is a signed user; id alone, or anonymousId, is stored as anon_ and the id.
- `context` (map from string to any, optional) — Your app’s JSON context (at most 4 KB).
- `guideId` (string, optional) — Start (or resume) this guide.
- `language` (string, optional) — One of the expert’s languages (400 otherwise).
- `page` (EngineSessionRequestPage, optional)
- `tools` (list of map from string to any, optional) — Custom tools the page registered: \{ name (2–41 lowercase letters, digits, \_), description, parameters (a JSON Schema object, at most 4 KB) }.
- `preview` (string, optional) — A preview or teach token (rydhm_pv_…): needed while the coach is in testing.

## Response

### 201

OK

- `sessionId` (string, required) — A UUID.
- `livekit` (EngineSessionLivekit, required)
- `expert` (map from string to any, required) — As in bootstrap.
- `clientTools` (list of map from string to any, required)
- `pageMap` (list of map from string to any, required)
- `guide` (map from string to any, optional, nullable)

## Errors

### 400 Bad Request Error

Not valid (the message says what), or mode_not_available: the expert does not offer that mode.

- `statusCode` (integer, required)
- `message` (string, required)
- `error` (string, optional) — A stable code such as insufficient_scope, expert_not_allowed, rate_limited, plan_limit, payment_required.
- `code` (string, optional) — The stable code on the refusals that carry it here instead of in `error`: stale_edit (409 on an expert save).
- `requestId` (string, optional) — The X-Request-Id of the call, to quote to support.
- `upgradeHint` (ErrorUpgradeHint, optional) — On 402 payment_required and 403 plan_limit: what fixes it.
- `requiredScopes` (list of string, optional) — On 403 insufficient_scope: what the route needs.
- `missingScopes` (list of string, optional)
- `retryAfterSeconds` (integer, optional) — On 429: how long to wait.
- `retryAt` (datetime, optional, nullable)
- `timeZone` (string, optional, nullable)
- `localTime` (string, optional, nullable)
- `state` (string, optional, nullable)
- `exceptionsAllowed` (boolean, optional) — On 400 outside_calling_hours: whether `callingHoursException` may be sent.

### 401 Unauthorized Error

The publishable key is missing, not valid or revoked (invalid_publishable_key), or a secret API key was sent (secret_key_not_allowed).

- `statusCode` (integer, required)
- `message` (string, required)
- `error` (string, optional) — A stable code such as insufficient_scope, expert_not_allowed, rate_limited, plan_limit, payment_required.
- `code` (string, optional) — The stable code on the refusals that carry it here instead of in `error`: stale_edit (409 on an expert save).
- `requestId` (string, optional) — The X-Request-Id of the call, to quote to support.
- `upgradeHint` (ErrorUpgradeHint, optional) — On 402 payment_required and 403 plan_limit: what fixes it.
- `requiredScopes` (list of string, optional) — On 403 insufficient_scope: what the route needs.
- `missingScopes` (list of string, optional)
- `retryAfterSeconds` (integer, optional) — On 429: how long to wait.
- `retryAt` (datetime, optional, nullable)
- `timeZone` (string, optional, nullable)
- `localTime` (string, optional, nullable)
- `state` (string, optional, nullable)
- `exceptionsAllowed` (boolean, optional) — On 400 outside_calling_hours: whether `callingHoursException` may be sent.

### 402 Payment Required Error

payment_required: the workspace is out of credits.

- `statusCode` (integer, required)
- `message` (string, required)
- `error` (string, optional) — A stable code such as insufficient_scope, expert_not_allowed, rate_limited, plan_limit, payment_required.
- `code` (string, optional) — The stable code on the refusals that carry it here instead of in `error`: stale_edit (409 on an expert save).
- `requestId` (string, optional) — The X-Request-Id of the call, to quote to support.
- `upgradeHint` (ErrorUpgradeHint, optional) — On 402 payment_required and 403 plan_limit: what fixes it.
- `requiredScopes` (list of string, optional) — On 403 insufficient_scope: what the route needs.
- `missingScopes` (list of string, optional)
- `retryAfterSeconds` (integer, optional) — On 429: how long to wait.
- `retryAt` (datetime, optional, nullable)
- `timeZone` (string, optional, nullable)
- `localTime` (string, optional, nullable)
- `state` (string, optional, nullable)
- `exceptionsAllowed` (boolean, optional) — On 400 outside_calling_hours: whether `callingHoursException` may be sent.

### 403 Forbidden Error

coach_testing: the coach is in testing and the request has no valid preview token.

- `statusCode` (integer, required)
- `message` (string, required)
- `error` (string, optional) — A stable code such as insufficient_scope, expert_not_allowed, rate_limited, plan_limit, payment_required.
- `code` (string, optional) — The stable code on the refusals that carry it here instead of in `error`: stale_edit (409 on an expert save).
- `requestId` (string, optional) — The X-Request-Id of the call, to quote to support.
- `upgradeHint` (ErrorUpgradeHint, optional) — On 402 payment_required and 403 plan_limit: what fixes it.
- `requiredScopes` (list of string, optional) — On 403 insufficient_scope: what the route needs.
- `missingScopes` (list of string, optional)
- `retryAfterSeconds` (integer, optional) — On 429: how long to wait.
- `retryAt` (datetime, optional, nullable)
- `timeZone` (string, optional, nullable)
- `localTime` (string, optional, nullable)
- `state` (string, optional, nullable)
- `exceptionsAllowed` (boolean, optional) — On 400 outside_calling_hours: whether `callingHoursException` may be sent.

### 429 Too Many Requests Error

Rate limited (per visitor and per key); wait Retry-After seconds.

- `statusCode` (integer, required)
- `message` (string, required)
- `error` (string, optional) — A stable code such as insufficient_scope, expert_not_allowed, rate_limited, plan_limit, payment_required.
- `code` (string, optional) — The stable code on the refusals that carry it here instead of in `error`: stale_edit (409 on an expert save).
- `requestId` (string, optional) — The X-Request-Id of the call, to quote to support.
- `upgradeHint` (ErrorUpgradeHint, optional) — On 402 payment_required and 403 plan_limit: what fixes it.
- `requiredScopes` (list of string, optional) — On 403 insufficient_scope: what the route needs.
- `missingScopes` (list of string, optional)
- `retryAfterSeconds` (integer, optional) — On 429: how long to wait.
- `retryAt` (datetime, optional, nullable)
- `timeZone` (string, optional, nullable)
- `localTime` (string, optional, nullable)
- `state` (string, optional, nullable)
- `exceptionsAllowed` (boolean, optional) — On 400 outside_calling_hours: whether `callingHoursException` may be sent.

## Types

### EngineUser

Who the page’s user is. id with hash (hex HMAC-SHA256 of id under your workspace’s user-signing secret, computed on your server) is a signed user; id alone, or anonymousId, is stored as anon_ and the id.

- `id` (string, optional)
- `hash` (string, optional)
- `anonymousId` (string, optional)
- `name` (string, optional)
- `traits` (map from string to any, optional) — plan, role, company… (at most 4 KB); used by audiences.

### EngineSessionRequestPage

- `url` (string, optional)
- `path` (string, optional)
- `title` (string, optional)

### EngineSessionLivekit

- `url` (string, required)
- `token` (string, required)

### ErrorUpgradeHint

On 402 payment_required and 403 plan_limit: what fixes it.

- `action` (enum, optional)
  - Allowed values: `top_up`, `upgrade`, `contact`
- `planCode` (string, optional) — The smallest plan that allows it, when action is upgrade.
- `href` (string, optional) — Where to go in the app.

## Examples

**Request**

```json
{
  "mode": "voice"
}
```

**Response**

```json
{
  "sessionId": "string",
  "livekit": {
    "url": "string",
    "token": "string"
  },
  "expert": {},
  "clientTools": [
    {}
  ],
  "pageMap": [
    {}
  ],
  "guide": {}
}
```

**SDK Code**

```python
import requests

url = "https://api.rydhm.ai/v1/engine/sessions"

payload = { "mode": "voice" }
headers = {
    "Authorization": "Bearer <apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.rydhm.ai/v1/engine/sessions';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <apiKey>', 'Content-Type': 'application/json'},
  body: '{"mode":"voice"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```