> ## Documentation Index
> Fetch the complete documentation index at: https://docs.voicy.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Allocate Phone Number

> Take a free number and assign it to an agent, atomically

Takes one of your account's free numbers (no agent answers it) and assigns it to an
agent in a single step. Two requests made at the same moment can never both receive the
same number: each gets a different one, and a request that finds none left gets a `409`.

Send a `reference` of your own, such as the id of the user the number is for. Asking
again with the same `reference` returns the **same** number, so a retry after a timeout
or a double click never uses a second number. If that reference already holds a number
answered by a **different** agent than the `agent_id` you send, the answer is `409`, never a
silent reply with the old agent. It is the number's allocation key until you
[release it](https://docs.voicy.co/api-reference/phone-number-release.md).

Numbers that have never been used come first, then the one idle the longest. The
assignment is the one [Assign Phone Number](https://docs.voicy.co/api-reference/phone-number-modify.md) makes: the
number answers with the agent's latest **deployed** version.

> [!NOTE]
>
> An account API key is required, and an account reader key is refused (`403`), because
> this changes who answers a live number.

## Body Parameters

**agent\_id** `string` *required*

The agent that will answer the number. It must be on your account and deployed.

**reference** `string` *required*

Your own key for this allocation, 1 to 64 characters from letters, digits and `. _ : -`.
The same reference always returns the same number.

**min\_idle\_days** `integer` (default: 0)

Only allocate a number that has never been used, or was last used at least this many
days ago (0 to 3650). Use it to keep a number you just released away from new callers
for a while.

## Response

**phone\_number** `string`

The allocated number in E.164.

**agent\_id** `string`

The agent that answers it.

**status** `string`

Always `active`.

**reference** `string`

The reference you sent.

**allocated\_at** `string`

When it was allocated (ISO 8601, UTC).

```bash cURL theme={null}
curl -X POST https://api.voicy.co/functions/v1/phone-number-allocate \
  -H "Authorization: Bearer voicy_sk_live_xxx" \
  -H "Content-Type: application/json" \
  -d '{ "agent_id": "550e8400-e29b-41d4-a716-446655440000", "reference": "user-1234", "min_idle_days": 90 }'
```

```javascript JavaScript theme={null}
const res = await fetch('https://api.voicy.co/functions/v1/phone-number-allocate', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer voicy_sk_live_xxx',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    agent_id: '550e8400-e29b-41d4-a716-446655440000',
    reference: 'user-1234',
    min_idle_days: 90,
  }),
});
if (res.status === 409) {
  // no number is available right now
}
const number = await res.json();
```

```python Python theme={null}
import requests
res = requests.post(
    "https://api.voicy.co/functions/v1/phone-number-allocate",
    headers={'Authorization': 'Bearer voicy_sk_live_xxx'},
    json={'agent_id': '550e8400-e29b-41d4-a716-446655440000',
          'reference': 'user-1234', 'min_idle_days': 90},
)
if res.status_code == 409:
    pass  # no number is available right now
number = res.json()
```

```json 200 OK theme={null}
{
  "phone_number": "+972771234567",
  "agent_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "active",
  "reference": "user-1234",
  "allocated_at": "2026-11-13T10:00:00.000Z"
}
```

```json 400 Bad Request theme={null}
{
  "status": "error",
  "message": "reference is required: 1-64 characters from letters, digits and . _ : -"
}
```

```json 409 Conflict theme={null}
{
  "status": "error",
  "message": "No phone number is available"
}
```

```json 422 Unprocessable Entity theme={null}
{
  "status": "error",
  "message": "Agent not found or not accessible"
}
```

```json 429 Too Many Requests theme={null}
{
  "status": "error",
  "message": "Too many requests: this API key is limited to 600 requests per minute. Retry after 23 seconds."
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.