Metadata-Version: 2.5
Name: urun-pipecat
Version: 0.1.0
Summary: uRun LLM, speech-to-text, and speech-synthesis services for Pipecat — OpenAI-compatible chat completions with reasoning streamed as thought frames, realtime transcription, and speech synthesis on the /v1/audio/speech lane
Project-URL: Homepage, https://urun.sh
Project-URL: Documentation, https://docs.urun.sh
Project-URL: Repository, https://github.com/urun-sh/urun-pipecat
Author: Urun Platform, Inc
License: BSD 2-Clause License
        
        Copyright (c) 2026, Urun Platform, Inc
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Keywords: ai,llm,pipecat,urun,voice
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Communications :: Chat
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Requires-Dist: pipecat-ai[openai]<2.0,>=1.11.0
Provides-Extra: dev
Requires-Dist: aiohttp>=3.10; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.8; extra == 'dev'
Provides-Extra: example
Requires-Dist: pipecat-ai[daily,silero]<2.0,>=1.11.0; extra == 'example'
Provides-Extra: mic
Requires-Dist: pyaudio>=0.2.14; extra == 'mic'
Requires-Dist: sounddevice>=0.5; (sys_platform != 'linux') and extra == 'mic'
Description-Content-Type: text/markdown

# urun-pipecat

[uRun](https://urun.sh) services for [Pipecat](https://pipecat.ai) — build
voice agents and pipelines on uRun's OpenAI-compatible inference endpoint:
an LLM service, streaming speech-to-text, speech synthesis, a combined
speech-to-speech service, and a wrapper that colocates a whole voice
pipeline onto one speech-to-speech session.

`UrunLLMService` extends Pipecat's `OpenAILLMService` to work with
`https://inference.urun.sh/v1`:

- **OpenAI-compatible chat completions** — streaming, tools, structured
  output, all through the endpoint's `/v1/chat/completions` lane.
- **Reasoning as thought frames** — reasoning-capable uRun models stream
  reasoning on the delta's `reasoning_content` field (never inside
  `content`). The service maps it to `LLMThoughtStartFrame` /
  `LLMThoughtTextFrame` / `LLMThoughtEndFrame`, so reasoning is available to
  observers and logging without being sent to TTS.
- **Loud authentication** — a uRun API key is required at construction
  (argument or `URUN_API_KEY`); a missing key fails immediately, not on the
  first request.

`UrunTTSService` is a thin wrapper over Pipecat's `OpenAITTSService` for
uRun's `/v1/audio/speech` lane (24 kHz mono PCM16): the same defaults
(endpoint, API-key handling, `qwen3-tts-customvoice:bf16`, voice "Ryan",
24 kHz) and any voice string — uRun validates voices server-side against
the model's published list and answers a `400` naming the accepted set, so
the client does not duplicate the list.

```python
from urun_pipecat import UrunTTSService

tts = UrunTTSService()  # uses URUN_API_KEY from the environment
```

`UrunSTTService` extends Pipecat's `OpenAIRealtimeSTTService` for uRun's
realtime transcription session (`wss://inference.urun.sh/v1/realtime`):
streaming interim and final transcript frames, the same loud API-key
handling, and the default model `nemotron-3.5-asr:fp16`. uRun binds the
session to its model at WebSocket upgrade time, so the service appends
`&model=...` to the session URL at connect time and strips the model
from the session configuration it sends afterwards (the bound session
refuses an update naming one). The session offers no server-side turn
detection yet, so the service requires the pipeline's local VAD
(e.g. Silero), which drives the audio-buffer commits.

Final transcripts are commit-driven: the server finalizes a turn only
when the client commits the buffer, so finals arrive at utterance
boundaries — each local-VAD stop, and input end — rather than
continuously, and interim text between boundaries is not durable. The
service holds audio back until the session is configured (appending
before the session update would lock the session out of
transcription), so an utterance that starts immediately after the
pipeline starts still produces its final. A final committed at input
end races the connection teardown and may not be observed without an
error, so a pipeline that must observe every final should end input
on a VAD-stop boundary.

The service also exposes `consumed_audio_seconds`: the audio it has
actually handed to the endpoint, counting sends that completed — the
input task's direct sends and the held-back audio the configuration
drain delivers. A feeder can subtract it from what it pushed to know
how much of its audio is still queued and bound that backlog.

```python
from urun_pipecat import UrunSTTService

stt = UrunSTTService()  # uses URUN_API_KEY from the environment
```

`UrunRealtimeVoiceService` extends Pipecat's `OpenAIRealtimeLLMService` for
uRun's combined `voice-agent` realtime session
(`wss://inference.urun.sh/v1/realtime?model=voice-agent`): one
speech-to-speech session that takes the user's speech continuously and
returns the agent's speech and transcript. The model rides the connect URL
(uRun binds the session to it at upgrade time), so the session keeps the
model it was dialed with — a runtime settings delta that changes the model
is not applied, and the parent logs it as unsupported. The service strips
the model from the `session.update` it sends afterwards — the bound session
refuses an update naming one. The endpoint does its own turn detection: the
pipeline sends whatever audio arrives, silence included, resampled to the
session's 24 kHz mono PCM (`URUN_VOICE_SAMPLE_RATE`) when the transport
captures at another rate. Pass `transcript_preview=True` to also receive
the transcription model's live hypothesis of the open utterance as
replaceable preview frames (`InterimTranscriptionFrame` with a
`TranscriptPreviewResult` result): display-only revisions of the current
line, dropped once the utterance's transcript commits, never appended and
never part of the conversation history. Off by default; an endpoint
without the feature ignores the opt-in and the session runs unchanged.

```python
from urun_pipecat import UrunRealtimeVoiceService

service = UrunRealtimeVoiceService(model="voice-agent")
pipeline = Pipeline([transport.input(), service, transport.output()])
```

A headset conversation with it, no room needed, is the
[local microphone example](examples/voice-agent-mic/README.md).

Maintained by [uRun](https://urun.sh). See the
[uRun docs](https://docs.urun.sh) for the inference API reference.

## Installation

The package needs **Python 3.11+** (tested on 3.11, 3.12, and 3.13) and
installs a single runtime dependency: `pipecat-ai[openai]>=1.11,<2`.

The first release is not on PyPI yet. Until it is published, install from
a checkout:

```bash
git clone https://github.com/urun-sh/urun-pipecat
pip install "./urun-pipecat"
```

Once published, the same install works from the package name — with
[uv](https://docs.astral.sh/uv/) as usual:

```bash
pip install urun-pipecat        # or: uv add urun-pipecat
```

Optional extras:

| Extra | Adds | For |
| --- | --- | --- |
| *(none)* | the package alone | using the services in your own pipeline |
| `[example]` | the `daily` and `silero` Pipecat extras the shipped examples need | running `urun_pipecat.examples.*` |
| `[mic]` | PyAudio and sounddevice on non-Linux on top of the core package | the voice-agent microphone example (`python -m urun_pipecat.examples.mic`) — a terminal transcript UI with user captions on by default (`--no-captions` runs voice-only, `--no-preview` drops the live hypothesis preview) |
| `[dev]` | pytest and the test doubles | working on the package itself |

## Quickstart

Run a complete voice conversation — speech in, transcript, answer, spoken
reply back — with no room, microphone, or speaker. The recorded example
speaks a WAV into the pipeline exactly like a user and writes the bot's
reply back as audio:

```bash
git clone https://github.com/urun-sh/urun-pipecat
cd urun-pipecat
python -m venv .venv
.venv/bin/pip install ".[example]"    # from PyPI once the first release is published

export URUN_API_KEY="urun_sk_..."   # a uRun organization API key

# Any spoken-audio question, converted to the strict input contract —
# mono 16-bit 24 kHz PCM WAV:
ffmpeg -i question.wav -ar 24000 -ac 1 -c:a pcm_s16le question-24k.wav

.venv/bin/python -m urun_pipecat.examples.recorded question-24k.wav
```

The run prints each recognized user turn, the model's answers (with its
reasoning, when the model streams it), and writes the bot's speech to
`urun-bot-reply.wav` (change it with `-o`). The input contract is strict
because the realtime transcription session expects it. The run ends when
neither side has spoken for `--settle-secs` seconds (default 2) —
counted from the last speech activity, not from pending work — so a
deployment whose answer is slower than the settle window ends the run
before the reply is spoken; raise `--settle-secs` for it.

To talk to the bot live, in a Daily room, run the same pipeline as the
[foundational example](#running-the-examples) instead.

## Usage

```python
from urun_pipecat import UrunLLMService

llm = UrunLLMService()  # uses URUN_API_KEY from the environment
```

or explicitly:

```python
llm = UrunLLMService(
    api_key="urun_sk_...",
    settings=UrunLLMService.Settings(
        model="qwen3.8-27b:nvfp4",  # any id from GET /v1/models
        system_instruction="You are a helpful voice assistant.",
    ),
)
```

Use it anywhere a Pipecat LLM service fits, e.g. in a `Pipeline`:

```python
pipeline = Pipeline(
    [
        transport.input(),
        stt,
        user_aggregator,
        llm,  # <- UrunLLMService
        tts,
        transport.output(),
        assistant_aggregator,
    ]
)
```

See the examples shipped inside the package for complete, runnable voice
pipelines:

- [`urun_pipecat/examples/foundational.py`](src/urun_pipecat/examples/foundational.py)
  — a Daily room voice pipeline with a live microphone and speaker.
- [`urun_pipecat/examples/recorded.py`](src/urun_pipecat/examples/recorded.py)
  — the same pipeline over a recording: the input WAV is spoken into the
  pipeline at real time and the bot's reply is written back as a WAV, no
  microphone or room needed.
- [`urun_pipecat/examples/colocated.py`](src/urun_pipecat/examples/colocated.py)
  — the same pipeline, colocated onto one speech-to-speech session (next
  section).
- [`examples/voice-agent-mic`](examples/voice-agent-mic/README.md), shipped
  as `urun_pipecat.examples.mic` — talk to the combined `voice-agent`
  endpoint with your microphone and speakers through
  `UrunRealtimeVoiceService`.

## Three ways to run a voice pipeline

The same trio of models — ears, brain, voice — can run on uRun three ways,
and it is worth keeping them apart:

- **A Pipecat-managed cascade** is what the three services build: three
  independent network lanes — a realtime transcription session, a
  chat-completions stream, a speech-synthesis call — with Pipecat owning
  the turns. The pipeline's local VAD declares utterance boundaries, the
  context aggregators assemble the conversation, tools work, and each
  lane can use any model from `GET /v1/models`. Every turn pays three
  network round trips.
- **A speech-to-speech session** (uRun's `s2s` pool) is a different
  surface, with or without Pipecat: one duplex WebSocket — audio goes up,
  transcripts and speech come back down — with turn detection
  server-side. The three models are fixed when the session starts and
  share one serving stack. No pipeline code is involved; any client that
  speaks the session protocol can use it.
- **One-GPU colocation** is that same session applied to a Pipecat
  pipeline: `UrunColocated` keeps the Pipecat graph — transport, context,
  bookkeeping — and moves the trio onto one speech-to-speech session, so
  the three models share one GPU stack behind a single socket instead of
  three lanes.

| | Standalone cascade | Speech-to-speech session | `UrunColocated` |
| --- | --- | --- | --- |
| Who runs the turn | Pipecat (local VAD, aggregators) | the session, server-side | the session; turns mirrored into the context for bookkeeping |
| Network | three lanes | one duplex WebSocket | one duplex WebSocket |
| Models | any per lane (`GET /v1/models`) | the session's trio, fixed at dial time | the colocatable trio (table below) |
| Pipecat context, tools, transport | full | none — no Pipecat involved | context and transport carry over; tools and pre-seeded context have no wire path yet (v1) |

The rest of this section covers the colocation wrapper.

## Colocated voice pipelines

A standalone voice pipeline drives three network lanes — a realtime
transcription session, a chat-completions stream, a speech synthesis
call — so every turn pays three round trips and the three models sit on
three serving stacks. uRun's `s2s` pool colocates all three on one GPU
stack behind a single duplex session (the GPT-Live protocol on
`/v1/live/sessions`): audio goes up one socket, transcripts and speech
come back down it, and the models share one weights' memory instead of
three HTTP lanes.

`UrunColocated(pipeline)` moves a pipeline onto that session. Wrapping is
recognition, not rewriting: build the standalone pipeline exactly as you
already do, then wrap it before constructing the `PipelineWorker` (the
worker runs the pipeline object it was constructed with):

```python
from loguru import logger

from urun_pipecat import UrunColocated, UrunColocationError

try:
    pipeline = UrunColocated(pipeline)  # same models, one session
except UrunColocationError:
    # The application owns the fallback. The library never degrades
    # silently: on any refusal the original pipeline is untouched, so
    # log the downgrade loudly and keep serving the same models on
    # the standalone lanes (or re-raise — the choice is the app's).
    logger.warning("colocation rejected; running the standalone pipeline")
```

The matcher reads the pipeline's behaviour — the models the services are
plumbed to use and the hosts they point at — never their class names, so
a pipeline of stock OpenAI-shaped services pointed at uRun wraps exactly
as well as one using this package's services. It recognizes the voice
shape `[transport input, STT, user aggregator, LLM, TTS, transport
output, assistant aggregator]` and replaces the three services with one
`UrunColocatedSession`; the transport processors and the two context
aggregators (so your `LLMContext`) carry over unchanged. The session
derives its URL from the chat/speech base (`https://host/v1` becomes
`wss://host/v1/live/sessions`; override with the `sessions_url`
argument), requires the same uRun API key, and connects when the
pipeline runs — wrapping is offline-safe.

A trio colocates when each model has a slot on the `s2s` pool:

| Lane | Colocatable models (quantization suffix ignored) |
| --- | --- |
| STT | `parakeet-tdt-0.6b-v3`, `whisper-large-v3-turbo`, `qwen3-asr-1.7b` |
| LLM | `qwen3.8-27b`, `gemma-4-12b`, `phonellm-mini-alpha-2-nvfp4` |
| TTS | `qwen3-tts-1.7b-base`, `qwen3-tts-customvoice`, `qwen3-tts-voicedesign`, `kokoro-82m`, `breeze-tts-2` |

An uncolocatable model, a different shape, or services pointing at
different deployments raises `UrunColocationError` — the wrap never
falls back on its own. What the colocated path does differently, it says
at wrap time, loudly:

- the session speaks the pool's configured default voice — the
  standalone TTS `voice` setting has no effect on the colocated path;
- tools registered on the context cannot be called by the colocated
  engine, and pre-seeded context messages have no wire path to it (v1);
- the pool does not yet consume the system instruction (v1) — it is
  forwarded on the session start for when it does;
- the session is duplex and turn detection is server-side: it responds
  to spoken audio, and the local VAD/aggregators mirror the turns into
  the context for bookkeeping.

Run the colocated example (needs a Daily room):

```bash
python -m urun_pipecat.examples.colocated
```

## Environment variables

| Variable | Required | Description |
| --- | --- | --- |
| `URUN_API_KEY` | yes (unless `api_key` is passed) | A uRun organization API key. |
| `URUN_BASE_URL` | no | Base URL of the chat and speech lanes, overriding the hosted default. |
| `URUN_STT_BASE_URL` | no | WebSocket base URL of the realtime transcription lane, overriding the hosted default. |
| `URUN_MODEL` | no | Chat model id; any id from `GET /v1/models`. |
| `URUN_TTS_MODEL` | no | Speech model id. |
| `URUN_STT_MODEL` | no | Transcription model id. |
| `DAILY_ROOM_URL` | for the foundational and colocated examples | Daily room URL for the voice pipeline. |
| `DAILY_TOKEN` | no | Daily meeting token for the foundational example. |

## Running the examples

The foundational and recorded examples build the same voice pipeline:
Silero VAD and the three uRun services — the LLM (`UrunLLMService`),
streaming STT (`UrunSTTService` over uRun's realtime transcription
session, `nemotron-3.5-asr:fp16`; the pipeline's local VAD drives the
commits), and TTS (`UrunTTSService`: `qwen3-tts-customvoice:bf16`, voice
"Ryan", 24 kHz). The colocated example builds the same graph with the
colocatable trio pinned (Parakeet TDT 0.6B v3 → Qwen3.8-27B → Qwen3-TTS)
and wraps it with `UrunColocated` — see the colocation section above.

```bash
git clone https://github.com/urun-sh/urun-pipecat
pip install -e "urun-pipecat[example]"    # from PyPI once the first release is published
export URUN_API_KEY="urun_sk_..."

# A live room conversation (needs a Daily room):
export DAILY_ROOM_URL="https://your-domain.daily.co/?room=..."
python -m urun_pipecat.examples.foundational

# Or a recorded one (no room, no microphone): speak a WAV into the
# pipeline and get the bot's reply back as a WAV. The input must be mono
# 16-bit 24 kHz PCM — convert with `ffmpeg -i input.wav -ar 24000 -ac 1
# -c:a pcm_s16le input-24k.wav`.
python -m urun_pipecat.examples.recorded input-24k.wav

# Or talk to the combined voice-agent with your microphone and speakers
# (real hardware, and the PipeWire/PortAudio prerequisites described in
# the [mic example's README](examples/voice-agent-mic/README.md)):
pip install "urun-pipecat[mic]"
python -m urun_pipecat.examples.mic --check-mic   # keyless two-second capture check
python -m urun_pipecat.examples.mic               # a 60-second voice session
python -m urun_pipecat.examples.mic --no-captions # the same, voice-only (no input transcription)

# Or serve the same voice-agent pipeline to a browser over RTVI: a
# single-client WebSocket bot any RTVI client can dial. The paired browser
# client — `@pipecat-ai/client-js` over the WebSocket transport — lives in
# the [examples repository](https://github.com/urun-sh/examples), app
# `rtvi-voice-client`.
python -m urun_pipecat.examples.rtvi_ws --port 8765
```

## Models

uRun has no default model: `GET /v1/models` with your API key is the
authoritative list. The service's default model constant is a convenience
only; pass your own via `settings=UrunLLMService.Settings(model=...)`. See
the [uRun inference API docs](https://docs.urun.sh) for the request/response
contract, including how reasoning streams on `reasoning_content`.

## Version compatibility

The package requires **Python 3.11+** (CI tests 3.11, 3.12, and 3.13) and
is tested with [pipecat-ai](https://pypi.org/project/pipecat-ai/)
**1.11.0** (the minimum) and **1.17.0** (current at the time of testing),
via `pipecat-ai[openai]`; the example also needs the `daily` and `silero`
extras. The dependency is pinned `>=1.11.0,<2.0`. A pipeline built on these
services speaks [RTVI](https://docs.pipecat.ai/client/introduction) when it is
fronted by a Pipecat transport bot — the shipped WebSocket bot
(`urun_pipecat.examples.rtvi_ws`, run by the `rtvi-voice-client` example in the
[uRun examples repository](https://github.com/urun-sh/examples)) is driven by
the [@pipecat-ai client SDKs](https://docs.pipecat.ai/client-sdk/introduction);
the same pipeline behind any other RTVI-capable transport is reachable the
same way.

The test suite runs offline, against local fakes of uRun's lanes, and is
run against both versions:

```bash
python -m venv .venv-min
.venv-min/bin/pip install "pipecat-ai[openai]==1.11.0" -e ".[dev,example]"
.venv-min/bin/python -m pytest tests -q

python -m venv .venv-current
.venv-current/bin/pip install "pipecat-ai[openai]==1.17.0" -e ".[dev,example]"
.venv-current/bin/python -m pytest tests -q
```

## Troubleshooting

**Missing API key.** Every service requires a uRun API key at
construction — the `api_key` argument or `URUN_API_KEY` — and fails there,
loudly, not on the first request.

**A model id is not accepted.** `GET /v1/models` with your API key is the
authoritative model list; the services' default models are conveniences
only. Pass your own through each service's `Settings`.

**TTS answers `400` naming voices.** uRun validates voice strings
server-side against the model's published list and the error names the
accepted set — pass one of those.

**No final transcripts.** uRun's realtime transcription session has no
server-side VAD: finals are commit-driven and arrive at utterance
boundaries — each local-VAD stop, and input end — and interim text is not
durable across boundaries. Keep turn detection off (the service default)
and wire a VAD analyzer into the user context aggregator, as the shipped
examples do.

**The first request is slow.** The first request against a model can take
longer than warm ones while its serving stack becomes ready; subsequent
requests are faster. If a client aborts early, retry the request.

**Colocation refuses the pipeline (`UrunColocationError`).** The wrapper
never falls back on its own. Check that each lane's model is in the
colocatable table above, all three services point at one uRun deployment,
the pipeline matches the recognized voice shape (standard aggregator
order, no custom processors between them), and the wrap happens before the
`PipelineWorker` is constructed.

**The recorded example rejects a WAV.** The input must be mono 16-bit
24 kHz PCM WAV — convert with the `ffmpeg` command in the quickstart.

**Pipecat import errors.** The package needs
`pipecat-ai[openai]>=1.11.0,<2.0`; older Pipecat 0.x/1.x versions are not
supported.

## Release notes

Release notes live in [CHANGELOG.md](CHANGELOG.md); the package is
published to PyPI as
[`urun-pipecat`](https://pypi.org/project/urun-pipecat/).

## License

BSD-2-Clause. See [LICENSE](LICENSE).
