Skip to main content

Python Quickstart

This guide walks you through building a voice AI agent that answers phone calls using local/self-hosted mode.

Prerequisites

  • Python 3.11+
  • A telephony account (Twilio or Telnyx)
  • An AI provider key (OpenAI, ElevenLabs, or Deepgram)

Step 1: Install the SDK

pip install patter[local]

Step 2: Set Up Credentials

Create a .env file in your project root:
TWILIO_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TWILIO_TOKEN=your_auth_token
OPENAI_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxx
PHONE_NUMBER=+15550001234
WEBHOOK_URL=abc.ngrok.io

Step 3: Expose Your Server

Patter needs a public URL so Twilio/Telnyx can reach your local server. Use ngrok:
ngrok http 8000
Copy the hostname (e.g., abc.ngrok.io) and use it as your WEBHOOK_URL.

Step 4: Write Your Agent

import os
import asyncio
from dotenv import load_dotenv
from patter import Patter

load_dotenv()

phone = Patter(
    twilio_sid=os.environ["TWILIO_SID"],
    twilio_token=os.environ["TWILIO_TOKEN"],
    openai_key=os.environ["OPENAI_KEY"],
    phone_number=os.environ["PHONE_NUMBER"],
    webhook_url=os.environ["WEBHOOK_URL"],
)

agent = phone.agent(
    system_prompt="You are a helpful assistant for a pizza restaurant. Help customers place orders and answer questions about the menu.",
    voice="alloy",
    first_message="Hi! Welcome to Pizza Palace. What can I get for you today?",
)

async def main():
    await phone.serve(agent, port=8000)

asyncio.run(main())

Step 5: Make a Call

Call your PHONE_NUMBER from any phone. The AI agent will answer and start the conversation.

What’s Next

Configuration

Explore all constructor options and modes.

Agents

Customize voice, model, and behavior.

Tools

Add function calling to your agent.

Events

Handle call start, end, and transcript events.