gateway

module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT

README

Speko Gateway

Speko Gateway is an open-source sidecar for real-time voice AI. A voice agent talks to it over a local Unix socket with one streaming protocol, and the Gateway connects to the speech-to-text (STT), text-to-speech (TTS) or speech-to-speech provider. It runs with your own provider keys (BYOK), with a Speko API key for managed routing and consolidated billing, or with both.

This is an early preview. The protocol is versioned, but breaking changes may occur before the first stable release.

How it works

  • The Gateway listens on an owner-only Unix socket and opens no TCP port. Every call needs the local bearer token SPEKO_LOCAL_AUTH_TOKEN.
  • The agent creates a session, then streams audio or text over a WebSocket. On a provider_direct route the Gateway dials the provider itself, and audio and text do not pass through Speko. Routes served by the Speko Router do pass through it: managed GPT-Live, native relay mode and the Python LLM clients.
  • With BYOK, the Gateway plans the session in process. The provider key is sent only to that provider.
  • With SPEKO_API_KEY, the Gateway asks the Speko control plane for a signed, short-lived session plan that names the provider and carries a short-lived provider credential. The Gateway verifies the plan before it accepts media.
  • Content-free usage telemetry is on by default. See Telemetry.

The wire format is in docs/PROTOCOL.md. What the Gateway can see and where it sends data is in docs/TRUST.md.

Quick start

Start the Gateway with one provider key. This example uses Deepgram:

export SPEKO_LOCAL_AUTH_TOKEN="$(openssl rand -hex 32)"
export SPEKO_DEEPGRAM_BYOK_API_KEY=your-deepgram-key
mkdir -m 700 run
docker run -d --rm --name speko-gateway \
  --user "$(id -u):$(id -g)" -v "$PWD/run:/run/speko" \
  -e SPEKO_LOCAL_AUTH_TOKEN -e SPEKO_DEEPGRAM_BYOK_API_KEY \
  spekoai/gateway:0.1

Check that it is ready and see what it can open:

curl --unix-socket run/runtime.sock http://localhost/readyz
curl --unix-socket run/runtime.sock "http://localhost/v1/models?provider=deepgram"

In the same shell, install the Python client from a checkout of this repository and synthesize a sentence:

pip install ./integrations/python
export SPEKO_SOCKET_PATH="$PWD/run/runtime.sock"
python hello.py
docker stop speko-gateway
# hello.py: writes 24 kHz mono 16-bit PCM to hello.pcm
import asyncio

from speko_gateway import GatewayClient
from speko_gateway.client import SessionConfig


async def main() -> None:
    client = GatewayClient.from_env()
    session = await client.open(
        SessionConfig(
            kind="tts",
            execution={
                "provider_route": "provider_direct",
                "credential_source": "byok",
                "relay_policy": "forbidden",
            },
            request={
                "provider": "deepgram",
                "language": "en",
                "max_input_characters": 1000,
            },
            media={"encoding": "pcm_s16le", "sample_rate_hz": 24000, "channels": 1},
        )
    )
    await session.append_text("Hello from Speko Gateway.")
    await session.commit_text()
    with open("hello.pcm", "wb") as out:
        async for event in session.events():
            if event.audio:
                out.write(event.audio)
            elif event.type in ("audio.done", "error"):
                break
    await session.aclose()
    await client.aclose()


asyncio.run(main())

To run a long-lived Gateway beside an agent container, use deploy/docker-compose.yml. It puts the socket in the speko-runtime volume, which the agent container mounts at /run/speko and reads as UID 65532:

docker compose --env-file .env -f deploy/docker-compose.yml up -d

.env.example lists the variables it reads.

Use it in a voice agent

The Python package speko-gateway in integrations/python has LiveKit Agents and Pipecat classes. The Gateway image carries the binary and the package, so an agent image can copy both.

For the LiveKit Python agent starter, add these lines to its Dockerfile:

FROM spekoai/gateway:0.1 AS speko-gateway

# Build stage, after `uv sync`:
COPY --from=speko-gateway /opt/speko/python /opt/speko/python
RUN uv pip install --python /app/.venv/bin/python /opt/speko/python

# Final stage, before `USER appuser`:
COPY --from=speko-gateway /usr/local/bin/speko-gateway /usr/local/bin/speko-gateway
RUN install -d -o appuser -g appuser -m 0700 /run/speko

# Replace the final CMD:
CMD ["sh", "-c", "/usr/local/bin/speko-gateway & exec uv run src/agent.py start"]

Then use Speko for the voice legs where the agent creates its session:

from livekit.plugins import openai

from speko_gateway.livekit import STT, TTS

session = AgentSession(
    stt=STT(),                             # language="en", provider="auto"
    llm=openai.LLM(model="gpt-4.1-mini"),  # any LiveKit LLM plugin
    tts=TTS(),
)

Set SPEKO_LOCAL_AUTH_TOKEN and either SPEKO_API_KEY or one BYOK key as secrets of the agent. The agent and the Gateway share one container here, so the agent process can read the Gateway's environment. Use separate containers when the provider keys must be hidden from the agent.

For Pipecat, follow docs/PIPECAT.md. Options, the Speko LLM class, realtime models and the conversation profiler are in the Python package README.

Configuration

The Gateway reads environment variables only. Every secret also has an exclusive _FILE form, for example SPEKO_API_KEY_FILE=/run/secrets/speko_api_key. A provider credential file is read again for every new session, so a short-lived token can be rotated without a restart.

Variable Default Meaning
SPEKO_LOCAL_AUTH_TOKEN required Bearer token for the local socket
SPEKO_API_KEY unset Speko API key. Turns on managed routing and billing. Requests that ask for BYOK stay local
SPEKO_<PROVIDER>_BYOK_API_KEY unset Provider key. Without SPEKO_API_KEY at least one is required
SPEKO_<PROVIDER>_BYOK_TTS_VOICE catalog default Fallback voice for BYOK TTS. A voice in the request wins
SPEKO_SOCKET_PATH /run/speko/runtime.sock Absolute Unix socket path
SPEKO_MAX_SESSIONS 100 Concurrent sessions in this process
SPEKO_LOCAL_MAX_SESSION_DURATION 24h Longest BYOK session
SPEKO_TELEMETRY_DISABLED false true turns optional telemetry off
SPEKO_GATEWAY_REGION unset Cloud region the Gateway runs in, such as ap-northeast-1. Managed routing uses it to pick a nearby provider deployment
SPEKO_RUNTIME_INSTANCE_ID hostname Non-secret name of this process in reports to Speko
SPEKO_WORKLOAD_ID unset Stable ID of the agent or service that uses this Gateway
SPEKO_WORKLOAD_TYPE agent when an ID is set Workload category in the Speko dashboard
SPEKO_INSTANCE_HEARTBEAT_INTERVAL 20s How often a managed Gateway reports its session counts
SPEKO_WARM_PLAN_TARGET 4 Session plans kept ready per route. 0 turns prefetching off
SPEKO_WARM_ROUTES unset Routes to prefetch at startup
SPEKO_WARM_TTS_MAX_CHARACTERS 100000 Character allowance of prefetched TTS plans
SPEKO_CONTROL_PLANE_URL https://gateway.speko.dev Speko control plane
SPEKO_JWKS_URL <control plane>/.well-known/jwks.json Keys that sign session plans
SPEKO_PLAN_ISSUER control-plane URL Required plan issuer
SPEKO_PLAN_AUDIENCE speko-runtime Required plan audience
SPEKO_LIVE_RELAY_HOSTS unset Extra Speko Router hostnames allowed for managed GPT-Live, comma-separated. router.speko.dev is always allowed
Providers
Kind provider names
STT alibaba, assemblyai, cartesia, deepgram, elevenlabs, gemini, gladia, gradium, hamsa, hopper, inworld, meta, modulate, munsit, nari, omi, openai, palabra, smallest, soniox, speechmatics, xai
TTS alibaba, cartesia, deepgram, elevenlabs, fish, gemini, gradium, hamsa, hopper, inworld, maya, minimax, munsit, nari, openai, palabra, paxa, rime, smallest, soniox, speechify, xai
Realtime google, openai, xai
  • The BYOK variable is the name in upper case: SPEKO_DEEPGRAM_BYOK_API_KEY. The one exception is SPEKO_GOOGLE_BYOK_ACCESS_TOKEN.
  • google is Gemini Live and takes a bearer access token. Use the _FILE form so a token refresher can rotate it. gemini is the separate AI Studio speech API and takes an API key.
  • inworld takes the Base64 key:secret portal credential. fish takes a team API key.
  • GET /v1/models lists every model. Default models and endpoints are in gateway/catalog.go.
  • The Gateway checks each provider endpoint against an allow-list of the provider's official hosts before it attaches a credential. Provider connections use TLS on port 443.
Prefetched session plans

With SPEKO_API_KEY, the Gateway keeps a few signed session plans per route in memory, so opening a session needs no control-plane round trip. It learns routes from traffic. SPEKO_WARM_ROUTES covers the first session after a start, as kind:provider[:model[:language]] entries:

SPEKO_WARM_ROUTES=stt:deepgram:nova-3:en,tts:elevenlabs::en

When no plan is ready, the Gateway asks the control plane during session creation. GET /metrics reports speko_gateway_warm_plan_hits_total and speko_gateway_warm_plan_misses_total. BYOK sessions are never prefetched.

Native relay mode

speko-gateway native is a second mode, used by agents that Speko runs. It forwards STT, TTS, LLM and realtime requests from the local socket to one Speko Router origin. It holds no provider key and no process-wide Speko key: each request carries its own session credential. The local API is in docs/PROTOCOL.md, and a container template is in deploy/docker-compose.native.yml.

Variable Default Meaning
SPEKO_LOCAL_AUTH_TOKEN required Bearer token for the local socket
SPEKO_RELAY_URL required HTTPS origin of the Router
SPEKO_SOCKET_PATH /run/speko/runtime.sock Absolute Unix socket path
SPEKO_MAX_SESSIONS 100 Concurrent requests
SPEKO_NATIVE_MAX_REQUEST_BYTES 134217728 Largest HTTP request body
SPEKO_NATIVE_SETUP_TIMEOUT 30s Limit for connecting to the Router and for a stalled upload
SPEKO_NATIVE_WRITE_TIMEOUT 15s Limit for one write to the local client
  • The socket directory must belong to the process user with mode 0700.
  • The Gateway keeps a runtime.sock.lock file beside the socket. Leave it in place: after a crash, the next process uses it to take over the old socket. A socket that the lock file does not record is refused and needs manual cleanup.

Telemetry

The Gateway sends anonymous, content-free usage telemetry by default, also when only BYOK keys are set. Turn it off with:

SPEKO_TELEMETRY_DISABLED=true

Telemetry holds session lifecycle events, timings, error classes and provider request IDs. It never holds audio, transcripts, prompts, generated text, tool names, arguments or results, or credentials. When Speko supplies the provider credential, the usage and end-of-session records needed for billing are still sent with telemetry off. docs/TRUST.md lists every payload.

Versions

Pin a released version in production. Each release has notes on the releases page.

Image tag What it is Use it for
spekoai/gateway:0.1.0 One exact release. It never changes Production, when you choose every upgrade
spekoai/gateway:0.1 The newest 0.1.x release. Gets fixes only Production, when you want fixes automatically
latest, edge, sha-<commit> Every merge to main Testing unreleased changes

speko-gateway version prints the version of a binary.

Repository layout

Path Contents
cmd/speko-gateway The command: configuration, startup, shutdown
gateway Local HTTP and WebSocket server, BYOK planner, provider catalog, native relay mode
runtime Session engine, plan verification, telemetry exporter
protocol Wire types and the session-plan JSON schema
providers One adapter package per provider
controlplane Client for the Speko control plane, and its API notes
relayapi Public wire contract of the hosted Speko Router (OpenAPI and AsyncAPI)
integrations/python Python package for LiveKit Agents and Pipecat
deploy Docker Compose templates

Speko's hosted control plane, Router, billing and infrastructure are separate services and are not in this repository.

Build and test

Go 1.26 or newer. The Python checks need uv.

make build         # bin/speko-gateway
make test          # go test ./...
make check         # go vet, tests, race tests, Python lint and tests
docker build -t spekoai/gateway:dev .

More documentation

Document Subject
docs/PROTOCOL.md Local HTTP and WebSocket protocol, signed plans
docs/TRUST.md Trust boundaries, telemetry payloads, credential handling
docs/PIPECAT.md Pipecat setup
integrations/python/README.md Python package
controlplane/renewals.md Funded Google session renewal
controlplane/instances-v2.md, instances-v3.md Process reports to the control plane
docs/CARTESIA_BYTES_TTS.md Cartesia whole-input TTS adapter for Go embedders
docs/DEEPGRAM-CAPACITY-EVIDENCE.md Detecting Deepgram rate-limit refusals in Go
docs/RELEASING.md Cutting a release

Report vulnerabilities as described in SECURITY.md. To contribute, read CONTRIBUTING.md and the Code of Conduct. Speko Gateway is released under the MIT License.

Directories

Path Synopsis
cmd
speko-gateway command
speko-gateway runs the open customer-side Speko data plane behind an owner-only Unix socket.
speko-gateway runs the open customer-side Speko data plane behind an owner-only Unix socket.
Package controlplane implements the runtime-facing Speko control-plane contract.
Package controlplane implements the runtime-facing Speko control-plane contract.
Package gateway exposes the canonical Speko Voice Protocol to local cross-language clients.
Package gateway exposes the canonical Speko Voice Protocol to local cross-language clients.
internal
batchhttp
Package batchhttp is the shared plumbing under every provider's BatchTranscriber: credential extraction, bounded HTTP exchanges, the closed status-to-ProviderError mapping, streaming multipart bodies, the poll loop for job-style APIs, and word-to-segment grouping.
Package batchhttp is the shared plumbing under every provider's BatchTranscriber: credential extraction, bounded HTTP exchanges, the closed status-to-ProviderError mapping, streaming multipart bodies, the poll loop for job-style APIs, and word-to-segment grouping.
upstream
Package upstream validates provider endpoints before any customer-owned credential is attached to a request.
Package upstream validates provider endpoints before any customer-owned credential is attached to a request.
Package metering normalizes provider evidence without falling back to submitted audio or text.
Package metering normalizes provider evidence without falling back to submitted audio or text.
Package protocol defines the versioned, provider-neutral contracts shared by the runtime, control plane, and framework integrations.
Package protocol defines the versioned, provider-neutral contracts shared by the runtime, control plane, and framework integrations.
providers
alibaba
Package alibaba implements the provider-direct Alibaba Cloud DashScope (Model Studio / Qwen) streaming STT and TTS adapters.
Package alibaba implements the provider-direct Alibaba Cloud DashScope (Model Studio / Qwen) streaming STT and TTS adapters.
assemblyai
Package assemblyai implements the provider-direct AssemblyAI Universal- Streaming v3 transcription adapter.
Package assemblyai implements the provider-direct AssemblyAI Universal- Streaming v3 transcription adapter.
azure
Package azure is the relay's integration for Microsoft's in-house MAI speech models on Azure.
Package azure is the relay's integration for Microsoft's in-house MAI speech models on Azure.
cartesia
Package cartesia implements the provider-direct Cartesia streaming TTS adapter for customer-owned credentials.
Package cartesia implements the provider-direct Cartesia streaming TTS adapter for customer-owned credentials.
deepgram
Package deepgram implements provider-direct Deepgram streaming adapters.
Package deepgram implements provider-direct Deepgram streaming adapters.
elevenlabs
Package elevenlabs implements provider-direct ElevenLabs streaming adapters.
Package elevenlabs implements provider-direct ElevenLabs streaming adapters.
fish
Package fish implements Fish Audio's MessagePack WebSocket TTS protocol and the prerecorded ASR endpoint (transcribe-1, transcribe-1-pro).
Package fish implements Fish Audio's MessagePack WebSocket TTS protocol and the prerecorded ASR endpoint (transcribe-1, transcribe-1-pro).
fonada
Package fonada implements the FonadaLabs (api.fonada.ai) Kapture v3 speech-to-text adapter.
Package fonada implements the FonadaLabs (api.fonada.ai) Kapture v3 speech-to-text adapter.
gemini
Package gemini is the relay's integration for Google's AI Studio speech surface: the Gemini 3.5 Transcribe family (speech-to-text, live and prerecorded) and Gemini Flash speech generation (text-to-speech), on provider "gemini": the AI Studio generative surface, a global endpoint authenticated with a raw API key in x-goog-api-key.
Package gemini is the relay's integration for Google's AI Studio speech surface: the Gemini 3.5 Transcribe family (speech-to-text, live and prerecorded) and Gemini Flash speech generation (text-to-speech), on provider "gemini": the AI Studio generative surface, a global endpoint authenticated with a raw API key in x-goog-api-key.
geminirealtime
Package geminirealtime implements provider-direct Gemini Live sessions.
Package geminirealtime implements provider-direct Gemini Live sessions.
gladia
Package gladia implements the provider-direct Gladia streaming STT adapter.
Package gladia implements the provider-direct Gladia streaming STT adapter.
gradium
Package gradium implements the provider-direct Gradium streaming adapters for speech-to-text and text-to-speech.
Package gradium implements the provider-direct Gradium streaming adapters for speech-to-text and text-to-speech.
hamsa
Package hamsa implements the Hamsa (api.tryhamsa.com) speech-to-text and text-to-speech adapters.
Package hamsa implements the Hamsa (api.tryhamsa.com) speech-to-text and text-to-speech adapters.
hopper
Package hopper is the relay's integration for Hopper, which serves NVIDIA's Nemotron ASR and Qwen3-TTS on its own inference: the nemotron-asr transcription model over a streaming socket and a prerecorded upload, and qwen3-tts over an HTTP synthesis endpoint.
Package hopper is the relay's integration for Hopper, which serves NVIDIA's Nemotron ASR and Qwen3-TTS on its own inference: the nemotron-asr transcription model over a streaming socket and a prerecorded upload, and qwen3-tts over an HTTP synthesis endpoint.
inworld
Package inworld implements provider-direct Inworld STT and TTS adapters.
Package inworld implements provider-direct Inworld STT and TTS adapters.
maya
Package maya implements Maya Research's realtime WebSocket v2 text-to-speech protocol for Maya Calyx.
Package maya implements Maya Research's realtime WebSocket v2 text-to-speech protocol for Maya Calyx.
meta
Package meta is the relay's integration for Meta's Muse Voice Transcribe speech-to-text service (model muse-voice-transcribe-1.0): a realtime WebSocket for live transcription and a multipart HTTP endpoint for prerecorded WAV files.
Package meta is the relay's integration for Meta's Muse Voice Transcribe speech-to-text service (model muse-voice-transcribe-1.0): a realtime WebSocket for live transcription and a multipart HTTP endpoint for prerecorded WAV files.
minimax
Package minimax implements the MiniMax T2A v2 streaming TTS adapter.
Package minimax implements the MiniMax T2A v2 streaming TTS adapter.
mock
Package mock provides deterministic STT and TTS adapters for runtime and protocol conformance tests.
Package mock provides deterministic STT and TTS adapters for runtime and protocol conformance tests.
modulate
Package modulate implements Modulate Velma-2 streaming speech-to-text.
Package modulate implements Modulate Velma-2 streaming speech-to-text.
munsit
Package munsit is the relay's integration for Munsit, an Arabic speech platform: the munsit and munsit-en-ar transcription models over a streaming socket and a prerecorded upload, and the faseeh-v1-preview voice over an HTTP synthesis endpoint.
Package munsit is the relay's integration for Munsit, an Arabic speech platform: the munsit and munsit-en-ar transcription models over a streaming socket and a prerecorded upload, and the faseeh-v1-preview voice over an HTTP synthesis endpoint.
nari
Package nari is the relay's integration for Nari Labs, which serves the Qwen3 speech models on its own inference: Qwen3-TTS (qwen3-tts, qwen3-tts-fast) over an HTTP synthesis endpoint and Qwen3-ASR (qwen3-asr, qwen3-asr-fast) over a realtime transcription socket.
Package nari is the relay's integration for Nari Labs, which serves the Qwen3 speech models on its own inference: Qwen3-TTS (qwen3-tts, qwen3-tts-fast) over an HTTP synthesis endpoint and Qwen3-ASR (qwen3-asr, qwen3-asr-fast) over a realtime transcription socket.
omi
Package omi is the relay's integration for Omi Health, which serves the omi-medical-1 transcription model over a realtime socket and a prerecorded upload.
Package omi is the relay's integration for Omi Health, which serves the omi-medical-1 transcription model over a realtime socket and a prerecorded upload.
openai
Package openai implements the OpenAI STT and TTS provider adapters.
Package openai implements the OpenAI STT and TTS provider adapters.
openailive
Package openailive implements GPT-Live speech-to-speech sessions for OpenAI's gpt-live-1: a full-duplex voice model that listens while it speaks and delegates reasoning to a backend (the caller's own application, or a Responses model it is configured with).
Package openailive implements GPT-Live speech-to-speech sessions for OpenAI's gpt-live-1: a full-duplex voice model that listens while it speaks and delegates reasoning to a backend (the caller's own application, or a Responses model it is configured with).
openairealtime
Package openairealtime implements provider-direct speech-to-speech sessions for OpenAI Realtime and xAI Grok Voice.
Package openairealtime implements provider-direct speech-to-speech sessions for OpenAI Realtime and xAI Grok Voice.
palabra
Package palabra implements Palabra's provider-direct realtime speech-to-text and text-to-speech WebSocket APIs.
Package palabra implements Palabra's provider-direct realtime speech-to-text and text-to-speech WebSocket APIs.
paxa
Package paxa is the relay's integration for Paxa Labs (Bangkok), whose paxa-tts-flash-v1 and paxa-tts-flash-v2 models speak over an HTTP synthesis endpoint.
Package paxa is the relay's integration for Paxa Labs (Bangkok), whose paxa-tts-flash-v1 and paxa-tts-flash-v2 models speak over an HTTP synthesis endpoint.
rime
Package rime implements the provider-direct Rime TTS adapter.
Package rime implements the provider-direct Rime TTS adapter.
smallest
Package smallest implements the provider-direct Smallest AI (Waves) STT and TTS adapters.
Package smallest implements the provider-direct Smallest AI (Waves) STT and TTS adapters.
soniox
Package soniox implements the provider-direct Soniox streaming adapters for speech-to-text and text-to-speech.
Package soniox implements the provider-direct Soniox streaming adapters for speech-to-text and text-to-speech.
speechify
Package speechify implements SpeechifyAI Build's chunked-HTTP text-to-speech stream for the Simba model family.
Package speechify implements SpeechifyAI Build's chunked-HTTP text-to-speech stream for the Simba model family.
speechmatics
Package speechmatics implements Speechmatics' realtime v2 streaming STT adapter.
Package speechmatics implements Speechmatics' realtime v2 streaming STT adapter.
ttsoptions
Package ttsoptions answers whether a TTS route can honor the caller's provider_options, in one place for both edges that ask: the local gateway's session create and the hosted relay's routing.
Package ttsoptions answers whether a TTS route can honor the caller's provider_options, in one place for both edges that ask: the local gateway's session create and the hosted relay's routing.
xai
Package xai implements the xAI STT and TTS provider adapters.
Package xai implements the xAI STT and TTS provider adapters.
Package relayapi defines the public wire contract of the Global Speko Relay: HTTP request and response bodies, WebSocket control and event frames, SSE stream events, the normalized error envelope, response headers, and the idempotency hashing rules shared by every relay endpoint.
Package relayapi defines the public wire contract of the Global Speko Relay: HTTP request and response bodies, WebSocket control and event frames, SSE stream events, the normalized error envelope, response headers, and the idempotency hashing rules shared by every relay endpoint.
Package runtime implements the embedded provider-neutral session engine.
Package runtime implements the embedded provider-neutral session engine.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL