Metadata-Version: 2.5
Name: urun-pipecat
Version: 0.1.2
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
Requires-Dist: sounddevice>=0.5; sys_platform != 'linux'
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: 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.

## Contents

- [Get started](#get-started)
- [What it provides](#what-it-provides)
- [Usage](#usage)
- [Three ways to run a voice pipeline](#three-ways-to-run-a-voice-pipeline)
- [Colocated voice pipelines](#colocated-voice-pipelines)
- [Environment variables](#environment-variables)
- [Running the examples](#running-the-examples)
- [Models](#models)
- [Version compatibility](#version-compatibility)
- [Troubleshooting](#troubleshooting)
- [Release notes and license](#release-notes-and-license)

## Get started

Talk to a voice agent from your terminal — speech in through your microphone, spoken reply back out. Python 3.11+.

Install the package (sounddevice, the audio backend on macOS and Windows,
comes with it — its wheels bundle PortAudio; on Linux, capture and playback
go through the PipeWire command-line tools):

```bash
pip install urun-pipecat
```

Authenticate with a uRun API key from the [uRun console](https://console.urun.sh/settings/api-keys):

```bash
export URUN_API_KEY="urun_sk_..."
```

Run the demo:

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

Wear headphones, wait for the status line to show `●  Listening…`, and speak. The session renders as a scrolling transcript: what you say appears as a grey line that commits when your turn ends, the agent's reply appears as text while its speech plays, and the session ends after 60 seconds (`○  Session ended`). Pick a mic with `--check-mic` first if capture fails; it runs a two-second keyless capture check.

On Linux, the mic and the speaker run through PipeWire — make `pw-record`, `pw-play`, and `pw-dump` available on your PATH (`pipewire-bin` on Ubuntu). See the [mic example's README](examples/voice-agent-mic/README.md) for platform details and flags.

## What it provides

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. One runtime dependency: `pipecat-ai[openai]>=1.11,<2`.

`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.

```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 session offers no server-side turn detection, so the pipeline's local VAD (e.g. Silero) drives the audio-buffer commits — finals arrive at utterance boundaries rather than continuously, and interim text between boundaries is not durable.

The service also exposes `consumed_audio_seconds`: the audio it has actually handed to the endpoint, counting sends that completed. 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 — the session keeps the model it was dialed with. The endpoint does its own turn detection: the pipeline sends whatever audio arrives, resampled to the session's 24 kHz mono PCM 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 — display-only, 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).


## 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
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 examples
section.

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

**The mic example cannot capture.** See the
[mic example's README](examples/voice-agent-mic/README.md) for the
PipeWire/PortAudio prerequisites per platform, and run
`python -m urun_pipecat.examples.mic --check-mic` for a keyless capture
check.

## Release notes and license

Maintained by [uRun](https://urun.sh). See the
[uRun docs](https://docs.urun.sh) for the inference API reference. Release
notes live in [CHANGELOG.md](CHANGELOG.md); the package is published to
PyPI as [`urun-pipecat`](https://pypi.org/project/urun-pipecat/).
BSD-2-Clause; see [LICENSE](LICENSE).

## Installation

The package needs **Python 3.11+** (tested on 3.11, 3.12, and 3.13) and
installs two runtime dependencies: `pipecat-ai[openai]>=1.11,<2` and, on
non-Linux, the `sounddevice` audio backend (on Linux, audio capture and
playback go through the PipeWire command-line tools instead — a system
package, not a pip one).

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, with the audio backend included: sounddevice on non-Linux (its wheels bundle PortAudio); Linux uses the PipeWire command-line tools instead — a system package, not a pip one — see the [mic example](examples/voice-agent-mic/README.md#platform-prerequisites) | using the services in your own pipeline, and 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) |
| `[example]` | the `daily` and `silero` Pipecat extras the shipped examples need | running `urun_pipecat.examples.*` |
| `[mic]` | nothing: sounddevice is already in the base install; the name stays as an alias for readers of the old README | the same `pip install "urun-pipecat[mic]"` commands from the previous README |
| `[dev]` | pytest and the test doubles | working on the package itself |
