Metrics & Cost Tracking
Patter automatically tracks cost and latency for every call, broken down by provider component (STT, TTS, LLM, telephony).
How It Works
Metrics are collected automatically during calls. When a call ends, the onCallEnd callback receives a CallMetrics object with the full breakdown:
await phone.serve(agent, {
port: 8000,
onCallEnd: async (event) => {
const metrics = event.metrics;
if (metrics) {
console.log(`Duration: ${metrics.durationSeconds}s`);
console.log(`Total cost: $${metrics.cost.total.toFixed(4)}`);
console.log(` STT: $${metrics.cost.stt.toFixed(4)}`);
console.log(` TTS: $${metrics.cost.tts.toFixed(4)}`);
console.log(` LLM: $${metrics.cost.llm.toFixed(4)}`);
console.log(` Telephony: $${metrics.cost.telephony.toFixed(4)}`);
console.log(`Avg latency: ${metrics.latencyAvg.totalMs}ms`);
console.log(`P95 latency: ${metrics.latencyP95.totalMs}ms`);
}
},
});
Cost Breakdown
The CostBreakdown object provides per-component costs in USD:
| Field | Description |
|---|
stt | Speech-to-text cost (Deepgram, Whisper). |
tts | Text-to-speech cost (ElevenLabs, OpenAI TTS). |
llm | LLM cost (OpenAI Realtime tokens). |
telephony | Telephony cost (Twilio, Telnyx per-minute). |
total | Sum of all components. |
Latency Breakdown
The LatencyBreakdown object provides per-component latency in milliseconds:
| Field | Description |
|---|
sttMs | Time from user speech to transcript. |
llmMs | Time from transcript to LLM response. |
ttsMs | Time from LLM response to first audio byte. |
totalMs | End-to-end latency (user speech to first audio). |
Both latencyAvg and latencyP95 are available on CallMetrics.
Per-Turn Metrics
Each conversation turn is tracked individually:
await phone.serve(agent, {
port: 8000,
onCallEnd: async (event) => {
const metrics = event.metrics;
if (metrics) {
for (const turn of metrics.turns) {
console.log(`Turn ${turn.turnIndex}:`);
console.log(` User: ${turn.userText}`);
console.log(` Agent: ${turn.agentText}`);
console.log(` Latency: ${turn.latency.totalMs}ms`);
}
}
},
});
Custom Pricing
Override default provider pricing estimates:
const phone = new Patter({
openaiKey: "sk-...",
mode: "local",
pricing: {
deepgram: { price: 0.005 }, // Override STT price per minute
elevenlabs: { price: 0.15 }, // Override TTS price per 1k chars
twilio: { price: 0.015 }, // Override telephony price per minute
},
});
Default Pricing
| Provider | Unit | Default Price |
|---|
| Deepgram | per minute | $0.0043 |
| Whisper | per minute | $0.006 |
| ElevenLabs | per 1k chars | $0.18 |
| OpenAI TTS | per 1k chars | $0.015 |
| OpenAI Realtime | per token | varies by type |
| Twilio | per minute | $0.013 |
| Telnyx | per minute | $0.007 |
Default pricing is based on publicly listed provider rates and may become stale. Pass your own overrides for accurate cost tracking, or check the provider’s pricing page.
Real-Time Metrics
Use the onMetrics callback for live cost updates during a call:
await phone.serve(agent, {
port: 8000,
onMetrics: async (data) => {
const cost = data.costSoFar;
if (cost) {
console.log(`Running cost: $${cost.total.toFixed(4)}`);
}
},
});
Data Types
import type {
CallMetrics,
CostBreakdown,
LatencyBreakdown,
TurnMetrics,
} from "@patter-dev/sdk";
CallMetrics
| Field | Type | Description |
|---|
callId | string | Unique call identifier. |
durationSeconds | number | Total call duration. |
turns | TurnMetrics[] | Per-turn metrics. |
cost | CostBreakdown | Cost breakdown. |
latencyAvg | LatencyBreakdown | Average latency. |
latencyP95 | LatencyBreakdown | 95th percentile latency. |
providerMode | string | Voice mode used. |
sttProvider | string | STT provider name. |
ttsProvider | string | TTS provider name. |
telephonyProvider | string | Telephony provider name. |
TurnMetrics
| Field | Type | Description |
|---|
turnIndex | number | Zero-based turn index. |
userText | string | What the user said. |
agentText | string | What the agent replied. |
latency | LatencyBreakdown | Latency for this turn. |
sttAudioSeconds | number | Audio duration processed by STT. |
ttsCharacters | number | Characters synthesized by TTS. |
timestamp | number | Unix timestamp. |