API Reference
Complete reference for thepatter Python SDK (v0.3.0).
Patter
The main SDK client class.Constructor
| Parameter | Type | Default | Description |
|---|---|---|---|
mode | str | "local" | Operating mode. Can be omitted — auto-detected when provider keys are given. |
twilio_sid | str | "" | Twilio Account SID. |
twilio_token | str | "" | Twilio Auth Token. |
telnyx_key | str | "" | Telnyx API key. |
telnyx_connection_id | str | "" | Telnyx Call Control App ID. |
openai_key | str | "" | OpenAI API key. |
elevenlabs_key | str | "" | ElevenLabs API key. |
deepgram_key | str | "" | Deepgram API key. |
phone_number | str | "" | Phone number in E.164 format. |
webhook_url | str | "" | Public hostname (no scheme). |
pricing | dict | None | None | Override default provider pricing. See Metrics & Cost Tracking. |
Methods
call()
PatterConnectionErrorifagentis not provided.ValueErroriftois not in E.164 format.
agent()
ValueError if provider is invalid or required keys are missing.
serve()
TypeErrorifagentis not anAgentinstance.ValueErrorifportis out of range.
test()
on_message handler is provided and an openai_key is configured, the built-in LLM loop is used. See Test Mode for details.
Raises:
TypeErrorifagentis not anAgentinstance.
disconnect()
Static Methods
Patter.deepgram()
Patter.whisper()
Patter.elevenlabs()
Patter.openai_tts()
Patter.guardrail()
Patter.tool()
agent(tools=[...]).
| Parameter | Type | Default | Description | |
|---|---|---|---|---|
name | str | required | Tool name (visible to the LLM). | |
description | str | "" | What the tool does (visible to the LLM). | |
parameters | dict | None | None | JSON Schema for tool arguments. | |
handler | Callable | None | None | Async or sync callable `(arguments, context) -> str | dict`. Called in-process. |
webhook_url | str | "" | URL to POST to when the LLM invokes the tool. |
handler or webhook_url must be provided.
Raises: ValueError if neither handler nor webhook_url is provided.
Data Classes
All data classes are frozen (immutable) dataclasses.Agent
| Field | Type | Default | Description |
|---|---|---|---|
system_prompt | str | required | Agent instructions. |
voice | str | "alloy" | TTS voice name. |
model | str | "gpt-4o-mini-realtime-preview" | AI model ID. |
language | str | "en" | BCP-47 language code. |
first_message | str | "" | Greeting spoken at call start. |
tools | list[dict] | None | None | Tool definitions for function calling. |
provider | str | "openai_realtime" | "openai_realtime", "elevenlabs_convai", or "pipeline". |
stt | STTConfig | None | None | STT config for pipeline mode. |
tts | TTSConfig | None | None | TTS config for pipeline mode. |
variables | dict | None | None | Dynamic variable substitutions for {placeholder} in system_prompt. Values limited to 500 chars. |
guardrails | list | None | None | Output guardrails. |
CallEvent
| Field | Type | Default | Description |
|---|---|---|---|
call_id | str | required | Unique call identifier. |
caller | str | "" | Caller phone number. |
callee | str | "" | Callee phone number. |
direction | str | "" | "inbound" or "outbound". |
IncomingMessage
| Field | Type | Description |
|---|---|---|
text | str | The user’s transcribed message. |
call_id | str | Unique call identifier. |
caller | str | Caller phone number. |
STTConfig
| Field | Type | Default | Description |
|---|---|---|---|
provider | str | required | STT provider name ("deepgram", "whisper"). |
api_key | str | required | Provider API key. |
language | str | "en" | BCP-47 language code. |
to_dict() -> dict
TTSConfig
| Field | Type | Default | Description |
|---|---|---|---|
provider | str | required | TTS provider name ("elevenlabs", "openai"). |
api_key | str | required | Provider API key. |
voice | str | "alloy" | Voice name or ID. |
to_dict() -> dict
Guardrail
| Field | Type | Default | Description |
|---|---|---|---|
name | str | required | Guardrail identifier. |
check | Callable[[str], bool] | None | None | Custom check function. |
blocked_terms | list[str] | None | None | Case-insensitive blocked terms. |
replacement | str | "I'm sorry, I can't respond to that." | Replacement text when blocked. |
CallControl
on_message handlers. Allows dynamic call management during a conversation.
| Method | Description |
|---|---|
await transfer(number: str) | Transfer the call to another phone number. |
await hangup() | End the call. |
| Property | Type | Description |
|---|---|---|
is_transferred | bool | Whether a transfer was requested. |
is_hung_up | bool | Whether a hangup was requested. |
ended | bool | True if transferred or hung up. |
CallMetrics
CostBreakdown
LatencyBreakdown
TurnMetrics
Exceptions
All exceptions inherit fromPatterError.
PatterError
Base exception for all Patter SDK errors.PatterConnectionError
Raised for connection failures or missing required parameters.Exports
All public symbols exported from thepatter package:

