Skip to main content

moss-voice-server

Backend token generation for Moss voice agents. Mints short-lived LiveKit participant JWTs server-side so your API secrets never reach the browser.

A Node.js equivalent is available as @moss-tools/voice-server on npm.

Why

Browser clients shouldn't hold LiveKit API secrets. The recommended flow:

  1. Your frontend asks your backend for a join token.
  2. Your backend calls MossVoiceServer.create_participant_token(...) and returns the signed JWT + server URL.
  3. The frontend connects to LiveKit with that token.

This package handles steps 1–2 from Python (FastAPI, Flask, Django, etc.).

Install

pip install moss-voice-server

Python 3.10+.

Usage — async (FastAPI, asyncio)

import os
from contextlib import asynccontextmanager
from fastapi import FastAPI
from moss_voice_server import MossVoiceServer, ParticipantInfo


@asynccontextmanager
async def lifespan(app: FastAPI):
    app.state.voice_server = await MossVoiceServer.create(
        project_id=os.environ["MOSS_PROJECT_ID"],
        project_key=os.environ["MOSS_PROJECT_KEY"],
        voice_agent_id=os.environ["MOSS_VOICE_AGENT_ID"],
    )
    yield


app = FastAPI(lifespan=lifespan)


@app.post("/voice/token")
async def issue_token(user_id: str, room: str) -> dict[str, str]:
    server: MossVoiceServer = app.state.voice_server
    token = server.create_participant_token(
        ParticipantInfo(identity=user_id),
        room_name=room,
    )
    return {"token": token, "url": server.get_server_url()}

Usage — sync (Flask, Django)

import os
from moss_voice_server import MossVoiceServerSync, ParticipantInfo

voice_server = MossVoiceServerSync.create(
    project_id=os.environ["MOSS_PROJECT_ID"],
    project_key=os.environ["MOSS_PROJECT_KEY"],
    voice_agent_id=os.environ["MOSS_VOICE_AGENT_ID"],
)

token = voice_server.create_participant_token(
    ParticipantInfo(identity="user_123", name="Jane"),
    room_name="support_456",
)

API

MossVoiceServer.create(project_id, project_key, voice_agent_id, api_url=...)

Async factory. Fetches credentials from the Moss API and returns an initialized instance. Raises RuntimeError on network failure or invalid credentials.

MossVoiceServerSync.create(...)

Same arguments, sync. Use in Flask/Django.

server.create_participant_token(participant, room_name, agent_name=None) -> str

Mint a signed JWT for participant to join room_name. Token TTL is 15 minutes. Pass agent_name only when you need to override LiveKit's default dispatch rules.

server.get_server_url() -> str

LiveKit WebSocket URL the client should connect to.

server.get_agent_name() -> str

Configured voice agent name.

ParticipantInfo(identity, name=None, metadata=None, attributes=None)

Identity payload for the token. identity is required and must be unique per user.

Environment variables

The library accepts credentials as arguments. By convention, applications typically read them from these env vars:

MOSS_PROJECT_ID=<your project id>
MOSS_PROJECT_KEY=<your project key>
MOSS_VOICE_AGENT_ID=<your voice agent id>

Development

pip install -e ".[dev]"
pytest

License

MIT

Metadata

Release files for moss-voice-server 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moss-voice-server 0.1.0
File Size Uploaded
moss_voice_server-0.1.0.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for moss-voice-server 0.1.0
File Interpreter ABI Platform
moss_voice_server-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.3 kB

Release files / moss_voice_server-0.1.0.tar.gz

Download URL moss_voice_server-0.1.0.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
21874cac97cee9caaab5efec85ff00b9443a39d258e7b1589de31cf918adf424
BLAKE2b-256 checksum
How to use checksums
69476976251b536f81030a075c5aa886f6b9d978867f2c225117c1519bf8313d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / moss_voice_server-0.1.0-py3-none-any.whl

Download URL moss_voice_server-0.1.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0dbecf6df690ceb10b9871b7fab96484d4b0b7dc8052dc09cb8fbb372f670f9
BLAKE2b-256 checksum
How to use checksums
a9d2f127688b074aeb57dcd9cc065b36a23ea7340d17cfdb6ccd8330afbd3f09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page