API · Sessions

Start a session

Start a live avatar for one visitor. Pick the mode, and optionally another face, voice or look for this session only; the agent's saved settings stay as they are.

Request

POSThttps://talk.selviaai.com/v1/sessions

Needs a key with the sessions permission.

FieldTypeDescription
agent_idinteger, requiredThe agent to start. List yours with GET /v1/agent/list.
modeconversation | renderDefault conversation. render: your own agent does the talking (render mode).
avatar_idstringAnother face for this session, e.g. face12. See the catalog.
voice_idstringAnother voice for this session. Premium voices need a paid account.
lookobjectStudio look for this session, laid over the agent's: backdrop (a backdrop id, or null for plain), cameras (any of far, mid, close), camera (start on far, mid, close or auto), face_light (0.5 to 1.5).
turn_patienceintegerHow long the agent waits after the visitor pauses, for this session: 1 (quick) to 5 (patient), 3 by default. Conversation mode only.
varsobjectDynamic variables for this session: name to value (text, number or true/false), e.g. {"name": "John"}. They fill the agent's dynamic instructions, reach your data handoffs, and one of them can be the greeting (below). Conversation mode only.
external_user_idstringYour own id for the visitor, at most 128 characters. The agent remembers the visitor by it; given back, never shown to the agent (below).
external_session_idstringYour own id for this session, e.g. a cart or ticket id. At most 128 characters.
messagesarrayUp to 20 messages to the agent's AI: facts or instructions it didn't hear from the visitor (kept for the whole call by default), and optionally one exact greeting for this session. Conversation mode only.

Unknown fields are refused, so a typo answers 422 instead of being ignored.

curl -X POST https://talk.selviaai.com/v1/sessions \
  -H "Authorization: Bearer $SELVIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": 7,
    "mode": "conversation",
    "avatar_id": "face12",
    "look": { "backdrop": "library", "camera": "mid", "face_light": 1.1 }
  }'

Dynamic variables and the greeting

Pass what you know about the visitor in vars. Names use letters, digits and _, start with a letter and are at most 40 characters; at most 30 values, 2,000 characters each, 16 KB in all. Sent with your key, they count as verified, so they also unlock verified-only instructions. A bad name or a value that is too long answers 422 invalid_vars.

The greeting is the first thing the agent says, word for word. To set it per session, save the variable's name on the agent once, then pass it with each session:

PATCH /v1/agent/7     {"greeting_variable": "greeting"}

POST  /v1/sessions    {"agent_id": 7,
                       "vars": {"name": "John", "greeting": "Hi John, good to see you again!"}}

A session that doesn't pass it opens with the agent's welcome_message, or in the agent's own words when that is empty. "greeting_variable": "" turns it off. Keep it short: the visitor waits for it to finish before they can talk. It must be in a language the agent speaks: one in another script (say Arabic for an English-only agent) is not used, and the session opens as if it hadn't been passed.

Your own ids

Start a session with external_user_id and external_session_id to find it again in your own terms. They are stored with the session and come back in GET /v1/sessions/{id}, the call record, the conversation list (GET /v1/reports/conversations?external_user_id=…) and your data handoffs. The agent never sees them. An id longer than 128 characters answers 422 invalid_external_id.

The agent also remembers a visitor by external_user_id. With it, the agent recognizes the visitor by your id instead of working it out itself and doesn't ask for their name, and from their next session it remembers what was said before (the memory is updated shortly after each session ends). The first session with a new id starts as a new visitor. Memory is kept per account: the same id reaches the same memory through any of your agents. For separate memory per agent, make the id unique per agent, e.g. agent42:u_88. Conversation mode only. Ids sent with your key are trusted. A web page can also pass the id unsigned, but anyone can set that in their own browser and would then talk to an agent that remembers that visitor: sign it (signed values) whenever the memory may hold anything private.

The voice must suit the face

As in the console, a session can't pair a man's face with a woman's voice or the other way round: changing the face to one whose voice no longer fits answers 422 voice_face_mismatch. Pass a voice_id that suits the new face.

Response

FieldDescription
session_idUse it to check, stop or direct the session.
player_urlThe page your visitor watches. It works for this session only.
ws_urlRender mode only. Where your server streams the avatar's speech. It contains a secret token: keep it on your server.
max_session_secondsThe session ends at this age (300 on the free plan). null: it runs until you stop it.
external_user_id, …When you passed your own ids: external_user_id, external_session_id and whether each is verified (true when sent with your key).

Conversation · 201

{
  "session_id": "93d59ff0-3708-4cb8-bf1f-0b955b8e6a4b",
  "status": "active",
  "mode": "conversation",
  "agent_id": 7,
  "player_url": "https://…selviaai.com:10000/?…&sid=93d59ff0-3708-4cb8-bf1f-0b955b8e6a4b",
  "max_session_seconds": null,
  "created_at": "2026-10-17T14:41:55Z"
}

Render mode · 201

{
  "session_id": "ce681d63-47de-4ba2-ad5b-cf008ea50be5",
  "status": "active",
  "mode": "render",
  "agent_id": 7,
  "player_url": "https://…selviaai.com:10000/render.html?sid=ce681d63-…",
  "ws_url": "wss://…selviaai.com/ws/render/1?token=…",
  "max_session_seconds": null,
  "created_at": "2026-10-17T14:41:45Z"
}

When an avatar has to start

If no avatar is free right now, one starts for you and the answer is 202 instead of 201. No session exists yet and nothing is billed. Call POST /v1/sessions again after retry_after seconds (also in the Retry-After header). It is usually ready within 90 seconds.

Starting · 202

{
  "status": "starting",
  "message": "Starting an avatar for you. Try again in about 90 seconds.",
  "retry_after": 15,
  "eta_seconds": 90
}
Check the status code before you read session_id: a 202 has none.

Show it to the visitor

HTML

<!-- conversation: the visitor talks to the avatar -->
<iframe src="PLAYER_URL" allow="microphone; autoplay; fullscreen"
        style="width:100%; aspect-ratio:16/9; border:0"></iframe>

<!-- render mode: no microphone needed -->
<iframe src="PLAYER_URL" allow="autoplay; fullscreen"
        style="width:100%; aspect-ratio:16/9; border:0"></iframe>
The visitor hears the avatar from the player. Browsers may ask for one tap before they play sound; the player shows a play button when that happens. Open the page within about 90 seconds of starting the session.

Errors

StatuscodeMeaning
402insufficient_balanceA paid account with no balance left. Top up in the console.
402free_minutes_exhaustedA free account used its 60 minutes this month.
402free_concurrencyA free account already has a session running.
402paid_featureA premium voice on a free account.
404agent_not_foundNo agent with this id in your account.
409agent_buildingThe agent's knowledge is being built (conversation mode). Try again in a few minutes.
409concurrency_limitThe agent already has as many sessions as its concurrency_limit allows, usually because your own earlier session is still running. Stop it, then start again.
422voice_face_mismatchThe voice doesn't suit the face.
422unknown_avatar / invalid_lookA face, backdrop or camera that doesn't exist.
422invalid_varsA dynamic variable with a bad name or a value that is too long, or vars on a render session.
422invalid_external_idexternal_user_id or external_session_id longer than 128 characters, or not text.
422invalid_messagesA message breaks a rule (empty, over 2,000 characters, two exact ones, an unknown field), or messages on a render session.
503messages_unavailableMessages can't be taken by the avatar host right now. No session was started; try again shortly.
503no_capacityEvery avatar is in a session and none can start. Try again shortly, after the Retry-After header's seconds when it is there.

The body is {"detail": {"code": "…", "message": "…"}}. See Errors.