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

# Let KugelAudio run the back office

> List your tools and let a model KugelAudio runs decide when to use them, so your code only runs each tool.

Set `delegation.type` to `responses`. KugelAudio then runs the model that works on a delegation,
and your client runs its tools. Everything the model writes is spoken, and it can ask the caller
something and carry on with the answer. When it cannot finish without that answer, such as a
detail it needs or a yes before it acts, its question is said word for word and the caller's
reply goes back to the model. An offer the caller is free to pass over is said like any result,
and what the caller says next is the agent's to handle. There is one exception. When the
caller has already spoken on while a question for them was being written, the question is not
said. The model answers once more with what the caller said. The same holds for a tool call
the model wrote before the caller went on: it is not sent, and the model decides again with the
caller's newer words. A note your client adds with `session.thinking.append` or
`session.instructions.append` while a delegation runs reaches the model too, which answers once
more with it. When speech recognition is unsure how a word of the caller's turn is spelled, the
model gets the likely other spellings with that turn (the ones `kugel.input_transcript.alternatives`
carries) and tries them before asking the caller again; a tool call it wrote with one of those
words before they arrived is not sent, and it decides again with them.

Confirmations follow the caller. When the caller gives the details and says yes or go ahead, the
model acts without reading them back again. When the caller has said go ahead and then gives the
one detail the model asked for, the model acts; only for something that cannot easily be undone
does it first say the complete details once and wait for a yes. When the caller says go ahead
without answering the model's question, the model takes the answer the call makes most likely,
acts, and says which one it used. If nothing in the call points to an answer, such as a time
nobody mentioned, it asks once more instead of acting. When the caller later asks about
something they wanted changed and the change was not made, the model says first that it was
not made, then what stands now, so the old value does not sound like the result.

Asked about the assistant itself, such as who made it or what it runs on, the model answers as
the agent does: from your instructions, or else that it runs on Fluid by KugelAudio. It never
names another model or company.

## Run a call with a tool

Save this next to `talk.py` from the [quickstart](/speech-to-speech/quickstart):

```python back_office.py
import asyncio
import json
import os

from openai import AsyncOpenAI

from talk import RATE, Speaker, Transcript, stream_microphone


def find_order(number: str) -> dict[str, str]:
    """Your system: replace this with a real lookup."""
    return {"number": number, "status": "shipped", "arrives": "tomorrow"}


def run_tool(name: str, arguments: str) -> str:
    """The service asks for a tool, and your code runs it and returns text."""
    if name == "find_order":
        return json.dumps(find_order(**json.loads(arguments)))
    return json.dumps({"error": f"unknown tool {name}"})


async def main() -> None:
    tasks: set[asyncio.Task[None]] = set()
    speaker = Speaker()
    transcript = Transcript()

    async with (
        AsyncOpenAI(
            api_key=os.environ["KUGELAUDIO_API_KEY"],
            base_url="https://api.elbic.com/v1",
        ) as client,
        client.live.connect() as connection,
    ):
        await connection.session.start(
            session={
                "model": "fluid-1",
                "instructions": "You answer the phone for a parcel service. Keep replies short.",
                "audio": {"format": {"type": "audio/pcm", "rate": RATE}},
                "delegation": {
                    "type": "responses",
                    "responses": {
                        "model": "mistral-medium-3.5-128b",
                        "instructions": "You are the back office of a parcel service.",
                        "tools": [
                            {
                                "type": "function",
                                "name": "find_order",
                                "description": "Find an order by its number.",
                                "parameters": {
                                    "type": "object",
                                    "properties": {"number": {"type": "string"}},
                                    "required": ["number"],
                                },
                            }
                        ],
                    },
                },
            }
        )
        with speaker.stream:
            async for event in connection:
                if event.type == "session.started":
                    tasks.add(asyncio.create_task(stream_microphone(connection)))
                    print("Talk now. Press Ctrl+C to hang up.", end="")
                elif event.type == "session.output_audio.delta":
                    speaker.play(event.delta)
                elif event.type == "session.input_transcript.delta":
                    transcript.add("You", event.delta)
                elif event.type == "session.output_transcript.delta":
                    transcript.add("Agent", event.delta)
                elif event.type == "response.event" and event.event["type"] == "response.output_item.done":
                    item = event.event["item"]
                    await connection.send(
                        {
                            "type": "response.item.create",
                            "item": {
                                "type": "function_call_output",
                                "call_id": item["call_id"],
                                "output": run_tool(item["name"], item["arguments"]),
                            },
                        }
                    )
                    await connection.send({"type": "response.create"})
                elif event.type == "error":
                    print("Error:", event.error.code, event.error.message)
                elif event.type == "session.closed":
                    break


if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("\nHung up.")
```

Run it with `python back_office.py` and ask about order 4711. The agent's words print as it
speaks, and the tool's result is in what it says.

## Return tool results

Return every tool call of a response, then send one `response.create`. KugelAudio waits 60
seconds for it. After that the response fails with `tool_output_timeout`, the caller hears that
it failed, and the call goes on. If another tool of that delegation had already returned its
output, the caller hears instead that the outcome could not be confirmed, and is asked to check.
When a delegation fails after every tool call returned, for example because the model wrote no
answer, the caller hears what the tools returned.

A delegation makes at most 16 model calls. When the caller speaks while a question for them is
being written, the delegation answers once more with what they said. A model call that fails
after a tool returned its output is made once more. Both count toward the 16. The conversation
carries across the delegations of a call.

## Choose the model

Omit `responses.model` for the default. Without paid credit, you get `kugel-llm-1`.
With paid credit: a wallet balance, a paid plan, or a contract with KugelAudio, you get `mistral-medium-3.5-128b` and can choose other supported models.
Where a region serves `kugel-llm-1`, every account can name it. With paid credit it is charged at its [published price](#pricing).

| `responses.model` | Runs on | Where the conversation and your tool results go |
|---|---|---|
| `kugel-llm-1` | Kugel back-office model | Paris, France; EU and EFTA data centres once your organisation agrees in the app; from any host |
| `mistral-medium-3.5-128b` | Mistral Medium 3.5 | Scaleway's API in Paris, from any host |
| `gpt-6.1-sol`, `gpt-6-astra` or `gpt-6.1-terra` | That OpenAI model | OpenAI's API, from any host |

The back office reaches OpenAI only when you name an OpenAI model.

### Models free credit covers

Welcome and promotional credit covers `kugel-llm-1`. Without paid credit, a session that names
another model is refused before the call starts: `session.start` gets an `error` event with
the code `paid_balance_required`, and a [WebRTC](/speech-to-speech/webrtc) create gets HTTP `402`
with the same code. The message names the models your free credit covers and links the top-up
page, for example:

`gpt-6.1-sol needs paid credit. Your free credit covers kugel-llm-1. Top up at https://kugelaudio.com/dashboard/billing?add_credits=1 to use gpt-6.1-sol.`

In the dashboard playground, the back-office model list marks each model **Covered by your free
credit** or **Needs paid credit**, and offers only the covered ones until you add credit.

## Pricing

Without paid credit, the Kugel back-office model (`kugel-llm-1`) is the default.
Welcome and promotional credits can pay for it. With paid credit, you can keep using it where the region serves it, or choose other
supported models at their published prices. Pass-through prices apply only where KugelAudio adds no margin.

The Kugel back-office model costs EUR 2.16 per million input tokens, including cached
input, and EUR 6.60 per million output tokens.

| API | Other model | Input | Cached input | Output | Pricing |
|---|---|---:|---:|---:|---|
| Speech to Speech | `mistral-medium-3.5-128b` | EUR 1.50 | EUR 1.50 | EUR 7.50 | Pass-through |
| Speech to Speech | `gpt-6.1-sol` | EUR 1.9257 | EUR 0.0963 | EUR 9.6285 | Published price |
| Speech to Speech | `gpt-6-astra` | EUR 9.6285 | EUR 0.9629 | EUR 48.1427 | Published price |
| Speech to Speech | `gpt-6.1-terra` | EUR 0.9629 | EUR 0.0481 | EUR 4.8143 | Published price |
| Hosted agents | `qwen3.8-27b` | EUR 0.80 | EUR 0.16 | EUR 4.40 | Published price |
| Hosted agents | `mistral-medium-3.5-128b` | EUR 1.5825 | EUR 1.5825 | EUR 7.9125 | Published price |

The table shows standard rates per million tokens, rounded for display.

```http
GET /v1/back-office/pricing
```

The public response includes the default model and wallet policy in `back_office`.
The `other_speech_to_speech_models` and `other_hosted_agent_models` arrays list alternate models
by API surface, with `pricing` set to `pass_through` or `published_price`. All amounts in
`prices_eur_per_million_tokens` are standard published rates. An organization with a negotiated rate
may pay a different price.

## Supported settings

`responses` takes `model`, `instructions`, `tools`, `tool_choice` (`auto`, `none` or `required`),
`parallel_tool_calls` and `reasoning.effort`. Only function tools work: hosted tools and MCP from
[OpenAI's delegation guide](https://developers.openai.com/api/docs/guides/live-delegation) are
refused with `invalid_event`.

The agent hands a turn to the back office when answering it needs one of your tools, and it
judges that from each tool's `name` and `description`. A description that names what callers ask
for works best: "Get current weather for a city. Use whenever the caller asks about weather."

## Next steps

<CardGroup cols={2}>
  <Card title="Control a call" icon="sliders" href="/speech-to-speech/during-a-call">
    Handle interruptions, pick a voice, mute and restart
  </Card>
  <Card title="Check the limits" icon="gauge" href="/speech-to-speech/limits">
    See session, rate and size limits
  </Card>
</CardGroup>
