> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.rasen.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.rasen.ai/_mcp/server.

# Phone numbers

Use numbers already imported into the workspace. You can connect carrier accounts and import
numbers through the [Telephony management API](/guides/telephony), or in the Rasen app.
Importing a number does not buy it from a carrier.

Each number has an ETag, equal to the body's `revision`. Every change sends it in `If-Match`.

```bash
export RASEN_API_BASE="https://api.rasen.ai/v1"
export RASEN_API_KEY="<your key>"
AUTH="Authorization: Bearer $RASEN_API_KEY"

curl -sS "$RASEN_API_BASE/phone-numbers?number=%2B12025550123" -H "$AUTH"
curl -sS -i "$RASEN_API_BASE/phone-numbers/num_…" -H "$AUTH"      # the ETag header equals "revision"
```

## Outbound: let an agent call from a number

```bash
curl -sS -X PUT "$RASEN_API_BASE/phone-numbers/num_…/outbound-agents/agent_…" \
  -H "$AUTH" -H "Idempotency-Key: $(uuidgen)" -H 'If-Match: "<revision from the read>"'
```

The answer is the number with its new `revision` and `outbound_agent_ids`. Adding a pair that is
already there, or removing one that is not, changes nothing and keeps the revision. Other agents on
the number are never touched. `DELETE` on the same path removes the agent.

| Answer                                        | Meaning                                                                                                                                           | What to do                                 |
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| `428 revision_required`                       | No `If-Match`.                                                                                                                                    | Read the number and send its `revision`.   |
| `409 conflict`, `reason: stale_revision`      | The number changed since your read.                                                                                                               | Read it again and retry with the new ETag. |
| `409 conflict`, `reason: active_call`         | On removal: a call still holds the pair. A running outbound call holds its number and agent; a running inbound call holds the inbound assignment. | Wait for it to end, then retry.            |
| `409 agent_not_published` or `agent_not_live` | The agent cannot take calls.                                                                                                                      | Publish the agent, or choose another.      |

## Inbound: answer a number with an agent

A number answers inbound calls with at most one agent, across every workspace.

```bash
curl -sS -X PUT "$RASEN_API_BASE/phone-numbers/num_…/assignments/inbound" \
  -H "$AUTH" -H "Idempotency-Key: $(uuidgen)" -H 'If-Match: "<revision>"' \
  -H "Content-Type: application/json" -d '{"agent_id": "agent_…", "configure_inbound": true}'
```

```json
{"number": {"id": "num_…", "inbound_agent_id": "agent_…", "inbound_setup": "ready", "…": "…"},
 "assignment_saved": true, "setup_state": "ready", "next_action": null}
```

The assignment is saved first. With `configure_inbound: true` the platform then asks the carrier to
route the number, and `setup_state` says what happened:

| `setup_state`            | Meaning                                                                                                                                                  | `next_action`                                                                                   |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `ready`                  | This workspace's last carrier setup of the number succeeded. It is not a live read of the carrier: a change made in the carrier's dashboard is not seen. | none                                                                                            |
| `needs_provisioning`     | Saved; carrier routing was not requested (`configure_inbound: false`).                                                                                   | `POST …/provision`                                                                              |
| `failed`                 | Saved; the carrier refused the setup.                                                                                                                    | Check the carrier account, then `POST …/provision` with a new key.                              |
| `manual_action_required` | This carrier needs a dashboard step.                                                                                                                     | The step, in words.                                                                             |
| `not_required`           | Returned when you remove the inbound agent: no carrier change is made.                                                                                   | A note that the carrier may still route the number to the platform, which no longer answers it. |

`setup_state` is an open list: treat a value you do not know as unknown, never as success. The
setup can also be refused outright with `409 carrier_action_required` or
`409 carrier_capability_unsupported` (`details.carrier` and `details.capability`).

* `409 conflict` with `reason: connected_elsewhere` means another workspace answers this number
  inbound. Nothing about that workspace is disclosed. The number can still be used for outbound
  calls.
* Removing the inbound agent (`DELETE …/assignments/inbound`) stops the platform answering. It does
  not change the carrier: the answer is `setup_state: not_required`, and `next_action` says the
  carrier may still route the number.
* `POST /phone-numbers/{number_id}/provision` is an explicit new setup attempt for a number that has
  an inbound agent. It never creates a second carrier application. Without an inbound agent it
  answers `409 conflict` with `reason: inbound_agent_required`.

## Retries and visibility

* Every assignment and provisioning change stores its full answer. A replay with the same key returns
  that answer with its original `ETag`, and it is answered before the current revision is checked.
* Use a new key for each new provisioning attempt; `GET /phone-numbers/{number_id}` shows the current
  setup state.
* A number of another workspace, a removed number and a malformed number ID all answer
  `404 not_found`. Carrier references and credentials never appear in an answer.