10 min readThe aifixly team

Gemini Live API: build an AI that sees and hears in real time

We built a real-time AI that sees through your camera and answers with voice. Here is the full flow — ephemeral tokens, audio formats, cost, and the bugs that cost us the most time.

The Gemini Live API is Google's interface for two-way real-time conversation: you stream microphone and camera to the model, and it answers with voice while you are still talking. We run it in production for aifixly's 14 AI experts. This guide is everything we wish we had known before starting.

What is the Gemini Live API — and how is it different from regular Gemini?

Regular Gemini calls are request/response: you send a question over HTTP, wait, get an answer. The Live API is an open WebSocket session instead. Audio, video and text go in continuously, and the model's reply streams back as audio chunks and transcripts while you are still speaking.

The practical difference is interruptibility. In a live session you can say "no, wait" mid-sentence and the model stops immediately. You cannot fake that with turn-based calls, no matter how fast the model is.

  • Regular Gemini: HTTP, one answer per call, great for text and single-image analysis.
  • Gemini Live API: WebSocket, continuous stream, audio in and audio out, video as a frame stream.
  • Audio formats: 16 kHz PCM in, 24 kHz PCM out — resampling is your job in the client.
  • Video is sent as individual frames (0.5–2 fps is usually enough), not as a video stream.

Is Google AI Studio free?

Google AI Studio is free as a development environment — sign in with a Google account, try models in the browser and generate an API key without adding a card. The API also has a free tier with daily quotas, which is plenty for prototypes.

Cost appears when you go to production. You pay per token, and for the Live API audio counts as tokens just like text — both what you send in and what the model speaks back. Real-time audio is more expensive per minute than plain text, because the session consumes tokens the whole time it is open.

Tip:The free tier has lower rate limits and sometimes different model versions than the paid tier. If your live session drops after a few seconds in development but works in AI Studio — check the quota before you debug the code.

How do you stream audio and video in real time?

Short answer: the browser opens a WebSocket straight to Google, but it never sees your real API key. Your server issues a short-lived token instead.

  • 1. The client calls your own server endpoint, for example /api/gemini-token.
  • 2. The server uses the secret GEMINI_API_KEY to mint an ephemeral token — ours lasts 30 minutes and is single-use.
  • 3. The client opens the WebSocket session against the Live API with that token.
  • 4. The setup message goes first: model name, system instruction, response modality (audio) and voice.
  • 5. Then microphone PCM chunks and camera frames stream continuously into the session.
  • 6. Replies come back as audio chunks that you queue and play, plus transcripts for the on-screen text.

Add rate limiting and an origin check to the token endpoint on day one. Without them anyone can pull tokens from your domain and run up your bill. We cap it at 5 requests per minute and 30 per hour per IP.

What does it cost in production?

Think per minute, not per call. A live session consumes tokens continuously while it is open — even during silence, because the audio stream keeps flowing. A ten-minute conversation on Gemini Live typically lands around $0.20–$0.50 depending on how much the AI itself talks.

  • The biggest cost driver is the AI's own speech — output audio tokens are the priciest.
  • The second biggest is idle open sessions. Add an inactivity timeout.
  • Video is cheaper than you expect if you send few frames per second.
  • Short, precise system instructions save tokens in every session, not just once.
Good to know:Latency lands around 400 milliseconds in practice for Gemini Live. That is enough to feel conversational, but you will notice the difference from a real phone call on a poor network.

Which pitfalls did we hit?

All four bugs below looked like API problems at first. None of them were.

A race condition on connect

We started the audio stream inside the onopen callback and sent the first frame before the session object had been assigned. The reference was still null and the first seconds vanished. The fix was to initialise the stream after the session is assigned, not inside the open event.

"WebSocket is already in CLOSING or CLOSED state"

The client kept sending audio and video frames after Google closed the session. The error floods the console, but the real damage is that the UI still says "live". We added an explicit flag that is cleared on both close and error, and every send checks it first.

A false live state

An open WebSocket does not mean the model is answering. We showed "live" as soon as the socket connected, and users sat in silence. Now we only show connected once the first response actually arrives, with a 12-second timeout that produces a readable error instead of endless silence.

The wrong audio format

The browser's AudioContext often runs at 48 kHz. The Live API wants 16 kHz in and sends 24 kHz out. Skip the resampling and you get either noise or a chipmunk. This is not an API bug — it is one easy-to-miss line in the docs.

What is it good for — and what is it not?

The Live API shines when the context is visual and the question is immediate: you are standing at a dripping tap, a broken bike chain, an unknown plant, or a job interview in ten minutes. Those are exactly the situations we built aifixly's experts for.

  • Good fit: real-time tutoring, language practice, troubleshooting where you need to show something.
  • Good fit: coaching where interruptions and follow-up questions are the whole point.
  • Poor fit: tasks needing exact fact-checking — text with sources is better there.
  • Poor fit: anything requiring a licensed professional, like electrical or gas work. The AI should refer you to a professional, not guess.

Want to see it in practice: pick an expert, allow camera and microphone, and start talking. No account needed to try.

Frequently asked questions

What is the Gemini Live API?
The Gemini Live API is Google's interface for two-way real-time conversation with the Gemini models. Instead of one HTTP call per question, you keep a WebSocket open and stream microphone and camera; the model replies with voice and transcripts while you speak, and can be interrupted mid-sentence.
Is Google AI Studio free?
Yes, AI Studio itself is free — sign in with Google, test models and create an API key with no card required. The API also has a free tier with daily quotas. Production is billed per token, and for the Live API both incoming and outgoing audio count as tokens.
Do I need a server to use the Gemini Live API?
Yes, if your app is public. A browser cannot keep your real API key secret. The fix is a small server endpoint that mints short-lived ephemeral tokens — ours last 30 minutes and are single-use — which the client then uses to open the WebSocket session directly with Google.
What audio format does the Gemini Live API require?
16 kHz mono PCM in to the model and 24 kHz PCM out. The browser's AudioContext often runs at 48 kHz, so you must resample in the client. The wrong sample rate produces noise or an unnatural pitch — it is the most common reason live audio sounds wrong.
What does a ten-minute Gemini Live conversation cost?
Roughly $0.20–$0.50, depending on how much the AI itself speaks. Output audio tokens are the largest line item. Idle open sessions cost money too, so an inactivity timeout is the easiest saving available.
Why does the console say "WebSocket is already in CLOSING or CLOSED state"?
The client keeps sending audio or video frames after the session closed. The error itself is harmless, but it signals that your UI is probably showing a session that is no longer alive. Guard every send with a flag reset in both the close and error handlers.
How much video can you send?
Send individual frames, not a video stream. 0.5–2 frames per second is enough for most use cases and keeps cost down. More frames rarely improve answers but noticeably increase token consumption.
Can I switch from Gemini Live to GPT Live later?
Partially. The APIs are conceptually similar — WebSocket, setup message, audio chunks — but event schemas, tool calling and auth differ. A thin abstraction layer in your backend makes the switch manageable, but budget at least a week per additional model.

Want to try a live AI yourself?

Pick an expert, allow camera and microphone, and start talking. No account needed to try.

Explore the experts →