# Phone numbers

> Buy a real phone number or bring your own, have an agent answer its calls, and have it call people with a goal.

A **phone number** you buy through NoClick rings one of your agents. The agent talks with the caller in a natural voice and can use its tools during the call. It can also place calls, working toward a goal you give it, and you get the transcript when it hangs up.

Want a line that answers your own business's calls, set up for you by texting NoClick? See the [answering service](https://www.noclick.com/answering-service).

Every number you hold is one `PhoneNumber`, however you got it: bought here, in the NoClick app (Resources, a Phone step's setup, a purchase link or a card in the chat), or ported in. `PhoneNumber.list()` and the console show them all, and each can do everything on this page. One bought in the app is your account's own (no `user_id`), with `source` `bought` and no `name` until you give it one.

You can buy numbers in every country NoClick sells in: local, mobile, toll-free and national numbers, wherever each is sold. Each number has its own price, billed monthly, plus a one-time cost where the carrier charges one. Finding numbers and their prices is free and needs no funds, though like every call here it takes a key with the `phone` scope (`available`, `coverage` and `places` included; without it they raise `noclick.PermissionDenied`). Buying one needs at least $5 of funds your account added (what your plan includes doesn't count), on any plan, and so does a quote for one, the first step of a purchase an agent makes through [MCP](https://www.noclick.com/docs/guide/mcp.md). Below it they raise `noclick.PaymentRequired`: its `next_step` says where to add funds, and its `offers` are links a person opens to pay. Where numbers aren't enabled on your account yet, they raise `noclick.NotAvailable`. A number you already have can answer too: see [Bring your own number](https://www.noclick.com/docs/guide/phone-numbers.md#bring-your-own-number).

## Buy a number

```python
import noclick

[pick] = noclick.PhoneNumber.available(country="US", area_code="415", limit=1)
print(pick.number, pick.locality, pick.monthly_usd, pick.upfront_usd)

number = noclick.PhoneNumber.buy(pick, max_monthly_usd=5)
```

```ts
import { PhoneNumber } from "noclick";

const [pick] = await PhoneNumber.available({ country: "US", areaCode: "415", limit: 1 });
console.log(pick.number, pick.locality, pick.monthlyUsd, pick.upfrontUsd);

const number = await PhoneNumber.buy(pick, { maxMonthlyUsd: 5 });
```

`monthly_usd` is what the number costs a month and `upfront_usd` what it costs once, when it's bought: the carrier's price for that number (a US local number is $1.00 a month and $1.00 once today). Both are charged when you buy it, and the number keeps its monthly price for as long as you hold it. `max_monthly_usd` is your ceiling on the month and `max_upfront_usd` on the one-time cost (by default, the `upfront_usd` the number you picked showed): above either, the purchase fails with `noclick.PriceExceeded` and nothing is bought.

### Find one anywhere

`available` searches one country at a time (`country`, `US` by default) for one kind of number (`type`: `local` by default, or `mobile`, `toll_free`, `national` or `shared_cost`), narrowed by any of:

- `area_code`, `locality` (a city) or `region` (a state or province);
- `contains` (digits you want, letters for their keypad digits, or `*` for any digit), `starts_with` or `ends_with` (digits of the number after its country code);
- `features`: `voice` (takes calls, the default) or `voice_sms` (calls and texts).

```python
for country in noclick.PhoneNumber.coverage():
    print(country.country, country.types)          # where numbers are sold, and which kinds

places = noclick.PhoneNumber.places("GB")           # the cities with numbers for sale
london = noclick.PhoneNumber.available(country="GB", locality="London", contains="2024")
```

```ts
import { PhoneNumber } from "noclick";

for (const country of await PhoneNumber.coverage()) {
  console.log(country.country, country.types);          // where numbers are sold, and which kinds
}

const places = await PhoneNumber.places("GB");           // the cities with numbers for sale
const london = await PhoneNumber.available({ country: "GB", locality: "London", contains: "2024" });
```

`places` lists cities, or area codes in the US and Canada, with numbers of a kind for sale.

### What a country asks first

Many countries ask who holds a number before it's sold: an address, an ID, proof of address, a company registration. Each result says what its country asks in `requirements`: `needs` is `none`, `address`, `documents` or `steps`, and `items` lists each thing asked, with its `id`, `kind` (`address`, `contact`, `textual`, `document` or `step`), `name`, `description`, the carrier's `example` and, for a textual one that takes only some answers, those `values`.

- `none` (the US and Canada, among others): buy it straight away.
- `address`: pass the holder's name and address to `buy`, and NoClick files it with the carrier. Where a requirement's `kind` is `contact` (the holder's contact information, as for mobile numbers in the Netherlands and Mexico), pass a `phone` to reach them on, in E.164, too. The carrier checks it; if it refuses the address, nothing is bought and nothing is charged.
- `documents`: upload each document first, then pass the holder (where it's asked) and `requirements` to `buy`: each textual and document requirement's answer by its `id`. The carrier reviews what you filed, which can take a few days, so `buy` returns a `PhoneNumberOrder` rather than the number.
- `steps`: the country asks for a step the carrier takes with the holder itself (an identity check at its own link, a company it approved first). These numbers are listed, but can't be bought through NoClick yet; `buy` raises `noclick.NotAvailable`.

```python
holder = noclick.NumberHolder(name="Dana Ruiz", street="Keizersgracht 1", city="Amsterdam",
                              postal_code="1015 CJ", country="NL", phone="+31612345670")
noclick.PhoneNumber.buy(pick, max_monthly_usd=5, address=holder)
```

```ts
import { PhoneNumber, type NumberHolder } from "noclick";

const holder: NumberHolder = {
  name: "Dana Ruiz", street: "Keizersgracht 1", city: "Amsterdam",
  postalCode: "1015 CJ", country: "NL", phone: "+31612345670",
};
await PhoneNumber.buy(pick, { maxMonthlyUsd: 5, address: holder });
```

#### File the holder once

Keep the holder on file instead of in every call: a holder profile is the holder's details, their answers to what numbers' countries ask (by requirement id), and when they accepted having them filed with the carrier in their name. Your account has one, and so can each user (`user=`). A purchase files it with `holder_on_file`, taking the answers its number's country asks; with none on file it raises `noclick.ActionRequired`:

```python
noclick.PhoneNumber.set_holder_profile(holder, accepted_at=accepted_at)   # when Dana agreed to it
noclick.PhoneNumber.buy(pick, max_monthly_usd=5, holder_on_file=True)
```

```ts
import { PhoneNumber } from "noclick";

await PhoneNumber.setHolderProfile(holder, { acceptedAt });
await PhoneNumber.buy(pick, { maxMonthlyUsd: 5, holderOnFile: true });
```

Over HTTP it's `PUT /v1/phone_numbers/holder` (`GET` reads it, `DELETE` clears it), from your server or signed in: never an agent connected through MCP, and never an app's code. An app's code buying a number that files a holder waits for your account's owner by default; where your approval settings make `person_filing` standing, a purchase the profile covers runs with no one asked, and one it doesn't is refused naming the call that files it ([policy](https://www.noclick.com/docs/guide/policy.md#terms-and-filings-kept-on-file)).

`coverage()` says which kinds each country sells this way: `documents_types` are bought with documents, `steps_types` can't be bought here yet.

### Numbers bought with documents

`upload_document` sends a file (a PDF, PNG or JPEG, up to 20 MB) to the carrier for one requirement; the carrier holds it, and NoClick keeps only its name and what it's for. Name it in `requirements` within 25 minutes; once a purchase has named it, it can be named again for your next number.

```python
[pick] = noclick.PhoneNumber.available(country="IT", limit=1)
asked = {item["name"]: item for item in pick.requirements["items"]}
passport = noclick.PhoneNumber.upload_document(
    "passport.pdf", requirement=asked["Identity Document"], country="IT")
giulia = noclick.NumberHolder(name="Giulia Rossi", street="Via Roma 1", city="Milano",
                              postal_code="20121", country="IT", phone="+393471234567")
order = noclick.PhoneNumber.buy(
    pick, max_monthly_usd=5, max_upfront_usd=5, address=giulia,
    requirements={asked["Identity Document Type"]["id"]: "Passport",
                  asked["Identity Document"]["id"]: passport},
)
print(order.status)          # in_review
```

```ts
import { readFile } from "node:fs/promises";
import { PhoneNumber, PhoneNumberOrder, type NumberHolder } from "noclick";

const [pick] = await PhoneNumber.available({ country: "IT", limit: 1 });
const asked = Object.fromEntries((pick.requirements?.items ?? []).map((item) => [item.name, item]));
const passport = await PhoneNumber.uploadDocument(await readFile("passport.pdf"), {
  filename: "passport.pdf", requirement: asked["Identity Document"], country: "IT",
});
const giulia: NumberHolder = {
  name: "Giulia Rossi", street: "Via Roma 1", city: "Milano",
  postalCode: "20121", country: "IT", phone: "+393471234567",
};
const order = await PhoneNumber.buy(pick, {
  maxMonthlyUsd: 5, maxUpfrontUsd: 5, address: giulia,
  requirements: {
    [asked["Identity Document Type"].id]: "Passport",
    [asked["Identity Document"].id]: passport,
  },
});
if (order instanceof PhoneNumberOrder) {
  console.log(order.status);          // in_review
}
```

Nothing is charged while the order is in review. Its `status` follows the carrier:

- `in_review`: the carrier is checking what you filed.
- `rejected`: it sent the order back; `reason` is its words and `deadline` when the correction is due. `resubmit` files corrected answers (new uploads, a fixed address) on the same order, and it's `in_review` again.
- `completed`: the number is yours, its first month and any one-time cost are charged now, and `phone_number()` returns it.
- `failed`: it ended without the number (cancelled, or nobody corrected it in time). Nothing was charged.

```python
order = noclick.PhoneNumberOrder.retrieve(order.id)
if order.status == "rejected":
    clearer = noclick.PhoneNumber.upload_document(
        "passport-full.pdf", requirement=asked["Identity Document"], country="IT")
    order.resubmit(address=giulia, requirements={asked["Identity Document Type"]["id"]: "Passport",
                                                 asked["Identity Document"]["id"]: clearer})
elif order.status == "completed":
    number = order.phone_number()
```

```ts
import { readFile } from "node:fs/promises";
import { PhoneNumber, PhoneNumberOrder } from "noclick";

const latest = await PhoneNumberOrder.retrieve(order.id);
if (latest.status === "rejected") {
  const clearer = await PhoneNumber.uploadDocument(await readFile("passport-full.pdf"), {
    filename: "passport-full.pdf", requirement: asked["Identity Document"], country: "IT",
  });
  await latest.resubmit({
    address: giulia,
    requirements: { [asked["Identity Document Type"].id]: "Passport", [asked["Identity Document"].id]: clearer },
  });
} else if (latest.status === "completed") {
  const number = await latest.phoneNumber();
}
```

Every number takes calls the same way, wherever it is. Texting differs by country, and each result's `texting` says which applies: `registration` (a US local number, which texts once your business is registered with the US carriers: see [Text the caller](https://www.noclick.com/docs/guide/phone-numbers.md#text-the-caller)), `unavailable` (texting from that country, or from a toll-free number, isn't available yet; its calls work) or `none` (the number can't text).

## Name it in your code

A number can have a name your code knows it by, unique among its user's numbers (`buy(..., name=...)`). `from_name` with `create_if_missing=True` owns one idempotently: the first run buys a local number in `area_code` (any US area code when you leave it out) for at most `max_monthly_usd` a month and `max_upfront_usd` once, and every run after finds the same number. `area_code` and the prices say how to buy it, so they matter only that first time; with `connect=`, a number of that name other than the one you name raises `noclick.Conflict`.

```python
number = noclick.PhoneNumber.from_name(
    "front-desk", create_if_missing=True, area_code="415", max_monthly_usd=5, max_upfront_usd=5,
)
number.update(name="reception")   # a new name; None removes it
```

```ts
import { PhoneNumber } from "noclick";

const number = PhoneNumber.fromName("front-desk", {
  createIfMissing: true, areaCode: "415", maxMonthlyUsd: 5, maxUpfrontUsd: 5,
});
await number.update({ name: "reception" });   // a new name; null removes it
```

A name another of the user's numbers has raises `noclick.Conflict` with that number's `existing_id`, before anything is bought, and a released number gives its name up. When no number is for sale in the area code, `from_name` raises `noclick.NotAvailable` and buys nothing. `record_calls=` passed to `from_name` sets [recording](https://www.noclick.com/docs/guide/phone-numbers.md#record-calls) every time it runs, and `connect=` owns [a number you keep with your own phone provider](https://www.noclick.com/docs/guide/phone-numbers.md#connect-a-number-you-keep-with-your-phone-provider) the same way.

## Answer calls with an agent

```python
receptionist = noclick.Agent.from_name(
    "receptionist",
    create_if_missing=True,
    instructions="You answer calls for Harbor Dental: opening hours, directions, and what to bring.",
    tools=["search"],
)
number.answer_with(receptionist)
```

```ts
import { Agent } from "noclick";

const receptionist = Agent.fromName("receptionist", {
  createIfMissing: true,
  instructions: "You answer calls for Harbor Dental: opening hours, directions, and what to bring.",
  tools: ["search"],
});
await number.answerWith(receptionist);
```

From then on, every call to the number reaches that agent. A number rings one agent at a time; calling `answer_with` again moves it. A number an automation's Phone step answers in the app rings that automation: `answer_with` raises `noclick.Conflict` naming it until its phone trigger is removed.

Once a call it answered ends, the agent reads the whole call again in a turn of its own, when nobody is on the line. If its tools give it a person's `notify` (`noclick.Human.owner().only("notify")`, or your user's), that turn has it and is told to tell them about the call in one short message: who called, why, and what it promised them. Its instructions can say otherwise, and a call with nothing to pass on (nobody spoke, a wrong number) gets no message. The message goes where any notify does: for your account's owner, the app they text NoClick on, else email.

Any agent on the `sdk` harness can answer, with all its tools. Its [connections](https://www.noclick.com/docs/guide/connections.md) work during a call as they do in a message: a user's agent books into that user's calendar, an account agent uses the account's connections. A caller is never handed a connect link: when a connection isn't connected yet, the agent tells the caller it can't do that right now, and the link is emailed to the connection's own person (its user, or your account's owner), at most once a day. Your [policy](https://www.noclick.com/docs/guide/policy.md#who-approves) applies to its calls too, approvals included. `answer_with` refuses an agent whose model connection isn't connected (`noclick.NeedsConnection` or `noclick.CredentialDisconnected`, with its `connect_url`); if it breaks later, callers hear "I can't take calls right now, please try again later" and the agent's person is emailed why, once a day. An agent on a [coding harness](https://www.noclick.com/docs/guide/agents.md#harnesses) can't answer, since a call waits on each turn's words and a coding harness replies later: `answer_with` raises `noclick.NotAvailable`.

### Transfer a call, and know who's calling

`answer_with` takes two more options, a tool and a gate for the answering agent:

```python
number.answer_with(
    receptionist,
    transfer_to=noclick.Human(email="dana@harbordental.test", phone="+14155550142"),
    callers="anyone",
)
```

```ts
import { Human } from "noclick";

await number.answerWith(receptionist, {
  transferTo: new Human({ email: "dana@harbordental.test", phone: "+14155550142" }),
  callers: "anyone",
});
```

- `transfer_to` (a number in E.164 form, or a `noclick.Human` with a `phone`) gives the agent a `transfer_call` tool that hands the caller to that number, when the caller asks for a person or the agent can't help. The agent says it's putting them through, then the call rings the person from your number; they hear who's calling and why before they're connected. Once they pick up the call is theirs, and the agent's part of it ends. A transfer nobody picks up within about 25 seconds comes back to the agent, which is told and tells the caller. On the Free and Member plans, the call goes on being billed at your number's carrier rates while they talk: the caller's minutes, the call placed to the person, and the recording if the number records. An older plan's per-minute price covers only the agent's part, and on a connected number your provider bills these to you. Policy names the tool `phone.transfer_call`.
- `callers` says who gets through: `"anyone"` (the default), `"users"` (only callers proven to be one of your users, as below) or `"owner"` (only the number's own user, or your account's owner for an account number, by the phone verified on their NoClick account). Anyone else hears that the number doesn't take their call, and the call is listed with `status` `refused`.

On a number of your account's, a caller whose number is one of your users' verified phones ([`user.verify_phone`](https://www.noclick.com/docs/guide/users.md#verify-a-user-s-phone)), with the carrier attesting the caller id (STIR/SHAKEN level A), runs as that user, in their connections, whatever `callers` says, and the call's `user_id` names them. So a line that answers anyone still gives a known customer what it gives them in your app, and a caller id alone, which anyone can fake, never does. Any other call runs as your account, and so does a call from a phone two of your users share. A user's own number runs every call as that user.

Calling `answer_with` again sets the number's answering afresh: an option you leave out goes back to its default.

### Choose the conversation

Each caller's calls to the number are a conversation of their own with the agent. `conversation=` names the conversation instead, a template over `{caller}` (the caller's number) and `{number}` (this one), and it's the same conversation `agent.message(..., conversation=...)` reaches:

```python
assistant = noclick.Agent.from_name("assistant")
number.answer_with(assistant, callers="owner", conversation="owner")
assistant.message("Remind me what we said on the phone.", conversation="owner")
```

```ts
import { Agent } from "noclick";

const assistant = Agent.fromName("assistant");
await number.answerWith(assistant, { callers: "owner", conversation: "owner" });
await assistant.message("Remind me what we said on the phone.", { conversation: "owner" });
```

During the call the agent reads what's already in the conversation, and at hang-up the call's transcript joins it. A call that runs as one of your users lands in that user's own conversation of that name. Calls from anyone else share one, so a fixed name such as `"owner"` belongs with `callers="owner"`, and the owner's [texts, and calls to NoClick's own number](https://www.noclick.com/docs/guide/humans.md#answer-the-owner-s-texts-and-calls-with-an-agent), and [email](https://www.noclick.com/docs/guide/inboxes.md#choose-the-conversation) can share it too.

### Text the caller

> [!NOTE]
> Invite-only beta. [Request access](mailto:support@noclick.com?subject=Invite-only%20beta%20access) to use this section's API; without access, `texts=True` and `noclick.TextingRegistration` raise `noclick.NotAvailable`.

`answer_with(..., texts=True)` gives the agent a `send_text` tool that texts the caller, and only the caller: a link, a confirmation, an address. The agent asks first ("May I text that to this number?") and sends only after a spoken yes; its tool says so. Each text is signed with your business's name (`Harbor Dental: here's the link you asked for`), the first one to a caller adds "Reply STOP to opt out.", and a call sends at most three. Texting anyone but the caller isn't offered.

Texting is for US local numbers: a number in another country, or a toll-free one, can't text through NoClick yet, and `answer_with(..., texts=True)` raises `noclick.NotAvailable` for one. Texting from a US local number needs your business registered with the US carriers first, as the legal entity on its tax records. Register it once; NoClick writes the rest of what the carriers review (what you text, and how a caller agrees to it) from your business's facts, so you only supply those:

```python
registration = noclick.TextingRegistration.create(
    legal_name="Harbor Dental LLC",
    brand_name="Harbor Dental",          # what texts are signed with
    entity_type="private_company",       # public_company, nonprofit, government, sole_proprietor
    tax_id="12-3456789",                 # the EIN; none for a sole proprietor
    industry="healthcare",
    website="https://harbordental.test",
    address={"street": "1 Ferry Building", "city": "San Francisco", "region": "CA", "postal_code": "94111"},
    contact={"name": "Dana Ruiz", "email": "dana@harbordental.test", "phone": "+14155550142"},
    privacy_url="https://harbordental.test/privacy",
    terms_url="https://harbordental.test/terms",
    max_setup_usd=40,
    max_monthly_usd=5,
)
print(registration.status, registration.setup_usd, registration.monthly_usd)
```

```ts
import { TextingRegistration } from "noclick";

const registration = await TextingRegistration.create({
  legalName: "Harbor Dental LLC",
  brandName: "Harbor Dental",          // what texts are signed with
  entityType: "private_company",       // public_company, nonprofit, government, sole_proprietor
  taxId: "12-3456789",                 // the EIN; none for a sole proprietor
  industry: "healthcare",
  website: "https://harbordental.test",
  address: { street: "1 Ferry Building", city: "San Francisco", region: "CA", postalCode: "94111" },
  contact: { name: "Dana Ruiz", email: "dana@harbordental.test", phone: "+14155550142" },
  privacyUrl: "https://harbordental.test/privacy",
  termsUrl: "https://harbordental.test/terms",
  maxSetupUsd: 40,
  maxMonthlyUsd: 5,
});
console.log(registration.status, registration.setupUsd, registration.monthlyUsd);
```

The website, privacy policy and terms must open without signing in, and the privacy policy must say phone numbers aren't shared. The `contact` is your business's own person, never NoClick: the registry checks that an email or address isn't reused across many businesses. Review takes days to weeks, and `status` follows it:

| `status` | Meaning |
| --- | --- |
| `pending` | The carriers' registry is checking the business |
| `awaiting_human` | Waiting on the contact: a public company's contact answers the registry's verification email within 7 days; a sole proprietor's contact gets a code by text, which `verify(code)` sends back |
| `in_review` | The business is verified; the carriers are reviewing what it texts |
| `approved` | Texting can start: answer with `texts=True` |
| `rejected` | Refused: `status_reason` says why and `fields` names the facts; `update(**corrections)` sends it again |
| `suspended` | Stopped by the carriers after approval |

The registry's verification email comes from The Campaign Registry, not from NoClick or your brand, and it may reach every business's contact, sometimes with an ID check, from January 2027. A `phone.texting_registration.updated` event tells you when the status moves. Until it's `approved`, `answer_with(..., texts=True)` raises `noclick.ActionRequired` naming the registration. A user's own number texts under its user's registration when there is one (`with noclick.as_user(...)`: when your users are businesses, each registers as itself), else under the account's. One registration texts from up to 49 numbers; a sole proprietor's, from one (the registry's limit).

```python
number.answer_with(receptionist, texts=True)
for text in number.text_messages(direction="inbound"):
    print(text.from_number, text.text, text.keyword)
```

```ts
await number.answerWith(receptionist, { texts: true });
for (const text of await number.textMessages({ direction: "inbound" })) {
  console.log(text.fromNumber, text.text, text.keyword);
}
```

A reply to the number doesn't wake the agent. `text_messages()` lists what the number sent and received, and each received text arrives as a `phone.text.received` event. STOP (and UNSUBSCRIBE, CANCEL, END, QUIT) stops every text from your business to that person until they text START. HELP is answered with your business's name and contact. Both are answered in your business's name, and the keyword is on the text.

Texting costs what the carriers' registry charges: a one-time setup (`setup_usd`, $25.50: registering the business, then its review and first three months) and a monthly fee after that (`monthly_usd`, $2.00). A sole proprietor's campaign is the registry's own kind, at its price: $49.50 to set up and $10.00 a month. Each text costs `segment_usd` a segment (160 characters), sent or received, plus the other person's network fee as its own line (networks charge about $0.003 to $0.005 a segment to send, some charge to receive too, and they change these several times a year). A registration like this sends up to about 2,000 texts a day to T-Mobile customers, shared with any other service your business texts through. `delete()` stops texting and the monthly fee. A number you keep with your own phone provider can't text through NoClick yet.

## Record calls

```python
number.update(record_calls=True)
```

```ts
await number.update({ recordCalls: true });
```

From the next call, a recorded call holds both sides in one file, and the caller hears "This call is recorded." before the agent speaks, on calls it answers and calls it places. A recording is ready a minute or so after the call ends; each call's `recording_url` is then a signed link, valid for an hour from when you read the call. It's stored in the agent's files, where deleting it removes it for good. `from_name(..., record_calls=True)` keeps the setting in your code, and `buy` and `connect` take it too.

## Place a call

```python
call = number.call(
    "+14155550100",
    goal="Confirm Friday's 3pm booking, or find a new time that works.",
).wait()

print(call.status)   # completed, or not_connected
print(call.text)     # the transcript, one turn per line
```

```ts
const call = await (await number.call("+14155550100", {
  goal: "Confirm Friday's 3pm booking, or find a new time that works.",
})).wait();

console.log(call.status);   // completed, or not_connected
console.log(call.text);     // the transcript, one turn per line
```

`call` returns an [operation](https://www.noclick.com/docs/guide/operations.md) that finishes once the call has hung up and its charge is recorded (usually at hang-up) with an `noclick.PhoneCall`: its `transcript` (turns of `role`, `text` and time), how long it lasted and what it was charged. The call goes out through the agent that answers the number, so route the number with `answer_with` first.

### Follow a call, and hang it up

```python
import noclick

op = number.call("+14155550100", goal="Ask whether the order shipped.")

call = noclick.PhoneNumber.get_call(op)
print(call.status, call.answered_at)    # calling, and when they picked up (None while it rings)
for line in call.lines:                 # what was said so far, turn by turn
    print(line["who"], line["text"])    # them, or agent

noclick.PhoneNumber.hang_up(op)
print(op.wait().ended_by)               # hang_up
```

```ts
import { PhoneNumber } from "noclick";

const op = await number.call("+14155550100", { goal: "Ask whether the order shipped." });

const call = await PhoneNumber.getCall(op);
console.log(call.status, call.answeredAt);   // calling, and when they picked up (null while it rings)
for (const line of call.lines) console.log(line.who, line.text);   // them or agent

await PhoneNumber.hangUp(op);
console.log((await op.wait()).endedBy);      // hang_up
```

`get_call` reads a call as it stands, by the operation `call` returned or by the call's own id (the operation's `call_id`): `answered_at` once the person picked up, and `lines`, what was said so far, turn by turn, with keys the agent pressed read as `Pressed 1`. Read it again as often as you need while it goes; the operation's progress carries the same lines. `hang_up` ends a call the number placed, ringing or live: the agent says goodbye and hangs up, or a ringing call is cancelled, and the call ends as any call does, with `ended_by` `hang_up` and its operation settling with the transcript. A call that already ended raises `noclick.Conflict`, and one the number answered `noclick.NotAvailable`. A call isn't canceled: canceling its operation raises `noclick.Conflict` that points to `hang_up`.

An [app](https://www.noclick.com/docs/guide/apps.md)'s production code calls and texts from a number its own code bought, within the app's budget: each call's minutes and turns and each text count toward it, and once it's used up a call isn't placed or let in. A preview's code never rings anyone. ([What an app buys](https://www.noclick.com/docs/guide/apps.md#what-it-buys).)

## See its calls

```python
for call in number.calls():
    print(call.to, call.status, call.seconds, call.cost_usd)
```

```ts
for (const call of await number.calls()) {
  console.log(call.to, call.status, call.seconds, call.costUsd);
}
```

`calls()` lists the calls the number answered and placed, newest first, each with its `direction`. `direction="inbound"` or `"outbound"` keeps one kind, `since=` (a timezone-aware `datetime`) those that started at or after it, and `limit=` the newest that many. A call that ran as one of your users names them in `user_id`, and a call the agent handed to a person says where in `transfer`. `cost_usd` is what a call was charged, as your usage shows it, once it has ended and the charge is recorded: usually at hang-up, and `null` until then.

```python
from datetime import datetime, timedelta, timezone

week_ago = datetime.now(timezone.utc) - timedelta(days=7)
for call in number.calls(direction="inbound", since=week_ago, limit=50):
    print(call.from_number, call.seconds, call.recording_url, call.text)
```

```ts
const weekAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
for (const call of await number.calls({ direction: "inbound", since: weekAgo, limit: 50 })) {
  console.log(call.fromNumber, call.seconds, call.recordingUrl, call.text);
}
```

## Link your own phone to your account

The numbers you message and call NoClick from are another thing: not numbers your agents answer, but your account's own ways in. A number linked to your account reaches it (texts and calls from it go to your NoClick), and NoClick's phone sign-in signs in to your account with it; proving a number a phone-only account holds folds that account into yours. Each is linked by a code texted to it, as Settings → Phone in the NoClick app does, or by texting NoClick from it. So linking is the signed-in owner's, or a key of your account's own that names the `account:phones` scope: a key with `*` doesn't hold it unless it's named too, and a key held to one of your users, an app's code, an MCP connection or an agent never may (`noclick.PermissionDenied`).

```python
linked = noclick.AccountPhones.get()
print([p.phone for p in linked.phones], linked.max_phones)

challenge = noclick.AccountPhones.link("+14155550123")   # texts a code to it
noclick.AccountPhones.verify(challenge.id, "123456")     # the code they read back
noclick.AccountPhones.unlink("+14155550123")
```

```ts
import { AccountPhones } from "noclick";

const linked = await AccountPhones.get();
const challenge = await AccountPhones.link("+14155550123");
await AccountPhones.verify(challenge.id, "123456");
await AccountPhones.unlink("+14155550123");
```

Over HTTP it's `GET /v1/account/phones`, `POST /v1/account/phones` with `{"phone": "+14155550123"}` (a challenge whose `id` the code is checked against within ten minutes), `POST /v1/account/phones/verify` with `{"challenge_id": ..., "code": ...}`, and `DELETE /v1/account/phones/{phone}`. A refusal names its kind in `reason`: a wrong code (`invalid_code`) can be tried again, `expired` or `too_many_checks` needs a new code, `linked_elsewhere` is a number another account holds, and `last_way_in` the only number of an account with no email, which can't be unlinked. Each link and unlink is a `phones` change on [watch](https://www.noclick.com/docs/guide/watch.md).

## Bring your own number

A number you already have can be answered by your agents three ways: connect it where it is, through your own phone provider account; port it to NoClick for good (invite-only beta); or forward its calls to a NoClick number. `source` says which a number is: `bought`, `connected` or `ported`.

### Connect a number you keep with your phone provider

First connect the provider account, with the account's own id and secret: for the provider NoClick supports for calls today, `twilio`, its Account SID and Auth Token. NoClick checks every call the provider sends it against the account's signature, which only the account's own secret can do, so a restricted API key isn't enough: a connection holding one raises `noclick.InvalidRequest` naming `connection`.

```python
provider = noclick.Connection.create(
    "phone-provider", integration="twilio", credential_type="twilio_account",
    data={"account_sid": "AC...", "auth_token": "..."},
)
for pick in noclick.PhoneNumber.connectable(provider):
    print(pick.number, pick.label, pick.routed_elsewhere)

number = noclick.PhoneNumber.connect("+14155550123", connection=provider, name="front-desk")
number.answer_with(noclick.Agent.from_name("receptionist"))
```

```ts
import { Agent, Connection, PhoneNumber } from "noclick";

const provider = await Connection.create("phone-provider", {
  integration: "twilio", credentialType: "twilio_account",
  data: { account_sid: "AC...", auth_token: "..." },
});
for (const pick of await PhoneNumber.connectable(provider)) {
  console.log(pick.number, pick.label, pick.routedElsewhere);
}

const number = await PhoneNumber.connect("+14155550123", { connection: provider, name: "front-desk" });
await number.answerWith(Agent.fromName("receptionist"));
```

`connectable` lists the account's numbers (up to 1,000), each with its `label`, the account's own name for it; `routed_elsewhere` means a number's calls go somewhere today (a URL, an application or a SIP trunk), and a number already connected to NoClick names the number it's connected as (`phone_number_id`) and the agent answering it (`agent_id`). `connect` records the number and where its calls go, and leaves them there until `answer_with` routes them to an agent; `disconnect()` takes the number off its agent, puts its calls back where they went, and takes it off your list. Everything on this page works on a connected number: `answer_with`, `call` (placed through your provider account), `calls` and recording. `from_name("front-desk", create_if_missing=True, connect="+14155550123", connection=provider)` connects it idempotently. A number on a SIP trunk can't be connected (`noclick.InvalidRequest`): take it off the trunk first.

Your provider bills the number and its minutes to you directly, as it does today, so a connected number's `monthly_usd` is `None`. NoClick bills only what it adds: the agent's time on each call.

Inside `as_user` it's the user's number, on the user's own connection. A number that's connected already, or that another NoClick workflow answers, raises `noclick.Conflict`, whose `existing_id` names it when it's yours: one number rings one agent. Reconnecting the connection moves its numbers onto the new credential, and deleting it hands its numbers back first. If the connection stops working (its secret rotated, the account closed), callers hear that the number's provider account is no longer connected.

### Port a number in

> [!NOTE]
> Invite-only beta. [Request access](mailto:support@noclick.com?subject=Invite-only%20beta%20access) to use this section's API; without access, a call raises `noclick.NotAvailable`.

```python
port = noclick.PhoneNumber.port_in(
    "+14155550188",
    account_holder="dana@harbordental.test",
    account_name="Harbor Dental LLC",
    service_address={"street": "1 Ferry Building", "city": "San Francisco", "region": "CA", "postal_code": "94111"},
    account_number="8812-4410-09",
    pin="4410",
    max_monthly_usd=5,
    name="front-desk",
)
print(port.status, port.sign_url)   # awaiting_human, the page Dana signs
```

```ts
import { PhoneNumber } from "noclick";

const port = await PhoneNumber.portIn("+14155550188", {
  accountHolder: "dana@harbordental.test",
  accountName: "Harbor Dental LLC",
  serviceAddress: { street: "1 Ferry Building", city: "San Francisco", region: "CA", postalCode: "94111" },
  accountNumber: "8812-4410-09",
  pin: "4410",
  maxMonthlyUsd: 5,
  name: "front-desk",
});
console.log(port.status, port.signUrl);   // awaiting_human, the page Dana signs
```

Porting moves US local numbers from their carrier to NoClick for good: one, or several on one account (pass a list; one letter covers them). A carrier lets a number go only on a letter of authorization signed by the person authorized on the account, so `port_in` emails `account_holder` (a `noclick.Human` or an email) a link to a NoClick page, branded like your other pages, where they check the details, read the letter and sign; `sign_url` is that page, to send them yourself. Their signature is an electronic one, recorded with when, from where and what they saw.

The details must match the current carrier's records, as its bill shows them: `account_name` is the name on the account (often a business, not the person signing), `service_address` the address the service is at, `account_number` the account's number, `billing_number` its main telephone number (the first number when you leave it out), `pin` where the carrier has one (a mobile account's transfer PIN, from its app), and `bill` (a recent bill's PDF bytes) where it asks for one. Every number on the account moves unless `remaining_numbers` names the ones that stay with the carrier; when the main number moves and others stay, the first of them becomes the account's main number. `requested_at` asks for a date; the carrier sets the real one, usually about a week out for a simple port and three weeks or more for a complex one, and refuses one outside the windows it allows. Moving the numbers is free.

`port_in` returns an [operation](https://www.noclick.com/docs/guide/operations.md), a `noclick.PortRequest`:

| `status` | Meaning |
| --- | --- |
| `awaiting_human` | Waiting for the account holder to sign (a letter unsigned after 14 days expires) |
| `running`, `step` `submitted` | Signed and sent to the carrier |
| `running`, `step` `scheduled` | The carrier gave every number a date: the last moves at `port_at` |
| `succeeded` | Moved: `wait()` gives the `PhoneNumber` objects, each with `source` `ported` |
| `failed` | The carrier refused it, with its reason |
| `canceled` | Canceled before the carrier committed to a date |

A carrier can move a letter's numbers on different days: `port.numbers` gives each one's `status` and `port_at`. The numbers keep working with their carrier until they move, then ring your agent. From then on each is a NoClick number, billed monthly like a bought one at its carrier's fee (`monthly_usd`, $1.00 today), at most `max_monthly_usd` (`noclick.PriceExceeded` above it, and nothing is sent).

A carrier refuses a port whose details don't match its records, and many first tries are refused, most often for the service address, so check it against the bill. `wait()` raises `noclick.InvalidRequest` with the carrier's reason, its `field` naming what didn't match: `account_name`, `account_holder`, `service_address`, `account_number`, `billing_number`, `pin`, `numbers` (one isn't on that account, or can't be ported), `remaining_numbers` (the account keeps numbers you didn't name, or none), `bill` or `requested_at`. `retry()` sends it again with the corrections, keeping the rest; a change to what the letter says (the holder, the account's name, the address, the account or billing number), or a refusal of the name it was signed with, asks the account holder to sign again, while a new `pin`, `bill`, `requested_at` or `remaining_numbers` goes straight back. A number that moved before the refusal stays yours.

```python
try:
    numbers = port.wait()
except noclick.InvalidRequest as err:
    print(err.field, err.message)   # account_number, The account number doesn't match.
    port = port.retry(account_number="8812-4410-07")
```

```ts
import { InvalidRequest } from "noclick";

try {
  const numbers = await port.wait();
} catch (err) {
  if (!(err instanceof InvalidRequest)) throw err;
  console.log(err.details.field, err.message);   // account_number, The account number doesn't match.
  const retried = await port.retry({ accountNumber: "8812-4410-07" });
}
```

`port.cancel()` stops it until the carrier has committed to a date (`scheduled`); after that it moves. `noclick.PortRequest.list(status="live")` lists the ports in flight, and takes the other [operation filters](https://www.noclick.com/docs/guide/operations.md).

A number you connected through your own phone provider is disconnected before it's ported in (`noclick.InvalidRequest` naming `numbers` otherwise); once ported, it's a new NoClick number to answer with an agent. For a number kept with Twilio, the name on the account is "Twilio, Inc.", its account number is the last 8 characters of your Account SID, and the PIN comes from Twilio's support (porting@twilio.com); Twilio also emails your account's owner to confirm the move, and the number's texting registration there doesn't come along.

### Move a number away

> [!NOTE]
> Invite-only beta. [Request access](mailto:support@noclick.com?subject=Invite-only%20beta%20access) to use this section's API.

```python
details = number.transfer_out()
print(details.account_name, details.account_number, details.pin, details.service_address)
```

```ts
const details = await number.transferOut();
console.log(details.accountName, details.accountNumber, details.pin, details.serviceAddress);
```

To move a NoClick number to another carrier, give that carrier what `transfer_out()` returns: the account the number is on (its name, and as its account and billing numbers the number itself), its service address and a transfer PIN for this number. For 30 days (until `expires_at`) another carrier may take it; a request outside that window, or quoting another PIN, is refused, so nobody takes your number without you. Each request arrives as a `phone.port_out.requested` event saying whether it goes ahead, and once the number moves it leaves your numbers, its billing stops, and `phone.port_out.completed` says so.

### Forward a line to a NoClick number

Forwarding needs no API. At your current carrier or phone system, forward the line (always, or when it's busy or unanswered) to a NoClick number that `answer_with` routes to an agent. The caller hears that agent, as on any call to the number, after the extra ring or two the forward takes.

A line can forward the calls it misses to the number and still be its `transfer_to`. A transfer rings it from the number, so one nobody picks up, forwarded back, reaches the number from itself: that call is turned away unanswered, and the caller comes back to the agent as with any transfer nobody took.

A forwarded call reaches NoClick from the forwarding line's carrier, which usually doesn't carry the caller's verified caller id (STIR/SHAKEN level A) over. So on an account number it runs as your account, never as one of your users, even when the caller's phone is a user's verified one, and `callers="users"` or `"owner"` turns it away: leave a forwarded line on `"anyone"`. To have callers recognised as your users, connect or port the number instead.

## Release a number

```python
number.release()
```

```ts
await number.release();
```

The number stops ringing and texting, its carrier takes it back, it stops being billed and it leaves your list. Deleting it in the app gives it back the same way, and so does a month your account can't pay once its 48-hour grace has passed: you're emailed when the grace starts and when the number goes. If the carrier can't take it back just then, `release()` raises `noclick.UpstreamError` and the number stays yours, still billed: release it again in a few minutes. A connected number isn't NoClick's to give back: `release()` raises `noclick.Conflict`, so `disconnect()` it.
