Voice chat
you can interrupt

A web app for a live voice call with a Cartesia Managed Agent. Talk over the agent and it stops, and the transcript keeps only the words it actually said.
A live call: the agent greeted the user, the user asked why the tides change twice a day, and the agent's answer is streaming in under a green Speaking badge, with Mute and End call buttons below

Screenshot. The template running locally.

Models
ink-2, sonic-3.6
Languages
English
License
Apache-2.0
Stack
Next.js 16React 19shadcn/uiagents-web
Cartesia products
Managed AgentsInk 2Sonic 3.6

What it does

Cartesia runs the whole agent, so your server has one job. It hands the browser a short-lived token, and your API key never reaches the page. The same agent can also answer phone calls, as the Front desk receptionist template does.

Run it yourself

  1. Install

    Run the commands below with Node 22.22 or newer. pnpm works too. npm run setup:agent creates the agent with POST /v1/agents and does nothing if the saved agent still exists. Deploying? Run it locally first, because the Vercel button asks for the id.

    npx degit cartesia-ai/cookbook/examples/voice-chat voice-chat
    cd voice-chat
    # add CARTESIA_API_KEY
    cp .env.example .env.local
    npm install
    # creates the agent, writes CARTESIA_AGENT_ID
    npm run setup:agent
    npm run dev
    

    Environment variables
    CARTESIA_API_KEY
    play.cartesia.ai/keys
    CARTESIA_AGENT_ID
    Written by npm run setup:agent
    AGENT_MODEL_ID
    Optional. The agent's LLM, from GET /v1/agents/models
    CARTESIA_VOICE_ID
    Optional. A voice from play.cartesia.ai/voices
    APP_PASSWORD
    Optional locally. Required on Vercel, or none to make the app public
    TRUST_PROXY
    Optional. 1 behind your own reverse proxy
  2. Start a call

    Open http://localhost:3000 and press Start call. Use headphones. Echo cancellation is on, but laptop speakers still leak into the mic and the agent interrupts itself.

Build it with your coding agent

One prompt that tells your coding agent where to start and what to read first.

Prompt

Claude CodeCursorCodex

Build a browser voice chat with a Cartesia Managed Agent. Start from https://github.com/cartesia-ai/cookbook/tree/main/examples/voice-chat and follow its AGENTS.md for the commands, files and rules. The server route mints a 60 second access token with only the agent grant through @cartesia/cartesia-js (client.accessToken.create), and the browser opens wss://api.cartesia.ai/v1/agents/websocket/{agent_id} with useCartesiaAgent from lib/agents-web. Create the agent once with npm run setup:agent, which calls POST /v1/agents. The agent runs Ink 2 and Sonic 3.6 for you, so do not add TTS or STT model fields to its config. If I don't have a Cartesia API key yet, follow https://www.cartesia.ai/agent-quickstart.md to get one.

How it works

Mic16 kHz PCM over the agent WebSocket, with echo cancellation on
Ink 2Hears you and decides when your turn has ended
LLMclaude-haiku-4.5 by default, set with AGENT_MODEL_ID
Sonic 3.6Speaks the reply as it is written
SpeakerDrops queued audio when you interrupt

Why it works this way

Interrupting clears the audio queue

When you talk over the agent, Cartesia sends an audio_output_clear event. The app throws away the audio it had queued and trims the agent's last message to the words it actually spoke.

The browser gets a 60 second token, not your key

The server makes a token that only works for agent calls and expires in 60 seconds. The token route answers 503 when the API key is missing, and 429 after 10 tokens a minute from one address.

Make it yours

Change what it says

Edit the instructions and greeting in scripts/prompt.ts, then run npm run setup:agent -- --force.

Use another voice or LLM

Set CARTESIA_VOICE_ID or AGENT_MODEL_ID and run npm run setup:agent -- --force.

Talk in another language

Set language.primary in buildBody in scripts/setup-agent.ts, write the prompt in that language and pick a voice that speaks it.

Questions

How do I keep my Cartesia API key out of the browser?

Your server makes a short-lived token and gives the browser only that. The token lasts 60 seconds and only works for agent calls, not for text to speech or speech to text. The server hands out at most 10 tokens a minute per address.

Why do my words show up only after I stop talking?

The agent sends back your words when your turn ends, not while you speak, so your message shows dots until then. The agent's own words appear as it speaks. The recipe also shows a version where you run your own LLM, and there your words appear live as you speak.

What does a call cost?

Managed Agent calls cost $0.06 a minute plus the LLM tokens. They are billed in dollars, not from your Cartesia credit balance, and each LLM has its own token price.

Are calls recorded?

Yes. Cartesia records the audio and transcript of every agent call by default. Tell your users, and delete the calls you don't need through the Cartesia API.

Is there a step-by-step guide to this template?

Yes. The recipe walks through the code, the README covers setup, environment variables and deployment, and the Managed Agents docs explain the Cartesia side.

Get started today

Talk to an expert.

Connect with a member of our team and learn how Cartesia can help you build world-class voice experiences.

Contact Sales

Start building.

Access our models via API and bring a voice agent into production in minutes.

Try Cartesia