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

# LLM Fallback for Voice Agents

> Switch to another model mid-call when the agent's own model is slow or fails

Every reply tries the agent's own model first. That is the model in `llm.model` or `llm.custom` on the [configuration](https://docs.fish.audio/agents/build/configuration.md).

Fallback decides what happens when that attempt produces no reply:

* The provider returns an error.
* The model takes too long.
* The response stream breaks off with nothing in it.

Instead of the call going silent, the platform retries the reply on another model.

A switch only affects the reply that failed. The next reply tries the agent's own model again.

## Modes

`llm.fallback.mode` picks the behavior:

| Mode | Behavior |
| - | - |
| `platform` (default) | The platform's own failover chain for platform models. A [custom LLM](https://docs.fish.audio/agents/build/custom-llm.md) gets no fallback in this mode. The chain is maintained by the platform and may change without notice. |
| `manual` | Only the models you list in `llm.fallback.models`, tried in order. |
| `off` | No model switch. A reply the agent's own model does not produce is a [failed reply](#when-a-reply-fails). |

With `manual` you choose which models back up the agent, in what order, and with what timing.

## Configure manual fallback

> [tab] Console
>
> On your agent's **Configuration** page, open **Fallback models** in the **Model** section and pick **Custom**. Select **Add fallback** and choose a model for each one, then select **Save**.
>
> The agent's own model appears as **Primary model**. Every model has a **First token timeout (s)** and a **Total timeout (s)**, entered in seconds.

> [tab] API
>
> Set `llm.fallback` on the agent's draft configuration through [`PATCH /v1/agent/agents/{agent_id}/config`](https://docs.fish.audio/agents/build/configuration#configure-through-the-api). It works like any other `llm` field.
>
> ```bash theme={null}
> curl --request PATCH "https://api.fish.audio/v1/agent/agents/$AGENT_ID/config" \
>   --header "Authorization: Bearer $FISH_API_KEY" \
>   --header "Content-Type: application/json" \
>   --data '{
>     "llm": {
>       "fallback": {
>         "mode": "manual",
>         "models": [
>           {
>             "model": "google/gemini-3.8-flash",
>             "parallel": { "kick_in_ms": 1200 }
>           },
>           {
>             "custom": {
>               "base_url": "https://llm.example.com/v1",
>               "model": "backup-70b",
>               "api_key": "sk-your-endpoint-key"
>             },
>             "ttft_timeout_ms": 4000
>           }
>         ],
>         "primary": { "ttft_timeout_ms": 3000 }
>       }
>     }
>   }'
> ```

Changes take effect for new sessions after you [publish](https://docs.fish.audio/agents/deploy/versions-publishing.md).

### `models`

1 to 3 entries, tried in the order you list them. Each entry names one model:

| Field | Content |
| - | - |
| `model` | A platform model id. Same values as `llm.model`. |
| `custom` | Your own OpenAI-compatible endpoint: `base_url`, `model`, `api_key`. Same rules as [`llm.custom`](https://docs.fish.audio/agents/build/custom-llm#point-the-agent-at-your-endpoint). Fallback endpoints don't take `headers`. |

Rules:

* An entry carries `model` or `custom`, not both. Anything else is `422`.
* No duplicates. The main model and every entry must be different models or endpoints. A duplicate is `422`.
* A custom main model can fall back to platform models.
* A platform main model can fall back to a custom endpoint.
* `api_key` is write-only. Reads and version snapshots return `null`.
* Omit `api_key` on a later patch to keep the stored key for the same `base_url` and `model`.

### Timeouts

Each entry in `models` can set two timeouts. `primary` sets the same two for the agent's own model.

| Field | Range | Default | Meaning |
| - | - | - | - |
| `ttft_timeout_ms` | 500–30,000 | 5000 | Milliseconds the model has to start its reply. Past it, the reply moves to the next model. |
| `total_timeout_ms` | 1,000–120,000 | no limit | Milliseconds the model has to finish generating its reply. Must be at least `ttft_timeout_ms` when both are set. |

The defaults apply to every model in `manual` mode. That includes the agent's own model when you leave `primary` out.

Both timeouts count from the moment a request goes to the model. A reply that calls a tool and then answers is two requests, and each has its own count.

These numbers are starting points, not thresholds. A shorter `ttft_timeout_ms` reaches a fallback sooner. It also switches away from a model that was about to answer.

#### When a reply has started

`ttft_timeout_ms` stops counting at the first of these.

* The first text of the reply.
* A tool call whose name and arguments have arrived in full. The beginning of a streamed tool call does not stop the count.

#### What `total_timeout_ms` covers

`total_timeout_ms` measures the model's generation, tool call arguments included.

* It does not measure playback. A reply can still be playing after the model has finished generating it.
* It does not include the time a tool takes to run.
* It keeps counting after the reply has started.

When it runs out, the reply has usually started, because `ttft_timeout_ms` comes first.

* What the model generated so far is still spoken. The rest is lost.
* The reply counts as a [failed reply](#when-a-reply-fails). It does not move to the next model.

If the model had not started its reply yet, the reply moves to the next model.

> [!WARNING]
>
> A short `total_timeout_ms` cuts replies that are simply long. On a platform model, a reply cut this way is generated again from the start, so the caller can hear its first words twice. Leave it unset unless you need a hard cap, and then keep it well above the time your longest reply takes to generate, tool call arguments included. To move away from a model that is slow to start, use `ttft_timeout_ms`.

### Run a fallback in parallel

The first fallback can run alongside the agent's own model, so a slow start does not hold the reply.

> [tab] Console
>
> In **Fallback models**, turn on **Run with the primary model** on **Fallback 1**, then set **Switch after (ms)**.

> [tab] API
>
> Set `parallel.kick_in_ms` on the first entry in `models`. On a later entry it is `422`.
>
> ```bash theme={null}
> curl --request PATCH "https://api.fish.audio/v1/agent/agents/$AGENT_ID/config" \
>   --header "Authorization: Bearer $FISH_API_KEY" \
>   --header "Content-Type: application/json" \
>   --data '{
>     "llm": {
>       "fallback": {
>         "mode": "manual",
>         "models": [
>           {
>             "model": "google/gemini-3.8-flash",
>             "parallel": { "kick_in_ms": 1200 }
>           }
>         ]
>       }
>     }
>   }'
> ```

The switch-over time is 300 to 10,000 ms, 1500 by default. On every reply, the platform requests the agent's own model and this fallback at the same time.

| What happens | Whose reply is used |
| - | - |
| The main model [starts its reply](#when-a-reply-has-started) within `kick_in_ms` | The main model's |
| `kick_in_ms` passes first | Whichever of the two starts first |
| One of the two fails | The other's, without waiting for `kick_in_ms` |
| Both fail | The next entry in `models` |

Parallel trades cost for latency. Both requests bill their own tokens, whichever reply is used. The request that was not used is cancelled.

## What triggers a switch

A reply moves to the next model on:

* A provider error.
* A model that has not started its reply within `ttft_timeout_ms`. Outside `manual`, within the platform's own limit.
* `total_timeout_ms` reached before the model started its reply.
* A response stream that breaks off with no output.

## What doesn't switch

* **The agent choosing silence.** A model that finishes normally with an empty reply is the agent staying quiet on purpose. Nothing switches.
* **A reply that has started.** Once a model has started its reply, a problem finishing it counts as a [failed reply](#when-a-reply-fails).

## When a reply fails

A reply fails when no model produced it, or when a problem cut it after it had started.

What the caller hears depends on the agent's own model.

* **A platform model.** The agent generates the reply again. If that fails too, it asks the caller to repeat. After three failed replies in a row it apologizes and hangs up.
* **A custom LLM.** See [Failure behavior](https://docs.fish.audio/agents/build/custom-llm.md#failure-behavior).

## Per-session override

A session can replace the agent's fallback configuration for that conversation only. See [`overrides.llm.fallback`](https://docs.fish.audio/agents/deploy/authenticated-sessions#overrides).

## See which model answered

The session detail endpoint reports every switch and which model wrote each reply. See [Conversation History](https://docs.fish.audio/agents/monitor/conversation-history.md#llm-fallbacks).

The console's **Conversations** view shows the same: each switch in the timeline, and which model answered each turn.

## Billing

* Each reply is billed by the model that answered it, at that model's rate.
* A request that a timeout cut is still billed for the tokens it used.
* A reply from a [custom LLM](https://docs.fish.audio/agents/build/custom-llm.md#point-the-agent-at-your-endpoint) endpoint has no LLM charge. Main model or fallback.

## Going further

> [card] [Custom LLM](https://docs.fish.audio/agents/build/custom-llm.md)
>
> Point the agent, or a fallback entry, at your own endpoint.

> [card] [Configuration](https://docs.fish.audio/agents/build/configuration.md)
>
> Where `llm.fallback` sits among the rest of the agent's settings.

> [card] [Authenticated sessions](https://docs.fish.audio/agents/deploy/authenticated-sessions.md#overrides)
>
> Override the fallback configuration for a single session.

> [card] [Conversation history](https://docs.fish.audio/agents/monitor/conversation-history.md#llm-fallbacks)
>
> Inspect every switch after the call.


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