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

# Get number usage

> Read usage for an owned Nixflex phone number. Check the response fields and account scope before using the totals in your application.

**FIXED · account** A number belongs to an account and agent. On a shared agent always pass that customer’s eligible from\_number.

**NOT OFFERED → do this instead · number** Fixed welcome\_message, language, general timezone and pickup delay belong to the agent. Use Dynamic greeting and the number’s custom\_prompt for its opening. Split agents for different fixed settings.

**YOU CAN CHANGE · number** PATCH fields below. Clearing depends on the field. Null record\_call or require\_booking\_confirmation inherits. Use the number’s voicemail controls. `calcom_timezone_override`, `custom_prompt`, `voice_id`, `sms_reply_enabled`, `sms_prompt`, `web_prompt`, `speaking_rate`, `dtmf_enabled`, `require_booking_confirmation`, `record_call`, `recording_source`, `voicemail_leave_enabled`, `voicemail_message`.

**SCOPE · number** Import an owned carrier number, assign an agent, edit its channels or remove its Nixflex connection.

For a different greeting per business, keep Dynamic greeting on (the default) and put the opening line in that number’s custom\_prompt. For example, “Start every call with: Thank you for calling Oak and Stone”.

[Read the compact AI rules](https://docs.nixflex.com/ai-rules.md#phone-numbers)

Get number usage in the authenticated account.

Method: **GET** · Success: **200** · Scope: **Owning account**

**The important part**

* These usage counters describe the selected owned number.
* Do not use counters as an invoice or a complete charge ledger.

[Business guide](https://docs.nixflex.com/guides/business/phone-numbers.md) · [Developer guide](https://docs.nixflex.com/guides/developer/phone-numbers.md) · [Glossary](https://docs.nixflex.com/guides/glossary.md)

## Authentication

Use `Authorization: Bearer KEY_ID:KEY_SECRET` for the owning account. An organisation API key has Owner authority. Personal sessions use the role rules documented in [Authentication](https://docs.nixflex.com/api-reference/authentication.md); do not treat a Member session as an API key.

## Request fields

| Field | Type | Required | Default and limits |
| - | - | - | - |
| `phoneNumber` (path) | string | Yes | Owned public E.164 number. URL-encode the plus. |
| `period` (query) | string | No | Calendar days including today, not rolling hours. All means retained history. Allowed: today, 7, 14, 30, 90, all Default: "all" |
| `time_zone` (query) | string | No | IANA zone such as Europe/London, or UTC. Match the dashboard browser zone. At most 64 characters Default: "UTC" |

Do not send a request body.

These examples
require Node/CLI 0.11.0 or later, Python 0.4.0 or later and MCP 0.5.0 or later. This is a read-only request.

Use an active API key. Ownership comes only from that key, never a request field.
URL-encode the plus in E.164: `/v1/phone-numbers/%2B12025550123/usage`.
Numbers you do not own, unknown numbers and pending imports return
`404 number_not_found`. Both API-imported and dashboard-imported owned numbers work.

### Period and time zone

* `period`: `today`, `7`, `14`, `30`, `90`, or `all` (default).
* `time_zone`: an IANA zone such as `Europe/London`, or `UTC` (default).
* Finite periods start at local midnight, including today: 7 means today plus
  six earlier calendar dates, not the previous 168 hours. DST is respected.
* `period_start` is inclusive; `null` for all retained history. `period_end` is
  the inclusive server query cutoff, not a future day-end. All returned ISO times
  identify absolute instants; an offset may differ from the selected zone.
* Use the dashboard browser's zone to compare. Requests at different instants
  can differ if new activity arrives, costs settle or retention removes history.
* Duplicate parameters, unknown parameters and invalid values return 400.

### Response and meaning

The envelope is `{ "usage": { ... } }`. It includes the number, period, zone,
boundaries and these fields:

| Field | Meaning |
| - | - |
| `call_count` | Retained call rows in this period, including unpriced/zero-duration rows |
| `total_ms`, `minutes` | Sum of stored duration in milliseconds; minutes = total\_ms / 60000, rounded to six decimals |
| `last_call` | Latest call creation timestamp in the period, or null |
| `total_cost`, `currency` | Exact decimal string of recorded call charges; currency USD |
| `unpriced_calls` | Number of calls with NULL cost; a known zero cost is not unpriced |
| `sms_sent`, `sms_received`, `sms_count` | Outbound, inbound and all retained SMS rows; counts are messages, not billable segments |
| `web_chats` | Distinct session IDs with messages in the period, scoped to the current number row |
| `unused` | Zero calls AND zero SMS. A number with only web chat is still “Unused” |
| `history_note` | Retained history, not a billing ledger; provider SMS charges are not included |

`duration_unit` is `milliseconds`; `start_inclusive` and `end_inclusive` are true.
For display, round minutes to at most two decimals and cost to two decimals, as
the dashboard does. Do not recompute cost from minutes or a current price.

Retention can reduce these totals. Calls and SMS are attributed by owner plus
business E.164 number (outbound = from; otherwise = to), exactly like the dashboard.
Same-owner re-import can therefore include that owner's older call/SMS history;
another owner's rows are excluded. Web chats additionally require the current
number-row generation; old/unbound generations are excluded. This is not lifetime
carrier usage, a payment statement, a ledger, or a guarantee that a call is settled.
No raw calls, messages, recordings, credentials or internal account IDs are returned.

### Query budget and failures

The aggregate has a three-second database RPC budget and a five-second engine
wait limit, with number/owner/time indexes. It returns full totals or
`503 usage_unavailable`, never a partial aggregate or false zero. Try a smaller
period or retry later; do not loop aggressively. The normal API rate limit applies.

### Client method examples

```javascript theme={"dark"}
const { usage } = await client.phoneNumbers.usage('+12025550123', {
  period: '30', time_zone: 'Europe/London'
});
console.log(usage.total_cost); // exact decimal USD string
```

```python theme={"dark"}
result = client.phone_numbers.usage('+12025550123', period='30', time_zone='Europe/London')
# Same method on AsyncNixflex: await client.phone_numbers.usage(...)
```

```shell theme={"dark"}
nixflex numbers usage +12025550123 --period 30 --time-zone Europe/London --json
```

The existing read-only MCP `list_phone_numbers` tool has an additive usage mode:

```json theme={"dark"}
{"phone_number":"+12025550123","usage":true,"period":"30","time_zone":"Europe/London"}
```

Do not combine usage with list filters/paging. Without `usage:true`, the existing
list/single-settings tool behaviour remains unchanged. No new credentials or
permissions are needed. Browser RPC grants have not been expanded.

## Response fields

`200` returns the following shape.

| Field | Type | Meaning |
| - | - | - |
| `usage` | object | Always returned. |
| `usage.phone_number` | string | Always returned. |
| `usage.period` | string | Allowed: today, 7, 14, 30, 90, all |
| `usage.time_zone` | string | Always returned. |
| `usage.period_start` | string or null | Inclusive boundary; null for all retained history. |
| `usage.period_end` | string | Inclusive server query cutoff. |
| `usage.start_inclusive` | boolean | Always returned. |
| `usage.end_inclusive` | boolean | Always returned. |
| `usage.currency` | string | Always returned. |
| `usage.duration_unit` | string | Always returned. |
| `usage.call_count` | integer | Minimum 0 |
| `usage.total_ms` | integer | Minimum 0 |
| `usage.minutes` | number | total\_ms / 60000, rounded to six decimals. total\_ms is authoritative. |
| `usage.last_call` | string or null | Always returned. |
| `usage.total_cost` | string | Exact decimal USD sum of retained calls.cost. No repricing. Display to two decimals to match the dashboard. |
| `usage.unpriced_calls` | integer | Retained calls where cost IS NULL, not zero. Minimum 0 |
| `usage.sms_sent` | integer | Minimum 0 |
| `usage.sms_received` | integer | Minimum 0 |
| `usage.sms_count` | integer | Minimum 0 |
| `usage.web_chats` | integer | Distinct session IDs with messages in the period, bound to the current number row and owner. Minimum 0 |
| `usage.unused` | boolean | Zero calls AND zero SMS in this period; web chats do not affect this field. |
| `usage.history_note` | string | Retained history, not a billing ledger; only recorded call charges, no provider SMS charges. |

## Example request

Production HTTP examples. Replace the placeholder identifiers with resources owned by the account. Set `NIXFLEX_API_KEY` privately; never print it.

```bash cURL (Bash) theme={"dark"}
curl --request GET \
  --url 'https://api.nixflex.com/v1/phone-numbers/%2B12025550123/usage' \
  --header "Authorization: Bearer $NIXFLEX_API_KEY"
```

```javascript Node (HTTP) theme={"dark"}
const response = await fetch('https://api.nixflex.com/v1/phone-numbers/%2B12025550123/usage', {
  method: 'GET',
  headers: { Authorization: `Bearer ${process.env.NIXFLEX_API_KEY}` },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const result = await response.json();
// Handle the private result without logging it.
```

```python Python (HTTP) theme={"dark"}
import os, json
from urllib.request import Request, urlopen

request = Request('https://api.nixflex.com/v1/phone-numbers/%2B12025550123/usage', method='GET',
    headers={'Authorization': 'Bearer ' + os.environ['NIXFLEX_API_KEY']})
with urlopen(request, timeout=30) as response:
    result = json.load(response)
# Handle the private result without logging it.
```

```powershell PowerShell (HTTP) theme={"dark"}
$headers = @{ Authorization = "Bearer $env:NIXFLEX_API_KEY" }
$result = Invoke-RestMethod -Method GET -Uri 'https://api.nixflex.com/v1/phone-numbers/%2B12025550123/usage' -Headers $headers -DisableKeepAlive
# Handle $result privately.
```

## Example response

Illustrative response with placeholder identifiers.

```json Response theme={"dark"}
{
  "usage": {
    "phone_number": "+12025550123",
    "period": "all",
    "time_zone": "UTC",
    "period_start": null,
    "period_end": "2026-11-02T12:00:00Z",
    "start_inclusive": true,
    "end_inclusive": true,
    "currency": "USD",
    "duration_unit": "milliseconds",
    "call_count": 0,
    "total_ms": 0,
    "minutes": 0,
    "last_call": null,
    "total_cost": "0",
    "unpriced_calls": 0,
    "sms_sent": 0,
    "sms_received": 0,
    "sms_count": 0,
    "web_chats": 0,
    "unused": true,
    "history_note": "Usage reflects retained records for this number generation."
  }
}
```

## Errors

Branch on `error.code`, not the wording of `error.message`. The envelope includes `type`, `code`, `message`, `doc_url` and `details`.

| Status / code | What it means | What to do |
| - | - | - |
| 400 · `invalid_phone_format` | The phone number is not valid E.164. | Correct the named field or query using the request table before trying again. |
| 400 · `invalid_period` | The requested period is invalid. | Correct the named field or query using the request table before trying again. |
| 400 · `invalid_timezone` | The time zone is invalid. | Supply a valid IANA time zone such as Europe/London. |
| 400 · `invalid_query` | The query contains an invalid, unknown or duplicate field. | Correct the named field or query using the request table before trying again. |
| 401 | Missing/invalid API key or inactive account at authentication. | Check the full account credential and API host privately; stop the retry loop. |
| 403 · `account_unavailable` | The account is unavailable for this operation. | Resolve the account or role restriction through an authorised person. |
| 404 · `number_not_found` | The number is absent or inaccessible to this account. | Check the exact owned identifier and current resource state; do not probe another account. |
| 429 | Existing API rate limit. | Wait at least Retry-After and use a bounded read retry. |
| 503 · `usage_unavailable` | Usage could not be read; it is not zero usage. | Keep the last result unknown and use bounded read retries; do not replace it with empty data. |

## Retry and idempotency

Use bounded retries only for temporary read failures. Keep the same filters while paging. See [retry rules](https://docs.nixflex.com/api-reference/retries.md).

## Related endpoints

* [List phone numbers](https://docs.nixflex.com/api-reference/phone-numbers/list.md)
* [Get a phone number](https://docs.nixflex.com/api-reference/phone-numbers/get.md)
* [Errors and recovery](https://docs.nixflex.com/api-reference/errors.md#error-envelope)


## OpenAPI

````yaml api-reference/public.openapi.json GET /phone-numbers/{phoneNumber}/usage
openapi: 3.1.0
info:
  title: Nixflex public API
  version: 1.0.0
  description: >-
    Nixflex API reference for agents, calls, messaging, knowledge, organisations
    and integrations. Authenticate with the owning account and follow each
    operation’s permissions, response and retry contract.
servers:
  - url: https://api.nixflex.com/v1
security:
  - bearerAuth: []
paths:
  /phone-numbers/{phoneNumber}/usage:
    get:
      tags:
        - Phone numbers
      summary: Get number usage
      operationId: getPhoneNumberUsage
      parameters:
        - name: phoneNumber
          in: path
          required: true
          schema:
            type: string
            pattern: ^\+[1-9][0-9]{6,14}$
          description: Owned public E.164 number. URL-encode the plus.
        - name: period
          in: query
          schema:
            type: string
            enum:
              - today
              - '7'
              - '14'
              - '30'
              - '90'
              - all
            default: all
          description: >-
            Calendar days including today, not rolling hours. All means retained
            history.
        - name: time_zone
          in: query
          schema:
            type: string
            maxLength: 64
            default: UTC
          description: >-
            IANA zone such as Europe/London, or UTC. Match the dashboard browser
            zone.
      responses:
        '200':
          description: Complete aggregate; never truncated partial totals.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - usage
                properties:
                  usage:
                    type: object
                    additionalProperties: false
                    required:
                      - phone_number
                      - period
                      - time_zone
                      - period_start
                      - period_end
                      - start_inclusive
                      - end_inclusive
                      - currency
                      - duration_unit
                      - call_count
                      - total_ms
                      - minutes
                      - last_call
                      - total_cost
                      - unpriced_calls
                      - sms_sent
                      - sms_received
                      - sms_count
                      - web_chats
                      - unused
                      - history_note
                    properties:
                      phone_number:
                        type: string
                      period:
                        type: string
                        enum:
                          - today
                          - '7'
                          - '14'
                          - '30'
                          - '90'
                          - all
                      time_zone:
                        type: string
                      period_start:
                        type:
                          - string
                          - 'null'
                        format: date-time
                        description: Inclusive boundary; null for all retained history.
                      period_end:
                        type: string
                        format: date-time
                        description: Inclusive server query cutoff.
                      start_inclusive:
                        type: boolean
                        const: true
                      end_inclusive:
                        type: boolean
                        const: true
                      currency:
                        type: string
                        const: USD
                      duration_unit:
                        type: string
                        const: milliseconds
                      call_count:
                        type: integer
                        minimum: 0
                      total_ms:
                        type: integer
                        minimum: 0
                      minutes:
                        type: number
                        description: >-
                          total_ms / 60000, rounded to six decimals. total_ms is
                          authoritative.
                      last_call:
                        type:
                          - string
                          - 'null'
                        format: date-time
                      total_cost:
                        type: string
                        pattern: ^-?[0-9]+(?:\.[0-9]+)?$
                        description: >-
                          Exact decimal USD sum of retained calls.cost. No
                          repricing. Display to two decimals to match the
                          dashboard.
                      unpriced_calls:
                        type: integer
                        minimum: 0
                        description: Retained calls where cost IS NULL, not zero.
                      sms_sent:
                        type: integer
                        minimum: 0
                      sms_received:
                        type: integer
                        minimum: 0
                      sms_count:
                        type: integer
                        minimum: 0
                      web_chats:
                        type: integer
                        minimum: 0
                        description: >-
                          Distinct session IDs with messages in the period,
                          bound to the current number row and owner.
                      unused:
                        type: boolean
                        description: >-
                          Zero calls AND zero SMS in this period; web chats do
                          not affect this field.
                      history_note:
                        type: string
                        description: >-
                          Retained history, not a billing ledger; only recorded
                          call charges, no provider SMS charges.
        '400':
          description: >-
            invalid_phone_format, invalid_period, invalid_timezone or
            invalid_query. Duplicate/unknown query fields are rejected.
        '401':
          description: Missing/invalid API key or inactive account at authentication.
        '403':
          description: >-
            account_unavailable: account became inactive before the database
            read.
        '404':
          description: 'number_not_found: absent, foreign, pending or internal identity.'
        '429':
          description: Existing API rate limit.
        '503':
          description: >-
            usage_unavailable: timeout, unavailable schema/database or invalid
            result. Not zero usage; use a shorter period or retry later.
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        KEY_ID:KEY_SECRET from the owning account. Keep it server-side. A
        verified personal dashboard Bearer session may be used where the
        operation documents role-based access.

````

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