Skip to content

Authentication

The API uses two different kinds of credentials, scoped very differently on purpose.

Secret keyParticipant token
Formatsk_...participant_token returned by POST /v1/sessions
Lives inYour server onlyYour client (browser / mobile / desktop)
ScopeFull account accessOne LiveKit room, until expiry
Used forEvery REST call (Authorization: Bearer sk_...)Joining the session’s LiveKit room
Can create sessions?YesNo
Can spend money?YesNo

Your secret key authenticates every REST call:

Terminal window
curl https://api.2wai.ai/v1/sessions \
-H "Authorization: Bearer sk_live_..."

Keys come in two prefixes, sk_test_... and sk_live_....

Keys are issued in the developer portal at 2wai.ai/developers. Rotation and revocation are self-serve there too: create the new key, deploy it to your server, then revoke the old one.

Participant tokens (the mint-proxy pattern)

Section titled “Participant tokens (the mint-proxy pattern)”

A participant_token is minted per-session by POST /v1/sessions and is only useful for joining that one session’s LiveKit room. It can’t call any REST endpoint. That’s what makes it safe to hand to a client:

{
"session_id": "ses_...",
"transport": "livekit",
"livekit_url": "wss://...",
"room_name": "...",
"participant_token": "eyJhbGciOi...",
"agent_identity": "viewer-...",
"expires_at": null,
"chat": { "send_topic": "lk.chat", "format": "text", "reply_topic": "lk.transcription" }
}

Your client passes livekit_url and participant_token (both exactly as the response gives them) to the LiveKit client SDK to join the room. From there the agent appears as the other participant and streams its video and audio tracks. room_name is its own value, not the session_id, and agent_identity is, despite its name, the identity the token assigns to your client.

The pattern is called a “mint proxy.” Your server exchanges your sk_ for a participant_token and hands only the token to the client. Every 2wai SDK (Flutter, Web/TypeScript, iOS native) expects a mint-proxy URL as its primary credential: pass the URL, and the SDK calls it to start a session. See Streaming into your app for the shape.

The LiveKit SDKs reconnect to the same room on short network blips with the token they already hold. Don’t call your mint proxy (and so POST /v1/sessions) to reconnect: every mint is a new session in a new room, and the old one stays open until you end it with DELETE /v1/sessions/{id} or it is reaped. POST /v1/sessions/{id}/token answers 409 not_available_on_livekit.

  1. Client asks your backend (your own API, not a 2wai endpoint) for a session.
  2. Your backend calls POST /v1/sessions with Authorization: Bearer sk_....
  3. Your backend returns livekit_url, participant_token and chat to the client.
  4. Client joins the LiveKit room directly and sends each user turn to the agent as a text stream on lk.chat. The avatar’s own brain and voice reply. No REST calls from the client.
  5. Your backend ends the session with DELETE /v1/sessions/{id} when the user leaves.

Next: Concepts for the vocabulary this builds on, or jump to Sessions for the full lifecycle.