A OneSay Agent is an AI voice participant. It joins your Room, listens to the microphone you give it and answers out loud, and you can interrupt it by speaking. It replies in the language you speak to it; before you speak, or when it cannot tell the language, it replies in Simplified Chinese (no API or SDK option sets the language). This guide gets you talking to one on the pre-production environment in a few minutes, then shows the same conversation in code with the JavaScript SDK.
Try it in OneSay Cloud
- New to OneSay: open
https://cloud.staging.onesay.com/cloud/sign-up/, choose Individual developer or Enterprise developer, enter your email address and select Continue with email (or sign up with Google or GitHub, when the page offers them); you come back to OneSay Cloud's onboarding. Already have an account: openhttps://cloud.staging.onesay.com/cloud/sign-in/. - Onboarding (
/cloud/onboarding/) walks you through your account: How will you use OneSay Cloud?, then, for an enterprise, Your company (the company and a contact); Name your Organization; Create your first Project (it gets a Test and a Live Environment; Live starts disabled); Add your first Application (its name and type); and Create your first API key (its name). Select Set up. The key's secret is shown once, in Save your secret key; copy it and select I've saved it (see API keys). You are ready then links to the Application and to the tests, and Go to OneSay Cloud opens the Overview. The new Project's Test Environment is in the trial from the start. - On Overview, under Project and Environment, choose your Project and its Test Environment. OneSay Cloud keeps this choice for the other pages. The trial runs only in an enrolled Project Environment.
- Open Voice call test in the navigation (
/cloud/tests/voice-call/, the Voice call trial page). The first time in a Project enrolled in the trial, the page signs you in once more with this Project's trial sign-in by itself, which usually brings you straight back to the page; if it shows Sign in for this Project's trial, select it and sign in once more. Then choose the Application and a Microphone Source, or select Create a new microphone Source. - Trial steps lists the steps in order: Create a Room, Start an app session, Connect, Publish the microphone, Start the Agent, Wait for the Agent, and Turn on sound and talk. For each step up to Start the Agent, select its Prepare: button (for example Prepare: create the Room): Your approval shows the exact operation; select Allow, or Deny to leave it undone. Then select the step's button that runs it (for example Create the Room). Your browser asks once for the microphone. The page then waits for the Agent by itself.
- When Wait for the Agent is done, select Turn on sound and speak. The Agent answers out loud; speak again to interrupt it.
- Select End trial, then approve each remaining step (stop the Agent, end the microphone publication, close the app session and close the Room) until the page reads "The trial has ended."
The previous OneSay Cloud, at https://cloud.staging.onesay.com/cloud-classic/ with the same account, still offers the
conversation behind one button: its Voice call test page (/cloud-classic/tests/voice-call/) has a OneSay Agent section
with Start conversation, which runs the same steps, each after your approval.
Limits in the OneSay Cloud trial
- A conversation has no time limit. It has a cost budget, and it ends when you end it or the money set aside for it runs out.
- Each enrolled account has an Agent allowance the OneSay team sets; an Agent you stop early still counts what it used.
- A trial Environment runs one Agent at a time.
The AI Agent demo on the OneSay website is a separate surface where a conversation ends when its money limit is reached or when you hang up. It is not run from OneSay Cloud.
The same conversation in code
The steps below show how to build the conversation into your own application with the OneSay JavaScript SDK (@onesay/sdk v0.2.0, in preview: the
JavaScript Quickstart says how to ask for access). OneSay Cloud's Voice call test does not run all of
them: it waits for the Agent and plays its voice in its own way.
Create the client
TypeScriptimport { OneSayClient, SPEC_SHA256, createConsentRequest, decideConsentRequest, normalizeConsentAction, setCustomEndpoints } from "@onesay/sdk"; const tokenProvider = async () => humanAccessToken; // a short-lived Human token from your sign-in flow; never an osp_ key setCustomEndpoints({ controlApi: "<CONTROL_API_URL>", realtime: "<REALTIME_URL>" }); const client = new OneSayClient({ environment: "custom", tokenProvider }); const actorId = ((await client.control.request({ operationId: "getCurrentUser", environment: "custom" })) as { data: { id: string } }).data.id; // the Human's user IDReplace
<CONTROL_API_URL>and<REALTIME_URL>with the addresses of the environment you use. On the pre-production environment (Staging) they arehttps://api.staging.onesay.com/v1andwss://realtime.staging.onesay.com/v1. Production and more regional nodes will follow, each with its own addresses, so take them from your configuration instead of writing them into your code. The SDK's environment table (SDK_ENVIRONMENTS) lists the environments a release knows by name.Call
setCustomEndpointsbefore you create a client: the released SDK names no pre-production address, and without itenvironment: "custom"is refused. An API key is refused too (authentication_required).actorId, the Human's user ID that every Consent request below names, comes fromgetCurrentUser(SDKv0.1.10or later).Confirm each step (Consent)
Every step that creates, changes or ends something needs the Human's confirmation first, except ending what is your own: stopping your own Agent, ending your own publication and revoking your own connection need none. Prepare a Consent request for the exact Action and input, show its
presentationto the Human, and record their decision:TypeScriptasync function confirm(actionId, input, scope, actorId) { const action = await normalizeConsentAction({ action_id: actionId, input }); const request = await createConsentRequest({ actor_principal_id: actorId, delegation_id: null, scope: { kind: "project_environment", project_id: scope.projectId, environment_id: scope.environmentId }, registry_digest: SPEC_SHA256, action }, { environment: "custom", idempotencyKey: crypto.randomUUID() }, { tokenProvider }); const decision = await askTheHuman(request.data.presentation); // "allow" or "deny", chosen by the Human await decideConsentRequest(request.data.id, { decision, request_digest: request.data.request_digest, wording_version: request.data.wording_version }, { environment: "custom", idempotencyKey: crypto.randomUUID() }, { tokenProvider }); }SPEC_SHA256is exported by the SDK. A request waits for a decision for at most 300 seconds. Without a decision, the operation answersconsent_required; after the Human allows it, run the operation with the same input.Room, app session, connection and microphone
Confirm and run each of these in order. The Action to confirm is in brackets.
TypeScriptconst room = await client.control.request({ operationId: "createRoom", environment: "custom", idempotencyKey: roomKey, body: { project_id, environment_id, name: "Agent conversation", max_participants: 2, ttl_seconds: 900, metadata: {} } }) as { data: { id: string } }; // room.create const appSession = await client.control.request({ operationId: "createAppSession", environment: "custom", idempotencyKey: sessionKey, body: { application_id, device_id: null, environment_id, expected_requirement_revision: null, expected_report_revision: null, registry_digest: SPEC_SHA256, ttl_seconds: 900 } }) as { data: { session: { id: string } } }; // app.session.create const roomId = room.data.id, appSessionId = appSession.data.session.id; const session = await client.rtc.connect({ roomId, appSessionId, microphoneSourceId: sourceId, idempotencyKey: connectKey }); // rtc.connection.create const microphone = await session.audio.publishLocalMicrophone();sourceIdis asensor.microphoneSource in your Organization. The Room's ID isdata.id; the app session's isdata.session.id(createAppSessionanswers with the session and its requirements assessment). PassingmicrophoneSourceIdcovers your microphone during connection admission (confirmrtc.connection.createwithmicrophone_source_id: sourceId) and returns its ID onsession.microphonePublicationId, sosession.audio.publishLocalMicrophone()captures and publishes the browser microphone directly with no extra server call.Start the Agent and hear it
TypeScriptif (!session.microphonePublicationId) { throw new Error("Connection admission did not return a microphonePublicationId."); } const scope = { projectId: project_id, environmentId: environment_id }; await confirm("agent.execution.create", { room_id: roomId, app_session_id: appSessionId, mode: "realtime", publication_ids: [session.microphonePublicationId], max_duration_seconds: 300 }, scope, actorId); const agentKey = crypto.randomUUID(); const agent = await client.rtc.agents.create({ roomId, appSessionId, mode: "realtime", publicationIds: [session.microphonePublicationId], maxDurationSeconds: 300, idempotencyKey: agentKey }); // agent.execution.createExpected:
agent.observedStateispending. Turn on the sound; you do not wait for the Agent or select its voice first:TypeScriptawait session.audio.enablePlayback(); // call it from a click or another user gesture session.audio.onAgentStatesChanged(states => console.log(states.map(s => s.state))); // listening, thinking, speaking ...With JavaScript SDK v0.2.0,
session.capabilities.autoSubscribeistrueunder LiveKit's stock auto-subscribe defaults, so LiveKit delivers the Agent's voice to your connection as soon as the Agent speaks, and the SDK plays it.session.audio.agentStatesthen lists the Agent with an emptypublicationId. To follow the Agent itself, read it withclient.rtc.agents.get(roomId, agent.agentExecutionId)at most once every 2 seconds.maxDurationSecondsis still required by the API, 1 to 1,200, but it is only recorded: reaching it ends neither the Agent nor the call. The Agent ends when you stop it, when the call ends, or when the money set aside for it at the start runs out; that amount does not come frommaxDurationSeconds. When that money runs out, the call ends for everyone in it, and rejoining that call is refused. KeepagentKey: if the response is lost, the same call with the same key returns the same Agent instead of starting another.Stop and clean up
TypeScript// Stopping your own Agent needs no confirmation. await client.rtc.agents.stop(roomId, agent.agentExecutionId, { idempotencyKey: stopKey }); // agent.execution.stopThen stop local microphone capture with
await microphone.stop()(or end the publication server-side withclient.rtc.endPublication(roomId, session.microphonePublicationId, { idempotencyKey })—rtc.publication.endneeds no confirmation since it is your own), and leave withsession.close(): it disconnects you through LiveKit, sends no revoke request and asks for no confirmation. When LiveKit reports that you left (participant_left) and you have not reconnected within about a minute, the server ends your connection. Then close the app session (app.session.close) and the Room (room.close), each after its confirmation. A stop request is accepted at once; the Agent has left when a read showsobservedStatestoppedwitheffectiveStoppedAt.
What the Agent's state means
observedState | Meaning |
|---|---|
pending | Accepted; the Agent has not joined yet |
running | The Agent is in the Room |
stopped | Your stop is confirmed (effectiveStoppedAt is set) |
failed | The Agent ended by itself before you stopped it, or it never joined: about a minute after the start OneSay asks it to join once more, and if it still cannot, the execution reads failed |
unknown | OneSay cannot confirm what the Agent is doing, for example after it stopped reporting |
desiredState is what you asked for (active or stopped); observedState is what OneSay observed.
Common errors
Every error carries code and retryable, and a requestId when the server answered. Retry only when retryable is true, and retry a create or stop
with the same idempotencyKey.
code | HTTP | Retryable | What it means and what to do |
|---|---|---|---|
consent_required | 409 | No | The step has no current approval. Confirm it (step 2), then run it again with the same input. |
quota_exceeded | 429 | No | An earlier Room, connection or Agent still holds this Environment's slot (a trial Environment runs one Agent at a time). Stop and close what is still open, then start again. |
budget_exceeded | 429 | No | The Environment's money allowance has too little left for this call. Add money to the allowance, or ask the OneSay team. |
rate_limited | 429 | Yes | Too many requests. Wait, then try again. |
capability_authority_unavailable | 503 | Yes | OneSay could not complete the request just now; your token was not refused. Wait a few seconds, then retry with the same idempotencyKey. |
service_unavailable | 503 | Yes | OneSay could not complete the request just now, and nothing is wrong with your request. Wait a few seconds, then retry with the same idempotencyKey. |
resource_state_invalid | 409 | No | The Room or Agent is not in a state that allows this step, for example an Agent is already running for this app session. Read it back, then stop or close what is open. |
grant_missing | 403 | No | Your identity may not do this here: details.required_grant names the permission you lack. Or, right after publishing, the server has not seen your microphone yet: details.required_observation is rtc.publication.published, with details.publication_id; start the Agent again. |
authentication_required | 401 | No | No token, or an API key was given. Supply a short-lived Human token. |
token_invalid | 401 | No | The token is not valid any more. Sign in again. |
token_expired | 401 | No | The token has expired. Get a new short-lived token from your sign-in flow and send the request with it. |
idempotency_conflict | 409 | No | The key was already used with different input. Use a new key for a new request. |
room_closed | 409 | No | client.rtc.connect failed because the Room no longer exists. Create a new Room for a new call. |
client_network_unavailable | — | Yes | client.rtc.connect could not reach the network or the server. Retry with a growing wait between attempts. A join that connect refuses with grant_missing (for example after the connection was revoked) is the server's definite refusal: do not retry it automatically; ask for authorization again (read the Room and app session back, confirm the Consent again if needed), then connect. |
A Device as the Agent's microphone and speaker (pre-production preview)
Use the call the Device starts itself. On OneSay's service today, the Agent does not hear the Device in a call that a person starts (ESP32 SDK 0.1.9 and earlier), which is the call this section describes.
A paired Device, such as an ESP32 board, can be the Agent's microphone and hear the Agent's answer. In this section's call you, the
Device's owner, start and stop the Agent: the Device cannot start an Agent in it, and OneSay refuses createAgentExecution and its stop from a
Device. The Device only publishes its microphone; once connected, it hears the Agent through LiveKit's own subscription.
This is a pre-production preview. On one ESP32-S3-BOX-3, on an earlier version of the service, a person has heard the Agent's reply this way, and several turns have run using recorded speech, in calls of up to about 4 minutes. Interrupting the Agent, a live conversation with several turns and longer calls are not yet verified on a device. Talk to an AI Agent on an ESP32-S3-BOX-3 walks through a call on that board.
What must be in place
- The Device's permissions. The Device is created with the Device permissions it needs, now including
rtc.subscription.configureandsignal.audio.subscribe. A Device may carry up to 32 permissions. A Device created before these two were added keeps its old credential scopes: create its credential again. - The pairing. You hold the Device's owner pair Grants for the Application:
app.session.create,room.join,source.use,signal.audio.publish,rtc.packet.configure,rtc.packet.send,rtc.subscription.configureandsignal.audio.subscribe, each naming the Application and the Device. The Device holds its own pair Grants too, includingrtc.subscription.configureandsignal.audio.subscribe. On the pre-production environment both sets are written when the Device is paired; a Device paired earlier gets the two when it is paired again. - The Delegation. The Device's media Delegation is delegated by you, the same Human who creates the Agent. OneSay refuses another Human's Device as your Agent's input.
- One place. The Device and your app session are in the same Room, Project, Environment and Application, and the Device is active.
The steps
These run on the pre-production environment.
- The Device publishes its microphone in the Room under its media Delegation, as in the
ESP32 Quickstart. Note its publication id (
pub_…). - You start the Agent with the Device's microphone as its input. This is step 4 above, made with REST:
createAgentExecution(POST /rooms/{room_id}/agent-executions) under your own app session, with Consent, and withpublication_idsholding the Device'spub_…id instead of your browser's. - The Device hears the Agent. Once connected, the Device is subscribed to the Agent's voice by LiveKit itself, as its join token allows. It makes no subscription request and needs no further Delegation or Consent; nothing is handed to it.
- Talk, then stop the Agent from your side (step 5 above).
Refusals
OneSay refuses with grant_missing (403) when:
- the Device is not paired to you for this Application, or belongs to another Application;
- another Human delegated the Device's media;
- a Device calls
createAgentExecutionor stops an Agent.
A Device with no usable capability report answers 409
device_capability_report_missing, device_capability_report_stale or
device_capability_unavailable; see the ESP32 Quickstart.
The other errors are those of the table above.
Limits
- Duration. No time limit: the call ends when someone hangs up or the money runs out. Through the API,
maxDurationSeconds(at most 1,200) is still required, is only recorded and does not end the call. - One Device and the Agent alone in the Room. The ESP32 plays every audio track it subscribes to, so other participants would be heard too.
- Echo. The board must cancel its own speaker's echo in what it captures. Without echo cancellation the Agent hears itself and keeps stopping. The quality of that is the board's.
- Revocation.
- After you revoke the Device, its credential, its media Delegation or your
source.usepair Grant, OneSay refuses a new Agent on that input, and the running Agent's input authority no longer holds. - The Device listens as long as its connection lasts. To stop its listening, revoke the Device, its credential or its own pair Grant: OneSay then requests revocation of the whole connection.
- After you revoke the Device, its credential, its media Delegation or your
Next steps
- JavaScript Quickstart: Task Voice, Realtime RTC and the Agent section.
- Multi-party voice Room: more than one person in a Room.
- The generated JavaScript SDK reference and API reference.