Start a session

Updated

Starts a session that runs a saved agent in an RTC channel or over the phone.

Preview documentation

You're reading the Conversational AI Platform (Preview) docs. Switch to Main.
POST
https://preview.ai.agora.io/conversational-ai/v1/projects/{appid}/sessions

The session uses the agent's configuration as saved when the session starts. To run a configuration without saving an agent first, use Start an ephemeral session.

A 200 response confirms that the session exists. It doesn't confirm that the agent has joined the RTC channel or that an outbound call was answered. To follow the session, retrieve it. The session ends when you stop it, or when it reaches a limit in lifecycle.

Path Parameters

appidstring
Required

The App ID of your project.

Header Parameters

Idempotency-Keystring

A unique key, so that retrying the request can't start a second session. If a session was already started with this key, the request fails with 409 and reason IdempotencyKeyConflict, and no new session starts. The API doesn't return the original response. To find the session, list sessions. Keep the same key when you retry; never switch keys.

Request Body

agent_idstring
Required

The ID of the saved agent to run.

transportRTC | Telephony
Required

How the agent connects to the participant. Pass the fields of one transport type only.

typestring(RTC)
Required

rtc: The agent joins an RTC channel.

channelstring(RTC)
Required

The name of the RTC channel to join, 1 to 256 characters.

tokenstring(RTC)

The RTC token the agent uses to join the channel. Required when the project has an App Certificate enabled. To renew it, update the session.

uidString | Integer(RTC)

The user ID the agent uses in the channel. Pass a string of up to 255 characters, such as "1002" or "agent-bot", or an integer from 0 to 4294967295, such as 1002. Omit it, or pass 0, to let Agora assign a user ID that differs from subscribe_uids.

subscribe_uidsarray<String | Integer>(RTC)
Required

The user ID of the participant the agent talks to, as a string or an integer. Pass exactly one user ID.

audio_scenariostring(RTC)

The audio scenario of the agent in the channel:

  • aiserver: Optimized for latency and network resilience in conversations with an agent.
  • chorus: For participants with good network conditions who need ultra-low latency.
encryptionobject(RTC)

Media encryption for the RTC channel. These values are never returned.

typestring(Telephony)
Required

telephony: The agent places a phone call.

fromstring(Telephony)
Required

The number_id of the number in the project to call from. Phone numbers aren't accepted. Import the number first.

tostring(Telephony)
Required

The phone number to call, in E.164 format, for example +14155550100.

call_policyobject(Telephony)

Limits and behavior for outbound phone calls. Each limit you omit adds no limit.

valuesobject

Values for the agent's variables, keyed by variable name, for this session only. Each key must be a variable the agent declares, and each value must match its type and options. Pass a value for every required variable. null values are rejected.

lifecycleobject

When the session ends on its own.

data_policyobject

How Agora handles the session's data. You set it when the session starts and can't change it afterward.

labelsobject

Key-value labels for this session, such as a team or customer ID. They're included in the payload of notification events.

Response Body

The session was created.

Response Headers

Agora-Request-Idstring

A unique ID for the request. Include it when you contact Agora support.

agent_session_idstring
Required

The ID of the session.

create_tsinteger
Required

The time the session was created, as a Unix timestamp in seconds.

statusstring
Required

The status of the session when it starts. For a phone call, RUNNING doesn't mean the call was answered.

Authorization

This endpoint requires authentication.

Request examples

curl -X POST 'https://preview.ai.agora.io/conversational-ai/v1/projects/string/sessions' \  -H 'Content-Type: application/json' \  -d '{  "agent_id": "3f6c2a9e-8d1b-4e7a-9c55-0b2f7d1e4a10",  "values": {    "customer_name": "Ada"  },  "labels": {    "team": "support"  },  "transport": {    "type": "rtc",    "channel": "support-4821",    "token": "<your_rtc_token>",    "uid": "1002",    "subscribe_uids": [      "1001"    ]  },  "lifecycle": {    "idle_timeout_ms": 30000,    "max_duration_ms": 3600000  }}'

Response example

Example Response
{  "agent_session_id": "a42ac95tp25py49fc37hp94vm67ht52h",  "create_ts": 1737111452,  "status": "RUNNING"}