Documentation Index
Fetch the complete documentation index at: https://patter-06b046ce-feat-observability-otel-attrs-0-6-1.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
API Reference
Complete reference for thegetpatter Python SDK.
Patter
The main SDK client class.Constructor
| Parameter | Type | Default | Description |
|---|---|---|---|
carrier | Twilio | Telnyx | None | None | Telephony carrier instance. Reads credentials from env vars when arguments are omitted. |
phone_number | str | "" | Phone number in E.164 format. |
webhook_url | str | "" | Public hostname, no scheme. |
tunnel | CloudflareTunnel | Static | bool | None | None | Tunnel directive. True is shorthand for CloudflareTunnel(). |
pricing | dict | None | None | Override default provider pricing. See Metrics & Cost Tracking. |
Methods
agent()
engine=OpenAIRealtime(...) or engine=ElevenLabsConvAI(...) for end-to-end engines; omit engine= and pass stt=/tts= for pipeline mode.
| Parameter | Type | Default | Description |
|---|---|---|---|
system_prompt | str | required | Agent instructions. |
engine | OpenAIRealtime | ElevenLabsConvAI | None | None | End-to-end voice runtime. Omit for pipeline mode. |
stt | STTProvider | None | None | STT instance for pipeline mode (e.g. DeepgramSTT()). |
llm | LLMProvider | None | None | LLM provider instance for pipeline mode (e.g. AnthropicLLM()). Mutually exclusive with on_message on serve(). Ignored when engine is set. |
tts | TTSProvider | None | None | TTS instance for pipeline mode (e.g. ElevenLabsTTS()). |
voice | str | "alloy" | TTS voice name (when engine doesn’t carry it). |
model | str | "gpt-4o-mini-realtime-preview" | AI model ID (when engine doesn’t carry it). |
language | str | "en" | BCP-47 language code. |
first_message | str | "" | Greeting spoken at call start. |
tools | list[Tool] | None | None | Tool(...) instances for function calling. |
variables | dict | None | None | Dynamic {placeholder} variable substitutions. |
guardrails | list[Guardrail] | None | None | Guardrail(...) instances applied to LLM output. |
hooks | PipelineHooks | None | None | Pipeline hooks for STT/TTS interception. |
text_transforms | list[Callable] | None | None | Text transformation functions (pipeline mode). |
vad | VADProvider | None | None | Voice activity detection provider (pipeline mode). |
audio_filter | AudioFilter | None | None | Audio preprocessing filter (pipeline mode). |
background_audio | BackgroundAudioPlayer | None | None | Background audio player (pipeline mode). |
barge_in_threshold_ms | int | 300 | Barge-in hang-over window (ms). Set to 0 to disable. |
aggressive_first_flush | bool | False | Emit the first clause on a soft punctuation boundary (,, em/en-dash) once buffer ≥40 chars. Saves 200–500 ms TTFA. Hard-disabled when language starts with "it". Pipeline mode only. |
disable_phone_preamble | bool | False | Disable the phone-friendly preamble Patter prepends to system_prompt (no markdown / emojis / lists, numbers spelled out, replies kept short). Default False keeps the preamble on. |
ValueError if required credentials are missing or conflicting options are passed (e.g. both engine and stt/tts).
serve()
call()
test()
disconnect()
Carriers
Twilio
Telnyx
Engines
OpenAIRealtime
ElevenLabsConvAI
STT classes
api_key: str | None = None and fall back to the provider’s standard env var. See the STT page for full constructor signatures.
TTS classes
api_key: str | None = None and fall back to the provider’s standard env var. See the TTS page for full constructor signatures.
LLM providers
api_key: str | None = None and fall back to the provider’s standard env var (GoogleLLM prefers GEMINI_API_KEY, falls back to GOOGLE_API_KEY). See the LLM page for full constructor signatures and tool-calling semantics.
Pass an instance via phone.agent(llm=...) for pipeline mode. llm= is mutually exclusive with on_message on serve() and is ignored when engine= is set.
Tunnels
| Class | Behavior |
|---|---|
CloudflareTunnel() | Auto-start a Cloudflare Quick Tunnel via the local cloudflared binary. |
Static(hostname=...) | Use an existing public hostname (user-managed tunnel, e.g. ngrok). |
Ngrok(hostname=...) | Use an existing ngrok hostname (you run ngrok http 8000 yourself). Same behavior as Static(hostname=...) with an ngrok-friendly name. |
tunnel=True on Patter(...) is shorthand for tunnel=CloudflareTunnel().
Tools & Guardrails
Tool
handler or webhook_url must be provided.
tool(...) is a factory that doubles as a decorator — see Tools.
Guardrail
Data Classes
All data classes are frozen (immutable) dataclasses.Agent
provider is a closed string literal — only "openai_realtime", "elevenlabs_convai", or "pipeline" are valid. It is normally derived from engine / stt+tts and rarely set by hand.
CallEvent
IncomingMessage
STTConfig / TTSConfig
Internal config dataclasses produced when you pass an STT/TTS instance tophone.agent(). You rarely need to construct these directly.
CallControl
Passed as the second argument toon_message handlers. Allows dynamic call management:
CallMetrics / CostBreakdown / LatencyBreakdown / TurnMetrics
See Metrics & Cost Tracking.Exceptions
ErrorCode on its code attribute. Branch on the code instead of class-name strings:
ErrorCode values
| Code | Raised when |
|---|---|
CONFIG | Invalid constructor args, missing required env var, frozen-config violation. |
CONNECTION | WebSocket connect failure, HTTP 5xx from a provider, network error. |
AUTH | Provider rejected our credentials (HTTP 401/403, invalid signature). |
TIMEOUT | Provider response, voicemail post, or other awaited operation timed out. |
RATE_LIMIT | Provider returned HTTP 429. |
WEBHOOK_VERIFICATION | Twilio / Telnyx webhook signature verification failed. |
INPUT_VALIDATION | Caller passed a malformed phone number, tool arg, etc. |
PROVIDER_ERROR | Generic catch-all for unexpected upstream provider failures. |
PROVISION | Phone number provisioning, webhook configuration, or carrier setup failed. |
INTERNAL | Assertion failed / unexpected internal state. Likely a Patter bug. |
ErrorCode is a StrEnum — values compare equal to their string form, so exc.code == "AUTH" also works for backward-compatible callers.
Audio helpers
| Helper | Purpose |
|---|---|
builtin_clip_path(name: str) -> Path | Resolve the on-disk path for a built-in BuiltinAudioClip (hold music, dial tones, hangup chimes) so callers can preload or copy them. |
select_sound_from_list(sounds, *, rng=None) -> str | Pick one entry from a list of sound paths/IDs deterministically (or randomly when rng is provided). Useful for randomised hold music. |
resample_24k_to_16k(pcm: bytes) -> bytes | One-shot 24 kHz → 16 kHz PCM resampler. Mirrors the helper Patter uses internally for OpenAI TTS chunks; exported for callers who need to do the same conversion outside the streaming loop. |

