Skip to main content
Version: Next

Building a Custom Provider

AVC can bridge a phone call to your own realtime voice backend, as long as it speaks an OpenAI Realtime-compatible WebSocket protocol.

This document is the contract your backend has to implement.

Terminology used throughout:

  • Backend - a custom stack that implements the OpenAI Realtime API.
  • Command - a JSON message AVC sends to the backend.
  • Event - a JSON message the backend sends to AVC.

1. Connecting​

AVC opens one WebSocket per phone call and closes it when the call ends.

URLWhatever is configured as the provider's API URL (ws:// or wss://)
AuthAuthorization: Bearer <api-key> - omitted entirely if no key is configured
HandshakeMust return 101. Anything else and AVC drops the call before answering it.
FramingJSON text frames, exactly one JSON object per frame

Every message in both directions is a JSON object with a top-level type field. AVC dispatches on type and silently ignores any type it does not recognise, so sending extra events is safe.


2. Audio format​

Codec used for audio streaming is PCM16 at 24 kHz only.

DirectionFormat
AVC → backendbase64-encoded PCM16 little-endian, mono, 24 kHz
backend → AVCbase64-encoded PCM16 little-endian, mono, 24 kHz

AVC sends audio continuously, in small chunks, for the whole duration of the call - including while the caller is silent.


3. Quick reference​

Commands you receive:

CommandWhen
session.updateAfter session.created, after audio setup, and whenever the tool list changes
input_audio_buffer.appendContinuously, for every chunk of caller audio
conversation.item.createOnce for the greeting, and once per tool result
response.createAfter the greeting item, and after every tool result

Events you send:

EventStatusNeeded for
session.createdRequiredInstructions, tools, voice, transcription
response.output_audio.deltaRequiredThe caller hearing your agent
conversation.item.createdRequiredThe opening greeting
input_audio_buffer.speech_startedRequiredBarge-in
response.doneRequiredCorrect timing of hangups and transfers
response.function_call_arguments.doneRequiredTool calling
response.output_audio_transcript.doneOptionalCall transcripts, agent-to-agent transfer
conversation.item.input_audio_transcription.completedOptionalCall transcripts
session.updatedOptionalNotifying that session has been updated
errorOptionalEnds or force-transfers the call

4. Commands backend receives​

4.1 session.update - is a merge, not a replace​

AVC sends at least two session.update commands per call, each carrying a different subset of the session, and the order between them is not guaranteed. The backend must merge each one into the existing session state. If you treat session.update as a full replace, you will clobber either your instructions and tools or your audio format, depending on which arrives last.

The configuration update, sent as soon as you send session.created:

{
"type": "session.update",
"session": {
"type": "realtime",
"model": "your-model-name",
"instructions": "You are a helpdesk agent for ...",
"tools": [
{
"type": "function",
"name": "end_call_tool",
"description": "Ends the call when the caller is done.",
"parameters": {
"type": "object",
"properties": {},
"required": []
}
}
],
"audio": {
"input": {
"transcription": { "model": "whisper-1" },
"turn_detection": {
"type": "server_vad",
"threshold": 0.8,
"prefix_padding_ms": 1000
},
"noise_reduction": { "type": "near_field" }
},
"output": { "voice": "alloy" }
}
}
}

The audio format update, sent when the phone leg's codec is settled:

{
"type": "session.update",
"session": {
"type": "realtime",
"audio": {
"input": { "format": { "type": "audio/pcm", "rate": 24000 } },
"output": { "format": { "type": "audio/pcm", "rate": 24000 } }
}
}
}

Notes on the fields:

  • instructions is the system prompt. It may be long, and it may contain a transcript of a previous conversation when the call was transferred from another agent.
  • audio.input.transcription is omitted entirely when the operator has not configured a transcription model. Do not assume the key is present.
  • audio.output.voice is omitted when no voice is configured - fall back to your own default.
  • tools is always the complete list. Later session.update commands that carry tools replace the whole array, so a tool that disappears from the list has been removed.

4.2 input_audio_buffer.append​

One per chunk of caller audio, continuously, for the whole call.

{ "type": "input_audio_buffer.append", "audio": "<base64 pcm16le 24kHz>" }

AVC never sends input_audio_buffer.commit. Segmenting the caller's speech into turns is entirely the backend VAD's job.

4.3 conversation.item.create​

Two shapes. The greeting, sent once at the start of the call:

{
"type": "conversation.item.create",
"item": {
"id": "msg_greet",
"type": "message",
"role": "user",
"content": [
{
"type": "input_text",
"text": "Greet the caller and ask how you can help."
}
]
}
}

The id is always the literal string msg_greet, and you must echo it back - see §6. If the operator has not configured a greeting, this command is never sent and your agent should stay silent until the caller speaks.

And the tool result, sent after every tool call:

{
"type": "conversation.item.create",
"item": {
"type": "function_call_output",
"call_id": "call_abc123",
"output": "successful"
}
}

4.4 response.create​

{ "type": "response.create" }

Sent in exactly two situations: right after you echo the greeting item, and right after every tool result. Never in response to the caller speaking.


5. Events the backend must send​

5.1 session.created - send it first​

This is the only trigger for AVC's configuration session.update. If you never send it, AVC never sends you the system prompt, the tool list, the voice, or the transcription model, and your agent will run the whole call on your own defaults with no tools.

Send it as soon as the socket is open:

{ "type": "session.created", "event_id": "evt_1", "session": {} }

5.2 response.output_audio.delta - the agent's voice​

{
"type": "response.output_audio.delta",
"item_id": "item_123",
"delta": "<base64 pcm16le 24kHz>"
}

item_id groups deltas into a single utterance. Keep it stable for the whole utterance and change it for the next one - AVC uses the change to know that a new utterance has started, and mis-grouped audio plays back in the wrong order.

5.3 conversation.item.created - echo the greeting​

Whenever AVC creates a conversation item, echo it back with the same id:

{
"type": "conversation.item.created",
"previous_item_id": "item_122",
"item": {
"id": "msg_greet",
"type": "message",
"role": "user",
"status": "completed",
"content": []
}
}

When AVC sees item.id == "msg_greet" it replies with response.create, and that is what makes the agent speak first. If the backend does not echo this item, the call opens in silence and the agent will not talk until the caller does.

5.4 input_audio_buffer.speech_started - barge-in​

{
"type": "input_audio_buffer.speech_started",
"event_id": "evt_9",
"audio_start_ms": 1200,
"item_id": "item_124"
}

The backend needs to send this the moment its VAD detects the caller starting to talk. AVC discards all buffered playback so the caller stops hearing the interrupted response. Stop generating audio at the same time - AVC sends no truncate command.

Without this event, the caller cannot interrupt the agent: they will hear the whole buffered response play out over the top of themselves.

5.5 response.done - end of turn​

{
"type": "response.done",
"event_id": "evt_10",
"response": {
"id": "resp_1",
"object": "realtime.response",
"status": "completed",
"status_details": null,
"output": [],
"usage": {}
}
}

The backend should send one at the end of every response. Beyond bookkeeping this drives tool-call timing, and response.id must line up with the response_id the backend puts on the function-call event - see §7.

A response.done with "status": "failed" and a non-null status_details is treated as a fatal failure and triggers the operator's fallback (see §8).

These are what populate the call transcript, and what gets handed over when a call is transferred from one AI agent to another. Everything still works without them; the transcript is just empty.

Your agent's turn:

{
"type": "response.output_audio_transcript.done",
"event_id": "evt_11",
"content_index": 0,
"transcript": "Hello, how can I help?"
}

The caller's turn - only relevant if a transcription model was configured:

{
"type": "conversation.item.input_audio_transcription.completed",
"event_id": "evt_12",
"content_index": 0,
"transcript": "I need to reset my password."
}

6. Call flow​


7. Tool calling​

The tools available to you arrive in the tools array of session.update (§4.1). To call one, emit response.function_call_arguments.done followed by response.done. AVC runs the tool and sends you the result.

Request the call like this:

{
"type": "response.function_call_arguments.done",
"event_id": "evt_20",
"response_id": "resp_5",
"item_id": "item_130",
"output_index": 0,
"call_id": "call_abc123",
"name": "end_call_tool",
"arguments": "{\"reason\":\"caller is finished\"}"
}

Two requirements:

  • arguments is a JSON-encoded string, not an object. Arguments that fail to parse are treated as an empty argument set rather than failing the call.
  • Follow it with response.done carrying the same id - response.id must equal the response_id you sent. Some tools hang up or transfer the call, and AVC uses this to wait until the agent has stopped speaking before firing them. Without a matching response.done, every such call stalls for 5 seconds and then cuts the caller off mid-sentence.

AVC replies with exactly two commands, on success or failure:

{
"type": "conversation.item.create",
"item": {
"type": "function_call_output",
"call_id": "call_abc123",
"output": "successful"
}
}
{ "type": "response.create" }

output is the tool's return value, or "successful" / "unsuccessful" for tools that return nothing. Tools have a 5 second execution budget; overrunning it yields "unsuccessful".

Treat the response.create as your cue to speak the result. For a tool that hangs up or transfers, the call may already be gone by the time these arrive - do not treat the socket closing right after a tool result as an error.


8. Errors and disconnects​

The error event ends the call​

{
"type": "error",
"event_id": "evt_30",
"error": {
"type": "invalid_request_error",
"code": "invalid_value",
"message": "...",
"param": null,
"event_id": null
}
}

An error event is fatal. AVC runs the operator's configured fallback, which either hangs up the call or force-transfers it to a fallback number.

A turn that never produces audio​

When a fallback is configured, AVC also puts a deadline on hearing something back from the backend. The clock starts when the call connects, restarts every time the backend sends conversation.item.created, and is cleared as soon as response.output_audio.delta arrives.

It expires when a turn is accepted but never speaks - a model that stalls, or a response that fails without reporting it. On expiry AVC runs the same fallback as above, so the caller is hung up or transferred rather than left listening to silence.

Losing the socket​

If the WebSocket drops, AVC ends the call cleanly - the caller hears the line go quiet and the call finishes. There is no reconnect and no resume; a new call means a new socket.


9. Skill for AI Agents​

If you are using AI agents to create and configure Custom provider backend to work with AVC, here is a skill file that will help with that.

Skill for creating and optimizing Custom provider backend to work with AVC
---
name: avc-custom-provider
description: Use when building, testing, or debugging a custom realtime voice backend that AVC (AI Voice Connector) bridges phone calls to - an OpenAI Realtime-compatible WebSocket server. Covers the command/event contract, session.update merge semantics, PCM16 24 kHz framing, the msg_greet greeting handshake, barge-in, tool calling, and the failures that end calls silently.
---

# Building an AVC-compatible realtime backend

AVC opens **one WebSocket per phone call** and speaks a subset of the OpenAI
Realtime protocol over it. You are implementing the server side of that socket.

Vocabulary: a **command** is JSON that AVC sends you; an **event** is JSON you
send AVC. Every frame is one JSON object with a top-level `type`. AVC silently
ignores types it does not know, so extra events are safe - extra _silence_ is not.

## The minimum that produces a working call

Six events. Anything less and the call is broken in a way that does not log an
error anywhere:

| Event | Omitting it means |
| --------------------------------------- | ----------------------------------------------------------- |
| `session.created` | You never receive instructions, tools, voice, transcription |
| `conversation.item.created` | The call opens in silence; the agent never greets |
| `response.output_audio.delta` | The caller hears nothing at all |
| `input_audio_buffer.speech_started` | The caller cannot interrupt; audio talks over them |
| `response.done` | Hangups and transfers cut the caller off mid-sentence |
| `response.function_call_arguments.done` | No tool ever runs |

Optional but cheap: `response.output_audio_transcript.done` and
`conversation.item.input_audio_transcription.completed` populate the call
transcript and the handover text when one AI agent transfers to another.

## Build in this order

Each step is verifiable on its own, and a step is invisible until the one above
it works. Do not jump ahead to tool calling with no audio path.

1. **Socket.** Accept the upgrade, return 101. Read `Authorization: Bearer ...`
if you require a key - AVC omits the header entirely when no key is
configured. Anything but 101 and AVC drops the call before answering it.
2. **`session.created`.** Send it immediately on open, even empty:
`{"type":"session.created","event_id":"evt_1","session":{}}`. This is the
only trigger for AVC's configuration `session.update`. Verify you then
receive instructions and tools.
3. **Session merge.** Handle `session.update` as a **deep merge** into existing
state. At least two arrive per call carrying disjoint subsets, **in no
guaranteed order**. Verify with both orderings.
4. **Audio in.** Decode `input_audio_buffer.append`, feed your VAD. Nothing is
expected back yet - just confirm the bytes decode to sane PCM.
5. **Audio out.** Emit `response.output_audio.delta`, then `response.done`.
Verify on a real call that the caller hears undistorted speech.
6. **Greeting.** Echo `conversation.item.created` for the item AVC creates.
Verify the agent speaks first.
7. **Barge-in.** Emit `input_audio_buffer.speech_started` from your VAD and stop
generating. Verify by talking over the agent.
8. **Tools.** `response.function_call_arguments.done` + a matching
`response.done`. Verify a hangup tool lets the agent finish its sentence.
9. **Transcripts, then errors.** Transcript events last; they change nothing
functionally.

## Invariants that break calls silently

| Rule | Break it and |
| ----------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| `session.update` is a merge, never a replace | The later update clobbers either your prompt+tools or your audio format |
| `item_id` is stable within an utterance, different for the next | Utterances merge or split; audio plays back out of order |
| Echo `conversation.item.created` with the same `id` | `msg_greet` never triggers `response.create`; the call opens mute |
| `response.done`'s `response.id` equals the `response_id` of the function call | Hangup/transfer stalls 5 s, then cuts the caller off mid-word |
| `arguments` is a JSON-encoded **string**, not an object | Arguments silently become an empty set |
| Audio is exactly PCM16 LE mono 24 kHz, both directions | Chipmunk or slowed speech - AVC does not resample |
| `error` is reserved for fatal problems | Any `error` event ends or force-transfers the live call |

That last one bites hardest when porting an existing Realtime server: many emit
`error` for benign things like an unrecognised field in `session.update`. Under
AVC that hangs up on the caller. Downgrade those to logs.

## Audio

- PCM16, little-endian, mono, **24 kHz only** - 48 000 bytes/s, 48 bytes/ms.
- Base64 in `delta` and in `audio`, one chunk per frame.
- AVC sends one RTP packet's worth per frame, typically 20 ms / 960 bytes,
**continuously for the whole call** including while the caller is silent. A
gap in appends is not a turn boundary.
- **`input_audio_buffer.commit` never arrives.** Segmenting the caller into
turns is entirely your VAD's job, as is deciding when to respond. AVC only
sends `response.create` after the greeting item and after a tool result.

## Tool calling

Tools arrive in the `tools` array of `session.update` and that array is always
**complete** - a tool missing from a later update has been removed. Emit:

```json
{
"type": "response.function_call_arguments.done",
"response_id": "resp_5",
"call_id": "call_abc123",
"name": "end_call_tool",
"arguments": "{\"reason\":\"caller is finished\"}"
}
```

then `response.done` with `response.id == "resp_5"`. That pairing is how AVC
learns your agent has stopped talking: for a tool that hangs up or transfers it
waits for it, then drains the audio already buffered, and only then fires the
tool. Without it the caller loses the last sentence.

AVC replies with `conversation.item.create` (`function_call_output`) and
`response.create`. Treat that pair as the cue to speak the result. Tools have a
**5 second** budget; overrunning yields `"unsuccessful"`. For a hangup or
transfer the socket may close before the result arrives - that is not an error.

## Rules

- Ignore unknown command types rather than erroring on them.
- Never assume a key is present: `audio.input.transcription` is absent when no
transcription model is configured, `audio.output.voice` when no voice is.
Fall back to your own defaults.
- `instructions` may be very long and may embed a prior conversation transcript
when the call was transferred in from another agent.
- Stamp `"type": "realtime"` handling into your parser - AVC sets it on every
`session.update`.
- Do not reconnect or resume. One call, one socket; when it drops the call ends.