Backend token generation for Moss voice agents. Mint LiveKit JWTs server-side so clients never see API secrets.
Project description
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:
- Your frontend asks your backend for a join token.
- Your backend calls
MossVoiceServer.create_participant_token(...)and returns the signed JWT + server URL. - 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moss_voice_server-0.1.0.tar.gz.
File metadata
- Download URL: moss_voice_server-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21874cac97cee9caaab5efec85ff00b9443a39d258e7b1589de31cf918adf424
|
|
| MD5 |
7137395fe422d1dfd63caf8448715e74
|
|
| BLAKE2b-256 |
69476976251b536f81030a075c5aa886f6b9d978867f2c225117c1519bf8313d
|
File details
Details for the file moss_voice_server-0.1.0-py3-none-any.whl.
File metadata
- Download URL: moss_voice_server-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0dbecf6df690ceb10b9871b7fab96484d4b0b7dc8052dc09cb8fbb372f670f9
|
|
| MD5 |
aeb0c75d38baf4e5e58173d319614fdc
|
|
| BLAKE2b-256 |
a9d2f127688b074aeb57dcd9cc065b36a23ea7340d17cfdb6ccd8330afbd3f09
|