API Reference
Complete reference for thegetpatter Python SDK.
Patter
The main SDK client class.Constructor
Methods
agent()
engine=OpenAIRealtime(...), engine=OpenAIRealtime2(...), or engine=ElevenLabsConvAI(...) for end-to-end engines; omit engine= and pass stt=/tts= for pipeline mode.
Raises:
ValueError if required credentials are missing or conflicting options are passed (e.g. both engine and stt/tts).
serve()
local_recording enables carrier-neutral SDK-side recording: an interleaved stereo WAV (left = caller, right = agent, PCM16 16 kHz) written incrementally per call. Pass a directory string to choose the output directory. The final path is surfaced as recording_path in the on_call_end payload. Independent of the carrier-side recording flag. See Local Recording.
call()
machine_detection=, ring_timeout=, on_machine_detection= (the latter was renamed from on_machine in 0.6.2; the callback receives a MachineDetectionResult not a raw dict).
machine_detection defaults to True since 0.6.2 — on Twilio Patter uses MachineDetection=DetectMessageEnd + Async AMD so there is no answer-latency penalty on human pickups. Pass machine_detection=False to skip per-call AMD billing for known destinations.
ring_timeout defaults to 25 seconds, the production-recommended value. Pass 60 for legacy carrier-default parity, or None to omit the parameter entirely (carrier picks its own default).
test()
disconnect()
Carriers
Twilio
Telnyx
Engines
OpenAIRealtime
OpenAIRealtime2
OpenAIRealtime because the GA endpoint speaks a different session.update wire shape. See Engines › OpenAIRealtime2.
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
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 — "openai_realtime", "openai_realtime_2", "elevenlabs_convai", or "pipeline". 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
ErrorCode is a StrEnum — values compare equal to their string form, so exc.code == "AUTH" also works for backward-compatible callers.

