API Reference
Complete reference for all types, interfaces, and exports in thegetpatter package.
Patter Class
Constructor
| Parameter | Type | Required | Description |
|---|---|---|---|
carrier | Twilio | Telnyx | Yes | Carrier instance. Reads credentials from env vars when arguments are omitted. |
phoneNumber | string | Yes | Phone number in E.164 format. |
webhookUrl | string | Conditional | Public hostname, no scheme. Required unless using tunnel: true in serve(). |
tunnel | CloudflareTunnel | StaticTunnel | boolean | No | Tunnel directive. true is shorthand for new CloudflareTunnel(). |
pricing | Record<string, Partial<ProviderPricing>> | No | Custom pricing overrides. |
persist | boolean | string | No | Persist the dashboard’s call history to disk. Defaults to ON since 0.6.2 — pass persist: false to disable. See Configuration. |
Instance Methods
| Method | Signature | Description |
|---|---|---|
agent | (opts: AgentOptions) => Agent | Validates and returns an agent configuration. |
serve | (opts: ServeOptions) => Promise<void> | Starts the embedded server. |
call | (opts: LocalCallOptions) => Promise<void> | Makes an outbound call. |
test | (opts: ServeOptions) => Promise<void> | Starts an interactive terminal test session. See Test Mode. |
disconnect | () => Promise<void> | Stops the tunnel, embedded server, and WebSocket connection. |
Carriers
Twilio
Telnyx
Engines
OpenAIRealtime
OpenAIRealtime2
OpenAIRealtime2Adapter and speaks the GA session.update wire shape (output_modalities, nested audio.{input,output}, session.type = "realtime"). GA session config pins turn_detection.create_response: false and interrupt_response: false so Patter owns response creation and barge-in cancellation. See OpenAIRealtime2.
ElevenLabsConvAI
STT classes
apiKey?: string and falls back to the provider’s standard env var. See the STT page for full constructor signatures.
TTS classes
apiKey?: string and falls back to the provider’s standard env var. See the TTS page for full constructor signatures.
LLM classes
apiKey?: string and falls back to the provider’s standard env var (GoogleLLM prefers GEMINI_API_KEY, falls back to GOOGLE_API_KEY). Pass an instance via phone.agent({ llm }) for pipeline mode. llm is mutually exclusive with onMessage on serve() and is ignored when engine is set. See the LLM page for full constructor signatures.
Tunnels
| Class | Behavior |
|---|---|
new CloudflareTunnel() | Auto-start a Cloudflare Quick Tunnel via the local cloudflared binary. |
new StaticTunnel({ hostname }) | Use an existing public hostname (user-managed tunnel). |
tunnel: true on new Patter(...) or phone.serve(...) is shorthand for new CloudflareTunnel().
Tools & Guardrails
Tool
handler or webhookUrl must be provided.
Guardrail
Interfaces
AgentOptions
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.
ServeOptions
localRecording 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 onCallEnd payload. Independent of the carrier-side recording flag. See Local Recording.
LocalCallOptions
ToolDefinition
IncomingMessage
CallControl
CallMetrics / CostBreakdown / LatencyBreakdown / TurnMetrics / ProviderPricing
See Metrics for the full shapes.Error Classes
All errors extendPatterError, which extends the native Error class.
| Class | Description |
|---|---|
PatterError | Base error class for all SDK errors. |
PatterConnectionError | WebSocket connection failures or disconnection errors. |
AuthenticationError | Invalid or missing API key. |
ProvisionError | Failures when provisioning resources (numbers, agents, calls). |
RateLimitError | Provider returned HTTP 429 on connect/upgrade. Extends PatterConnectionError. |
ErrorCode
Every Patter exception carries a stable, machine-readablecode property. Branch on the code instead of class-name strings:
const object plus value-union type (not a TS enum) so it is tree-shakeable and compatible with verbatimModuleSyntax. Mirrored byte-for-byte by the Python ErrorCode StrEnum.
Top-level exports
getpatter.
