Documentation Index
Fetch the complete documentation index at: https://patter-06b046ce-docs-fix-logo-and-home-icon.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
API Reference
Complete reference for all types, interfaces, and exports in the patter package.
Patter Class
Constructor
new Patter(options: LocalOptions)
Instance Methods
| Method | Signature | Description |
|---|
agent | (opts: AgentOptions) => AgentOptions | Validates and returns an agent configuration. |
serve | (opts: ServeOptions) => Promise<void> | Starts the embedded server (local mode only). |
call | (opts: LocalCallOptions) => Promise<void> | Makes an outbound call. |
test | (agent: AgentOptions, opts?: TestOptions) => Promise<void> | Starts an interactive terminal test session (local mode only). See Test Mode. |
Static Methods
| Method | Signature | Description |
|---|
Patter.deepgram | (opts: { apiKey: string; language?: string }) => STTConfig | Creates a Deepgram STT config. |
Patter.whisper | (opts: { apiKey: string; language?: string }) => STTConfig | Creates a Whisper STT config. |
Patter.elevenlabs | (opts: { apiKey: string; voice?: string }) => TTSConfig | Creates an ElevenLabs TTS config. |
Patter.openaiTts | (opts: { apiKey: string; voice?: string }) => TTSConfig | Creates an OpenAI TTS config. |
Patter.guardrail | (opts: { name: string; blockedTerms?: string[]; check?: (text: string) => boolean; replacement?: string }) => Guardrail | Creates a guardrail config. |
Patter.tool | (opts: { name: string; description?: string; parameters?: object; handler?: Function; webhookUrl?: string }) => ToolDefinition | Creates a tool definition. Requires either handler or webhookUrl. |
Interfaces
LocalOptions
interface LocalOptions {
mode: "local";
twilioSid?: string;
twilioToken?: string;
openaiKey?: string;
phoneNumber: string;
webhookUrl: string;
telephonyProvider?: "twilio" | "telnyx";
telnyxKey?: string;
telnyxConnectionId?: string;
telnyxPublicKey?: string;
pricing?: Record<string, Partial<ProviderPricing>>;
}
AgentOptions
interface AgentOptions {
systemPrompt: string;
voice?: string;
model?: string;
language?: string;
firstMessage?: string;
tools?: ToolDefinition[];
provider?: "openai_realtime" | "elevenlabs_convai" | "pipeline";
elevenlabsKey?: string;
elevenlabsAgentId?: string;
deepgramKey?: string;
stt?: STTConfig;
tts?: TTSConfig;
variables?: Record<string, string>;
guardrails?: Guardrail[];
}
ServeOptions
interface ServeOptions {
agent: AgentOptions;
port?: number;
onCallStart?: (data: Record<string, unknown>) => Promise<void>;
onCallEnd?: (data: Record<string, unknown>) => Promise<void>;
onTranscript?: (data: Record<string, unknown>) => Promise<void>;
onMessage?: PipelineMessageHandler | string;
onMetrics?: (data: Record<string, unknown>) => Promise<void>;
recording?: boolean;
voicemailMessage?: string;
dashboard?: boolean;
dashboardToken?: string;
}
LocalCallOptions
interface LocalCallOptions {
to: string;
agent: AgentOptions;
machineDetection?: boolean;
voicemailMessage?: string;
variables?: Record<string, string>;
}
interface ToolDefinition {
name: string;
description: string;
parameters: Record<string, unknown>;
webhookUrl: string;
}
Guardrail
interface Guardrail {
name: string;
blockedTerms?: string[];
check?: (text: string) => boolean;
replacement?: string;
}
STTConfig
interface STTConfig {
readonly provider: string;
readonly apiKey: string;
readonly language: string;
toDict(): Record<string, string>;
}
TTSConfig
interface TTSConfig {
readonly provider: string;
readonly apiKey: string;
readonly voice: string;
toDict(): Record<string, string>;
}
IncomingMessage
interface IncomingMessage {
readonly text: string;
readonly callId: string;
readonly caller: string;
}
CallControl
interface CallControl {
readonly callId: string;
readonly caller: string;
readonly callee: string;
readonly telephonyProvider: string;
transfer(number: string): Promise<void>;
hangup(): Promise<void>;
readonly isTransferred: boolean;
readonly isHungUp: boolean;
readonly ended: boolean;
}
Passed as the second argument to onMessage handlers. Allows dynamic call management during a conversation.
CallMetrics
interface CallMetrics {
callId: string;
durationSeconds: number;
turns: TurnMetrics[];
cost: CostBreakdown;
latencyAvg: LatencyBreakdown;
latencyP95: LatencyBreakdown;
providerMode: string;
sttProvider: string;
ttsProvider: string;
telephonyProvider: string;
}
CostBreakdown
interface CostBreakdown {
stt: number;
tts: number;
llm: number;
telephony: number;
total: number;
}
LatencyBreakdown
interface LatencyBreakdown {
sttMs: number;
llmMs: number;
ttsMs: number;
totalMs: number;
}
TurnMetrics
interface TurnMetrics {
turnIndex: number;
userText: string;
agentText: string;
latency: LatencyBreakdown;
sttAudioSeconds: number;
ttsCharacters: number;
timestamp: number;
}
ProviderPricing
interface ProviderPricing {
unit: string;
price?: number;
audio_input_per_token?: number;
audio_output_per_token?: number;
text_input_per_token?: number;
text_output_per_token?: number;
}
Type Aliases
type CallEventHandler = (data: Record<string, unknown>) => Promise<void>;
type PipelineMessageHandler = (data: Record<string, unknown>) => Promise<string>;
Error Classes
All errors extend PatterError, which extends the native Error class.
| Class | Description |
|---|
PatterError | Base error class for all SDK errors. |
PatterConnectionError | WebSocket connection failures or disconnection errors. |
import {
PatterError,
PatterConnectionError,
} from "getpatter";
try {
await phone.call({ to: "+15559876543", agent });
} catch (error) {
if (error instanceof PatterConnectionError) {
console.error("Connection issue:", error.message);
}
}
Exports
Classes
export { Patter } from "getpatter";
export { ElevenLabsConvAIAdapter } from "getpatter";
export { OpenAIRealtimeAdapter } from "getpatter";
export { DeepgramSTT } from "getpatter";
export { WhisperSTT } from "getpatter";
export { ElevenLabsTTS } from "getpatter";
export { OpenAITTS } from "getpatter";
Error Classes
export {
PatterError,
PatterConnectionError,
} from "getpatter";
Factory Functions
export { deepgram, whisper, elevenlabs, openaiTts } from "getpatter";
Transcoding Utilities
export {
mulawToPcm16,
pcm16ToMulaw,
resample8kTo16k,
resample16kTo8k,
resample24kTo16k,
} from "getpatter";
All Type Exports
export type {
IncomingMessage,
STTConfig,
TTSConfig,
LocalOptions,
AgentOptions,
ServeOptions,
LocalCallOptions,
CallEventHandler,
PipelineMessageHandler,
ToolDefinition,
Guardrail,
LocalConfig,
CallControl,
CallMetrics,
CostBreakdown,
LatencyBreakdown,
TurnMetrics,
ProviderPricing,
} from "getpatter";