# Phone: give an agent a phone number, or bring your own agent

Source: https://docs.autessa.com/docs/features/phone

> Put an AI agent on a phone number. Autessa handles numbers, calls, speech, the firewall voice check, and redaction after the call; the brain can be an Autessa agent or your own over a websocket.

# Phone

Put an AI agent on a real phone number. Autessa handles the number, the call, speech, and safety checks. The agent can be one you build in Autessa, or your own agent connected over a websocket.

**Status:** phone numbers and Autessa agents on calls are live in the Builder. The phone API and "use your own agent" are (Preview).

## When to use it

- You want an AI receptionist or support line without running telephony.
- You already have an agent (Pipecat, LiveKit, or your own code) and want it to answer a phone number.
- You want cloned-voice checks and PCI-safe recordings on every call.

## Quickstart: an Autessa agent on a number

1. In the Builder, open [Phone Numbers](/docs/guide/agentic/phone-numbers.md) and get a number.
2. Route the number to an agent.
3. Call it.

A call's id works with `transfer_call` for as long as the call is live. Your agent's address must be `wss://` on port 443.

## Quickstart: your own agent (Preview)

1. [Get a free API key](https://builder.autessa.com/get-api-key) as a company admin (you are one in the personal company you get at signup), or create an API key in **Settings → API keys** with the **Phone numbers** permission. New accounts get $100 of free credits for your first month. See [Keys](/docs/start/keys.md).
2. Find and buy a number: `POST /clients/phone/numbers/search`, then `POST /clients/phone/numbers/purchase`.
3. Route it to your websocket: `POST /clients/phone/numbers/{numberId}/routing`.

**curl:**

```bash
curl -X POST https://api.autessa.com/clients/phone/numbers/V1StGXR8Z5/routing \
  -H "Authorization: $AUTESSA_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "routingType": "EXTERNAL_AGENT",
    "externalAgent": {
      "url": "wss://agent.example.com/phone",
      "mode": "TEXT",
      "greeting": "Thanks for calling. How can I help?",
      "firewall": true,
      "redactAfterCall": true
    }
  }'
```

**Python:**

```python
# A TEXT-mode agent: Autessa does speech-to-text and text-to-speech.
# pip install websockets anthropic
import asyncio, json
import anthropic
import websockets

claude = anthropic.AsyncAnthropic()

async def handle(ws):
    history = []
    async for raw in ws:
        msg = json.loads(raw)
        if msg["event"] == "prompt" and msg.get("final"):
            history.append({"role": "user", "content": msg["text"]})
            reply = await claude.messages.create(
                model="claude-opus-5-5", max_tokens=1024,
                system="You are a friendly phone receptionist. Keep answers to one or two short sentences.",
                messages=history,
            )
            text = next(b.text for b in reply.content if b.type == "text")
            history.append({"role": "assistant", "content": text})
            await ws.send(json.dumps({"event": "text", "text": text, "final": True}))
        elif msg["event"] == "stop":
            break

async def main():
    async with websockets.serve(handle, "0.0.0.0", 8765):
        await asyncio.Future()

asyncio.run(main())
```

**TypeScript:**

```typescript
// A TEXT-mode agent. npm i ws @anthropic-ai/sdk
import Anthropic from "@anthropic-ai/sdk";
import { WebSocketServer } from "ws";

const claude = new Anthropic();
new WebSocketServer({ port: 8765 }).on("connection", (ws) => {
  const history: Anthropic.MessageParam[] = [];
  ws.on("message", async (raw) => {
    const msg = JSON.parse(raw.toString());
    if (msg.event !== "prompt" || !msg.final) return;
    history.push({ role: "user", content: msg.text });
    const reply = await claude.messages.create({
      model: "claude-opus-5-5",
      max_tokens: 1024,
      system: "You are a friendly phone receptionist. Keep answers short.",
      messages: history,
    });
    const text = reply.content.find((b) => b.type === "text")?.text ?? "";
    history.push({ role: "assistant", content: text });
    ws.send(JSON.stringify({ event: "text", text, final: true }));
  });
});
```

**Java:**

```java
var body = """
    {"routingType": "EXTERNAL_AGENT",
     "externalAgent": {"url": "wss://agent.example.com/phone", "mode": "AUDIO",
                       "firewall": true, "redactAfterCall": true}}
    """;
var req = java.net.http.HttpRequest.newBuilder(java.net.URI.create(
        "https://api.autessa.com/clients/phone/numbers/V1StGXR8Z5/routing"))
    .header("Authorization", System.getenv("AUTESSA_API_KEY"))
    .header("Content-Type", "application/json")
    .POST(java.net.http.HttpRequest.BodyPublishers.ofString(body))
    .build();
System.out.println(java.net.http.HttpClient.newHttpClient()
    .send(req, java.net.http.HttpResponse.BodyHandlers.ofString()).body());
```

## How it works

Pick a mode for your own agent:

| Mode | Autessa does | Your agent does |
| --- | --- | --- |
| `TEXT` | Phone call, speech-to-text, text-to-speech, turn-taking. | Reads `prompt` text, sends `text` replies. |
| `AUDIO` | Phone call only. Streams 8 kHz mu-law audio both ways. | Its own speech, model, and voice. Good for Pipecat or LiveKit. |

**Messages Autessa sends** (JSON text frames, each with an `event`): `start` (with `callId`) at the start of every call, `media` (base64 mu-law audio in `payloadB64`, AUDIO mode), `prompt` (the caller's words in `text`, with `final`, TEXT mode), `dtmf` (a keypad `digit`), and `stop` when the call ends.

**Messages you send back:** `text` (with `text` and `final`, TEXT mode), `media` (base64 audio in `payloadB64`, AUDIO mode), `clear` (stop playing queued audio, AUDIO mode), `mark` (a named marker in the audio, AUDIO mode), `transfer` (with `to`, another number), and `hangup`.

**Auth:** set `authSecretName` to the name of an Autessa Secret. Its value arrives as `auth` in the `start` message so your server can check it. Saving the routing adds the phone number to the secret's [What can use it](/docs/guide/agentic/secrets.md#what-can-use-a-secret) list if you have **Use** on it, and it keeps working while the person who set up the routing has Use.

**Other options:** `greeting` sets what callers hear first. `voice` sets the voice Autessa speaks with in TEXT mode.

**Safety extras:** `firewall: true` runs the cloned-voice check on caller audio. `redactAfterCall: true` runs [SecurePass](/docs/features/securepass.md) on the recording after the call. In TEXT mode, `firewall: false` turns the voice check off; leave it unset to keep the default.

**Stuck recordings:** if a call's recording can't be redacted after its tries, the unredacted original stays at the phone carrier and company admins see it under **Configure → Stuck recordings**. From there they can run redaction again or delete the original. Every action is recorded.

For Pipecat, `pipecat-autessa-phone` provides `AutessaPhoneTransport`, which connects a pipeline to a number in AUDIO mode (Preview). See [Pipecat](/docs/integrations/pipecat.md).

## Libraries

| Language | Package | Call |
| --- | --- | --- |
| Python | `autessa-phone` | `Phone().setup_assistant(agent_id=... or external_agent=..., area_code=...)`, `connect_external_agent(number_id, url, mode="AUDIO")`, `list_numbers()` |
| TypeScript | `@autessa/phone` | `new Phone().setupAssistant({ agentId } or { externalAgent }, ...)`, `connectExternalAgent({ numberId, url, mode })`, `listNumbers()` |
| Java | `com.autessa:autessa-phone` | `Phone.fromEnv().setupAssistant(AssistantSetup.externalAgent(url))`, `connectExternalAgent(numberId, url, mode)`, `routeToAgent(numberId, agentId)`, `listNumbers()` |

`setup_assistant` (`setupAssistant`) finds a number, buys it, and routes it in one step. The libraries also parse and build the websocket messages for your server: `autessa.phone.protocol` in Python (`parse_message`, `text`, `media`, `transfer`, `hangup`, `check_auth`), `parseServerMessage` and `reply` in TypeScript, and `CallProtocol` in Java.

```python
from autessa.phone import Phone

phone = Phone()  # reads AUTESSA_API_KEY; buying numbers needs Phone numbers
number = phone.setup_assistant(
    external_agent={"url": "wss://agent.example.com/phone", "mode": "TEXT", "firewall": True},
    area_code="206",
)
print("Call", number.phone_number)
```

The libraries are in private preview and not yet on PyPI, npm, or Maven Central. Install from GitHub as each library's README describes, for example:

```bash
pip install "autessa-core @ git+https://github.com/Autessa-Inc/autessa-python#subdirectory=packages/autessa-core"
pip install "autessa-phone @ git+https://github.com/Autessa-Inc/autessa-python#subdirectory=packages/autessa-phone"
```

## Limits

- Audio in AUDIO mode is 8 kHz mu-law.
- Buying numbers needs the **Phone numbers** key permission.
- Numbers and call minutes are billed to your company. See [Billing](/docs/start/billing.md).

## Pricing

Your own agent on a call is priced per minute, by mode:

| Mode | Price |
| --- | --- |
| Audio | $0.03/min |
| Text | $0.07/min |

LLM tasks use normal AI task pricing. Usage goes on your month-end invoice. See [Billing](/docs/start/billing.md).

## API reference

[Phone API](/docs/reference/phone.md)

## Benchmarks

Calls with `redactAfterCall` use SecurePass. See [SecurePass Bench](/docs/benchmarks/securepass-bench.md).

## Example

- [Pipecat payment line](https://github.com/Autessa-Inc/autessa-examples/tree/main/examples/pipecat-payment-line): a Pipecat voice bot that can answer an Autessa phone number with `AutessaPhoneTransport` (Preview).

## Related

- [Phone Numbers](/docs/guide/agentic/phone-numbers.md)
- [Pipecat integration](/docs/integrations/pipecat.md)
- [AI Application Firewall](/docs/features/ai-application-firewall.md)
- [SecurePass](/docs/features/securepass.md)

