TypeScript SDK
The official AgentPhone TypeScript library provides server-side access to the API. Examples below are checked against the published agentphone@1.0.25. Some endpoints return unknown; inspect or validate those results before accessing fields. Keep your API key on the server.
Installation
Set AGENTPHONE_API_KEY in the server process before running examples.
Quick start
Request and response types
The SDK exports all request and response types under the AgentPhone namespace:
The published 1.0.25 SDK omits limit from several list-request types. Use requestOptions.queryParams as shown below to pass that REST parameter. Method names and request fields differ from the Python SDK; do not copy Python calls into TypeScript.
The quick start buys a number and places a real call. See pricing and outbound calling requirements before running it. Use a recipient you control.
Resources
Agents
Numbers
Conversations
Calls
Webhooks
Usage
Error handling
Streaming transcripts
In agentphone@1.0.25, calls.streamCallTranscript reads the SSE response as JSON instead of exposing live events. Use the HTTP streaming examples until the package provides a corrected stream interface.
Recording downloads
In agentphone@1.0.25, calls.getCallRecording treats the audio response as JSON and does not return usable recording bytes. Download the recordingUrl with ordinary HTTP instead; see Call recording. Treat that URL as a sensitive bearer link.
Advanced
Retries
The SDK defaults to two retries on 408, 429, and 5xx, including writes. The examples set maxRetries: 0 because a timed-out send, purchase, or call may already have executed. Enable bounded retries on safe reads individually; do not automatically resend an ambiguous write. See Error handling.
Timeouts
Default timeout is 60 seconds.
Abort requests
Raw response access
Logging
Runtime compatibility
The SDK works in Node.js 18+, Vercel, Cloudflare Workers, Deno 1.25+, Bun 1.0+, and React Native.

