> ## Documentation Index
> Fetch the complete documentation index at: https://docs.talking-avatar.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Sessions and errors

> How a session starts, how it's billed, and why it can end.

A **session** is one avatar, live, from `LiveAvatar.start()` until it closes.

## Lifecycle

**1. Start**

`LiveAvatar.start()` checks your API key, your balance and your monthly spending limit, then resolves once the avatar is live. Billing starts here.

**2. Live**

You push audio and the avatar speaks it. Running sessions are checked every 30 seconds.

**3. End**

You call `close()`, your server disconnects, or the session is stopped (see the close codes below). Billing stops, and the `close` event reports why.

## Billing

* **\$0.02 per minute**, billed per second, from the moment the avatar is live until the session ends.
* A session needs a balance of at least **\$0.02** (one minute) to start.
* Each session's duration, rate and cost appear on the [Usage](https://docs.talking-avatar.dev/dashboard/usage.md) page.

> [!WARNING]
>
> Always `close()` a session when the conversation ends, the user leaves, or anything fails. A session you forget keeps billing until it reaches its 3-hour limit.

## Limits

| | |
| - | - |
| Session length | Up to **3 hours** each |
| Sessions at once | As many as you need |
| Viewers per session | Any number (direct mode) |

## Close codes

`LiveAvatar.start()` rejects with a `LiveAvatarError` when a session can't start, and the `close` event reports why a session ended. Both carry the same code.

| Code | Meaning | What to do |
| - | - | - |
| `1000` | You closed the session | Nothing: it's the normal end |
| `4001` | Invalid or missing API key | Check `TALKING_AVATAR_API_KEY`. The key may have been revoked. |
| `4002` | Out of credits (below a minute's worth at the start, or used up during the session), or the monthly spending limit is reached | Add credits, turn on auto top-up, or raise the limit on [Billing](https://docs.talking-avatar.dev/dashboard/billing.md) |
| `4003` | The session reached its 3-hour limit | Start a new session |
| `1011` | The avatar's stream was lost and couldn't recover | Start a new session |

```js theme={null}
import { LiveAvatar, LiveAvatarError } from "@interviewflowai/talking-avatar/server";

try {
  const avatar = await LiveAvatar.start({ apiKey, avatar: "ava4" });
  avatar.on("close", (code, reason) => {
    if (code === 4002) notifyOps("Talking Avatar: add credits");
  });
} catch (error) {
  if (error instanceof LiveAvatarError && error.code === 4002) {
    showMessage("The avatar is unavailable right now."); // keep the voice agent running
  } else {
    throw error;
  }
}
```

> [!TIP]
>
> Never let an avatar failure crash your voice agent. If a session can't start, carry on with voice only, and show a clear message.

## Network drops

If the connection drops, the stream recovers by itself. Your server's `LiveAvatar` emits `republished` when it has recovered, and `LiveAvatarView` reconnects on its own (its status goes to `reconnecting`, then back to `live`).

## The watermark

Unless your account has the [Remove watermark](https://docs.talking-avatar.dev/dashboard/billing.md#remove-watermark) plan, the video shows a small *Powered by Talking Avatar* in its bottom-right corner.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.