openapi: 3.1.0
info:
  title: Numsify Developer API
  version: "1.0.0"
  summary: Order one-time virtual numbers and receive SMS codes from your server.
  description: |
    The Numsify Developer API lets **reseller accounts** order one-time virtual numbers, read the SMS
    and call codes they receive, and cancel or retry them. Charges come out of your account's
    communication balance (USD cents), the same balance web top-ups fill.

    ## Authentication

    Send an API key from your server in the `Authorization` header:

    ```http
    Authorization: Bearer nsk_live_<64 hex characters>
    ```

    Create keys in the dashboard at <https://numsify.com/developers/keys>. The full key is shown once.
    Each key carries scopes (`numbers:read`, `numbers:write`, `balance:read`) and may have an IP
    allowlist, an expiry and a daily spend cap. An account can have at most 5 active keys.

    **Keys are for servers only.** Requests that carry an `Origin` header (that is, requests made by
    a browser) are rejected with `BROWSER_REQUESTS_NOT_ALLOWED`. Never ship a key in a web page,
    mobile app or any other client.

    ## Response envelope

    Every response, success or error, uses the same envelope:

    ```json
    { "success": true, "data": { }, "timestamp": "2026-11-22T10:00:00Z", "pagination": { } }
    { "success": false, "error": { "code": "INSUFFICIENT_BALANCE", "message": "..." }, "timestamp": "..." }
    ```

    `pagination` is present on list endpoints only.

    ## Errors

    Branch on `error.code`, not on the HTTP status. `error.message` is human readable and may change.
    The status shown for each code below is the usual one.

    | Code | Status | Meaning |
    |---|---|---|
    | `UNAUTHORIZED` | 401 | Missing or unknown API key |
    | `API_KEY_REVOKED` | 401 | The key was revoked |
    | `API_KEY_EXPIRED` | 401 | The key passed its expiry |
    | `IP_NOT_ALLOWED` | 403 | The request IP is not in the key's allowlist |
    | `INSUFFICIENT_SCOPE` | 403 | The key lacks the scope this endpoint needs |
    | `API_ACCESS_DISABLED` | 403 | API access is not enabled for this account |
    | `BROWSER_REQUESTS_NOT_ALLOWED` | 403 | The request carried an `Origin` header |
    | `VALIDATION_FAILED` | 400 | A parameter or body field is invalid |
    | `IDEMPOTENCY_KEY_REQUIRED` | 400 | `POST /v1/numbers` without `Idempotency-Key` |
    | `NUMBER_NOT_FOUND` | 404 | No number with this ID on your account |
    | `INSUFFICIENT_BALANCE` | 402 | Top up your communication balance, then retry with the same `Idempotency-Key` |
    | `DAILY_SPEND_LIMIT_REACHED` | 422 | The key's daily spend cap is used up |
    | `SERVICE_UNAVAILABLE` | 422 | This service is not offered in that country |
    | `TEMPORARILY_UNAVAILABLE` | 503 | Ordering is paused; retry later |
    | `SERVICE_RESTRICTED` | 403 | This service cannot be ordered through the API |
    | `CONCURRENT_ORDER` | 409 | Another order with this spend-capped key is in flight; retry shortly |
    | `ACTIVE_NUMBER_LIMIT` | 429 | Too many active numbers; cancel or wait for some to finish |
    | `CANCELLATION_TOO_EARLY` | 409 | Numbers can be canceled 2 minutes after the order (`cancelable_after`, `Retry-After` header) |
    | `NUMBER_CANCELLED` | 409 | The number is already canceled |
    | `NUMBER_EXPIRED` | 409 | The number already expired |
    | `IDEMPOTENCY_IN_PROGRESS` | 409 | The same `Idempotency-Key` is still being processed |
    | `IDEMPOTENCY_KEY_REUSED` | 422 | The same `Idempotency-Key` was sent with a different body |
    | `RATE_LIMIT_EXCEEDED` | 429 | Slow down and retry with backoff |
    | `INTERNAL_ERROR` | 500 | Something failed on our side; retry with backoff |

    ## Rate limits

    Per key: **120 requests per minute** overall and **20 orders per minute** (`POST /v1/numbers`).
    Over the limit you get `429 RATE_LIMIT_EXCEEDED`.

    ## Idempotency

    `POST /v1/numbers` requires an `Idempotency-Key` header (8–64 characters). For 24 hours, the same key
    with the same body returns the stored successful (`201`) response with `Idempotent-Replayed: true`, so a
    retry after a timeout never buys a second number. Failed orders are not stored, so you can retry
    them with the same key. The same key with a different body returns `422 IDEMPOTENCY_KEY_REUSED`;
    a request still in flight returns `409 IDEMPOTENCY_IN_PROGRESS`.

    ## Webhooks

    Instead of polling `GET /v1/numbers/{id}/sms`, configure one HTTPS endpoint at
    <https://numsify.com/developers/webhooks>. See the **Webhooks** section of this reference for the
    payloads and the `Numsify-Signature` scheme.
  contact:
    name: Numsify support
    url: https://numsify.com/contact-us
  termsOfService: https://numsify.com/terms
servers:
  - url: https://api.numsify.com/api
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Balance
    description: Your communication balance.
  - name: Services
    description: Services you can order numbers for, with price and stock per country.
  - name: Numbers
    description: Order, read, cancel and retry one-time numbers.
paths:
  /v1/balance:
    get:
      operationId: getBalance
      summary: Get balance
      description: "Your communication balance in USD cents. Scope: `balance:read`."
      tags: [Balance]
      security:
        - bearerAuth: ["balance:read"]
      responses:
        "200":
          description: The balance.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/SuccessEnvelope"
                  - type: object
                    required: [data]
                    properties:
                      data:
                        $ref: "#/components/schemas/Balance"
              example:
                success: true
                data: { balance_cents: 1250, currency: USD }
                timestamp: "2026-11-22T10:00:00Z"
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "500": { $ref: "#/components/responses/InternalError" }

  /v1/services:
    get:
      operationId: listServices
      summary: List services
      description: "Services you can order numbers for. Scope: `numbers:read`."
      tags: [Services]
      security:
        - bearerAuth: ["numbers:read"]
      parameters:
        - name: search
          in: query
          description: Filter by service name or code.
          schema: { type: string }
        - name: verification_type
          in: query
          description: Only services that support this verification type.
          schema: { $ref: "#/components/schemas/VerificationType" }
        - $ref: "#/components/parameters/Page"
        - $ref: "#/components/parameters/PageSize"
      responses:
        "200":
          description: A page of services.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/SuccessEnvelope"
                  - type: object
                    required: [data, pagination]
                    properties:
                      data:
                        type: array
                        items: { $ref: "#/components/schemas/Service" }
                      pagination: { $ref: "#/components/schemas/Pagination" }
        "400": { $ref: "#/components/responses/ValidationFailed" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "500": { $ref: "#/components/responses/InternalError" }

  /v1/services/{service_id}/countries:
    get:
      operationId: listServiceCountries
      summary: List countries for a service
      description: "Price and stock per country for one service. Scope: `numbers:read`."
      tags: [Services]
      security:
        - bearerAuth: ["numbers:read"]
      parameters:
        - name: service_id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: Countries with price and stock.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/SuccessEnvelope"
                  - type: object
                    required: [data]
                    properties:
                      data:
                        type: array
                        items: { $ref: "#/components/schemas/ServiceCountry" }
                      pagination: { $ref: "#/components/schemas/Pagination" }
        "400": { $ref: "#/components/responses/ValidationFailed" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "500": { $ref: "#/components/responses/InternalError" }

  /v1/numbers:
    post:
      operationId: orderNumber
      summary: Order a number
      description: |
        Orders a one-time number and charges `price_cents` to your communication balance.
        Requires the `Idempotency-Key` header. Limited to 20 orders per minute per key.
        Scope: `numbers:write`.
      tags: [Numbers]
      security:
        - bearerAuth: ["numbers:write"]
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/OrderNumberRequest" }
            example:
              service_id: 3f6c1d2e-8a4b-4c1e-9f2a-0b1c2d3e4f50
              country_id: 7a8b9c0d-1e2f-4a3b-8c4d-5e6f7a8b9c0d
              verification_type: sms
      responses:
        "201":
          description: The number was ordered (or, on a replay, the stored successful response).
          headers:
            Idempotent-Replayed:
              $ref: "#/components/headers/IdempotentReplayed"
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/SuccessEnvelope"
                  - type: object
                    required: [data]
                    properties:
                      data: { $ref: "#/components/schemas/Number" }
        "400":
          description: "`VALIDATION_FAILED` or `IDEMPOTENCY_KEY_REQUIRED`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ErrorEnvelope" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "402":
          description: "`INSUFFICIENT_BALANCE`. Top up and retry with the same `Idempotency-Key`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ErrorEnvelope" }
              example:
                success: false
                error: { code: INSUFFICIENT_BALANCE, message: Insufficient balance }
                timestamp: "2026-11-22T10:00:00Z"
        "403":
          description: "Authorization errors (see `Forbidden`) or `SERVICE_RESTRICTED`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ErrorEnvelope" }
        "409":
          description: "`IDEMPOTENCY_IN_PROGRESS` (a request with this key is still being processed) or `CONCURRENT_ORDER` (another order with this spend-capped key is in flight)."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ErrorEnvelope" }
        "422":
          description: "`IDEMPOTENCY_KEY_REUSED` (this key was used with a different body), `DAILY_SPEND_LIMIT_REACHED`, `SERVICE_UNAVAILABLE` (not offered in that country) or `VALIDATION_FAILED`."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ErrorEnvelope" }
        "429":
          description: "`RATE_LIMIT_EXCEEDED` (20 orders/minute per key) or `ACTIVE_NUMBER_LIMIT` (too many active numbers)."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ErrorEnvelope" }
        "500": { $ref: "#/components/responses/InternalError" }
        "503":
          description: "`TEMPORARILY_UNAVAILABLE`: ordering is paused; retry later."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ErrorEnvelope" }
    get:
      operationId: listNumbers
      summary: List numbers
      description: "Numbers ordered by your account, newest first. Scope: `numbers:read`."
      tags: [Numbers]
      security:
        - bearerAuth: ["numbers:read"]
      parameters:
        - name: status
          in: query
          schema:
            type: string
            enum: [active, expired, canceled]
        - $ref: "#/components/parameters/Page"
        - $ref: "#/components/parameters/PageSize"
      responses:
        "200":
          description: A page of numbers.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/SuccessEnvelope"
                  - type: object
                    required: [data, pagination]
                    properties:
                      data:
                        type: array
                        items: { $ref: "#/components/schemas/Number" }
                      pagination: { $ref: "#/components/schemas/Pagination" }
        "400": { $ref: "#/components/responses/ValidationFailed" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "500": { $ref: "#/components/responses/InternalError" }

  /v1/numbers/{id}:
    get:
      operationId: getNumber
      summary: Get a number
      description: "Scope: `numbers:read`."
      tags: [Numbers]
      security:
        - bearerAuth: ["numbers:read"]
      parameters:
        - $ref: "#/components/parameters/NumberId"
      responses:
        "200":
          description: The number.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/SuccessEnvelope"
                  - type: object
                    required: [data]
                    properties:
                      data: { $ref: "#/components/schemas/Number" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NumberNotFound" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "500": { $ref: "#/components/responses/InternalError" }

  /v1/numbers/{id}/sms:
    get:
      operationId: listNumberSms
      summary: List SMS for a number
      description: |
        SMS and call codes received on this number. Poll every few seconds while the number is
        `active`, or use the `sms.received` webhook instead. Scope: `numbers:read`.
      tags: [Numbers]
      security:
        - bearerAuth: ["numbers:read"]
      parameters:
        - $ref: "#/components/parameters/NumberId"
      responses:
        "200":
          description: Messages, newest first.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/SuccessEnvelope"
                  - type: object
                    required: [data]
                    properties:
                      data:
                        type: array
                        items: { $ref: "#/components/schemas/Sms" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NumberNotFound" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "500": { $ref: "#/components/responses/InternalError" }

  /v1/numbers/{id}/cancel:
    post:
      operationId: cancelNumber
      summary: Cancel a number
      description: |
        Cancels the number and refunds it when allowed. Not allowed in the first 2 minutes after the
        order (see `cancelable_after`). Scope: `numbers:write`.
      tags: [Numbers]
      security:
        - bearerAuth: ["numbers:write"]
      parameters:
        - $ref: "#/components/parameters/NumberId"
      responses:
        "200":
          description: The canceled number.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/SuccessEnvelope"
                  - type: object
                    required: [data]
                    properties:
                      data: { $ref: "#/components/schemas/Number" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NumberNotFound" }
        "409":
          description: "`CANCELLATION_TOO_EARLY` (with `Retry-After`), `NUMBER_CANCELLED` or `NUMBER_EXPIRED`."
          headers:
            Retry-After:
              description: Seconds until the number can be canceled. Sent with `CANCELLATION_TOO_EARLY`.
              schema: { type: integer, minimum: 0 }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ErrorEnvelope" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "500": { $ref: "#/components/responses/InternalError" }

  /v1/numbers/{id}/retry:
    post:
      operationId: retryNumber
      summary: Request another SMS
      description: "Asks the provider for another SMS on an active number. Scope: `numbers:write`."
      tags: [Numbers]
      security:
        - bearerAuth: ["numbers:write"]
      parameters:
        - $ref: "#/components/parameters/NumberId"
      responses:
        "200":
          description: The number.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/SuccessEnvelope"
                  - type: object
                    required: [data]
                    properties:
                      data: { $ref: "#/components/schemas/Number" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NumberNotFound" }
        "409":
          description: "`NUMBER_CANCELLED`: the number is no longer active."
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ErrorEnvelope" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "500": { $ref: "#/components/responses/InternalError" }

webhooks:
  sms.received:
    post:
      operationId: webhookSmsReceived
      summary: sms.received
      description: A new SMS or call code arrived on one of your numbers.
      security: []
      parameters:
        - $ref: "#/components/parameters/NumsifyEventId"
        - $ref: "#/components/parameters/NumsifyEventType"
        - $ref: "#/components/parameters/NumsifySignature"
        - $ref: "#/components/parameters/WebhookUserAgent"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    type: { const: sms.received }
                    data:
                      type: object
                      required: [number, sms]
                      properties:
                        number: { $ref: "#/components/schemas/Number" }
                        sms: { $ref: "#/components/schemas/Sms" }
      responses:
        "2XX":
          description: Return any 2xx status within 10 seconds to acknowledge. Anything else, a timeout or a redirect is retried.
  number.canceled:
    post:
      operationId: webhookNumberCanceled
      summary: number.canceled
      description: A number was canceled (by you) and refunded.
      security: []
      parameters:
        - $ref: "#/components/parameters/NumsifyEventId"
        - $ref: "#/components/parameters/NumsifyEventType"
        - $ref: "#/components/parameters/NumsifySignature"
        - $ref: "#/components/parameters/WebhookUserAgent"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    type: { const: number.canceled }
                    data:
                      type: object
                      required: [number, refunded]
                      properties:
                        number: { $ref: "#/components/schemas/Number" }
                        refunded: { type: boolean, description: Always true. The price went back to your balance. }
      responses:
        "2XX":
          description: Return any 2xx status within 10 seconds to acknowledge. Anything else, a timeout or a redirect is retried.
  number.expired:
    post:
      operationId: webhookNumberExpired
      summary: number.expired
      description: A number expired. `data.refunded` is true when no SMS arrived and the price was refunded.
      security: []
      parameters:
        - $ref: "#/components/parameters/NumsifyEventId"
        - $ref: "#/components/parameters/NumsifyEventType"
        - $ref: "#/components/parameters/NumsifySignature"
        - $ref: "#/components/parameters/WebhookUserAgent"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    type: { const: number.expired }
                    data:
                      type: object
                      required: [number, refunded]
                      properties:
                        number: { $ref: "#/components/schemas/Number" }
                        refunded: { type: boolean }
      responses:
        "2XX":
          description: Return any 2xx status within 10 seconds to acknowledge. Anything else, a timeout or a redirect is retried.
  webhook.test:
    post:
      operationId: webhookTest
      summary: webhook.test
      description: Sent when you press "Send test event" in the dashboard. Always delivered, whatever events you subscribed to.
      security: []
      parameters:
        - $ref: "#/components/parameters/NumsifyEventId"
        - $ref: "#/components/parameters/NumsifyEventType"
        - $ref: "#/components/parameters/NumsifySignature"
        - $ref: "#/components/parameters/WebhookUserAgent"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/WebhookEvent"
                - type: object
                  properties:
                    type: { const: webhook.test }
                    data:
                      type: object
                      properties:
                        message: { type: string, examples: ["This is a test event from Numsify."] }
      responses:
        "2XX":
          description: Return any 2xx status within 10 seconds to acknowledge. Anything else, a timeout or a redirect is retried.

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: nsk_live_<64 hex>
      description: |
        An API key created in the dashboard, sent as `Authorization: Bearer nsk_live_…`.
        The scopes listed on each operation must be granted to the key.

  parameters:
    Page:
      name: page
      in: query
      description: Page number, starting at 1.
      schema: { type: integer, minimum: 1, default: 1 }
    PageSize:
      name: page_size
      in: query
      description: Items per page.
      schema: { type: integer, minimum: 1, maximum: 100, default: 20 }
    NumberId:
      name: id
      in: path
      required: true
      description: The number's `id`.
      schema: { type: string, format: uuid }
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      description: |
        A unique value per order, 8–64 characters (a UUID works). Reuse it only to retry the
        same request: within 24 hours a successful order is replayed from storage, and a failed
        order is not stored, so retrying it with the same key runs it again.
      schema: { type: string, minLength: 8, maxLength: 64 }
      example: 2b6f0cc9-4a0e-4f63-9d3c-6a8f1e2d7b10
    NumsifyEventId:
      name: Numsify-Event-Id
      in: header
      required: true
      description: The event `id`. Use it to ignore duplicate deliveries.
      schema: { type: string, examples: ["evt_9b2c4e6f8a0b1c2d3e4f5a6b7c8d9e0f"] }
    NumsifyEventType:
      name: Numsify-Event-Type
      in: header
      required: true
      schema: { $ref: "#/components/schemas/WebhookEventType" }
    NumsifySignature:
      name: Numsify-Signature
      in: header
      required: true
      description: |
        `t=<unix seconds>,v1=<hex HMAC-SHA256>`. Compute
        `hex(HMAC_SHA256(secret, t + "." + raw_body))` and compare it in constant time with each
        `v1` value; accept if any matches and `t` is within 5 minutes of your clock. For 24 hours
        after a secret rotation the header carries two `v1` values (new and old secret).
      schema: { type: string, examples: ["t=1763805600,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"] }
    WebhookUserAgent:
      name: User-Agent
      in: header
      required: true
      schema: { type: string, const: Numsify-Webhooks/1.0 }

  headers:
    IdempotentReplayed:
      description: "`true` when this response is a stored replay of an earlier request with the same `Idempotency-Key`."
      schema: { type: string, enum: ["true"] }

  responses:
    Unauthorized:
      description: "`UNAUTHORIZED`, `API_KEY_REVOKED` or `API_KEY_EXPIRED`."
      content:
        application/json:
          schema: { $ref: "#/components/schemas/ErrorEnvelope" }
          example:
            success: false
            error: { code: UNAUTHORIZED, message: "Send your API key as: Authorization: Bearer <key>" }
            timestamp: "2026-11-22T10:00:00Z"
    Forbidden:
      description: "`IP_NOT_ALLOWED`, `INSUFFICIENT_SCOPE`, `API_ACCESS_DISABLED` or `BROWSER_REQUESTS_NOT_ALLOWED`."
      content:
        application/json:
          schema: { $ref: "#/components/schemas/ErrorEnvelope" }
          example:
            success: false
            error: { code: INSUFFICIENT_SCOPE, message: This API key is missing the numbers:write scope }
            timestamp: "2026-11-22T10:00:00Z"
    ValidationFailed:
      description: "`VALIDATION_FAILED`."
      content:
        application/json:
          schema: { $ref: "#/components/schemas/ErrorEnvelope" }
    NumberNotFound:
      description: "`NUMBER_NOT_FOUND`."
      content:
        application/json:
          schema: { $ref: "#/components/schemas/ErrorEnvelope" }
    RateLimited:
      description: "`RATE_LIMIT_EXCEEDED`: 120 requests/minute per key, 20 orders/minute per key."
      content:
        application/json:
          schema: { $ref: "#/components/schemas/ErrorEnvelope" }
          example:
            success: false
            error: { code: RATE_LIMIT_EXCEEDED, message: Rate limit exceeded for this API key. Slow down and retry. }
            timestamp: "2026-11-22T10:00:00Z"
    InternalError:
      description: "`INTERNAL_ERROR`."
      content:
        application/json:
          schema: { $ref: "#/components/schemas/ErrorEnvelope" }

  schemas:
    SuccessEnvelope:
      type: object
      required: [success, timestamp]
      properties:
        success: { type: boolean, const: true }
        data: {}
        message: { type: string, description: Optional human-readable note. }
        timestamp: { type: string, format: date-time }
        pagination: { $ref: "#/components/schemas/Pagination" }
    ErrorEnvelope:
      type: object
      required: [success, error, timestamp]
      properties:
        success: { type: boolean, const: false }
        error:
          type: object
          required: [code, message]
          properties:
            code: { $ref: "#/components/schemas/ErrorCode" }
            message: { type: string }
        timestamp: { type: string, format: date-time }
    ErrorCode:
      type: string
      description: Stable machine-readable error code. New codes may be added; treat unknown codes as failures.
      enum:
        - UNAUTHORIZED
        - API_KEY_REVOKED
        - API_KEY_EXPIRED
        - IP_NOT_ALLOWED
        - INSUFFICIENT_SCOPE
        - API_ACCESS_DISABLED
        - BROWSER_REQUESTS_NOT_ALLOWED
        - VALIDATION_FAILED
        - NUMBER_NOT_FOUND
        - INSUFFICIENT_BALANCE
        - DAILY_SPEND_LIMIT_REACHED
        - SERVICE_UNAVAILABLE
        - TEMPORARILY_UNAVAILABLE
        - SERVICE_RESTRICTED
        - CONCURRENT_ORDER
        - ACTIVE_NUMBER_LIMIT
        - CANCELLATION_TOO_EARLY
        - NUMBER_CANCELLED
        - NUMBER_EXPIRED
        - IDEMPOTENCY_KEY_REQUIRED
        - IDEMPOTENCY_KEY_REUSED
        - IDEMPOTENCY_IN_PROGRESS
        - RATE_LIMIT_EXCEEDED
        - INTERNAL_ERROR
    Pagination:
      type: object
      required: [page, page_size, total, total_pages, has_next, has_previous]
      properties:
        page: { type: integer, examples: [1] }
        page_size: { type: integer, examples: [20] }
        total: { type: integer, examples: [150] }
        total_pages: { type: integer, examples: [8] }
        has_next: { type: boolean }
        has_previous: { type: boolean }
    VerificationType:
      type: string
      enum: [sms, call]
    Balance:
      type: object
      required: [balance_cents, currency]
      properties:
        balance_cents: { type: integer, description: Communication balance in US cents., examples: [1250] }
        currency: { type: string, const: USD }
    ServiceRef:
      type: object
      required: [id, code, name]
      properties:
        id: { type: string, format: uuid }
        code: { type: string, examples: [whatsapp] }
        name: { type: string, examples: [WhatsApp] }
    Country:
      type: object
      required: [id, code, name, phone_prefix]
      properties:
        id: { type: string, format: uuid }
        code: { type: string, description: ISO 3166-1 alpha-2 code., examples: [GB] }
        name: { type: string, examples: [United Kingdom] }
        phone_prefix: { type: string, examples: ["+44"] }
    Service:
      type: object
      required: [id, code, name]
      properties:
        id: { type: string, format: uuid }
        code: { type: string, examples: [whatsapp] }
        name: { type: string, examples: [WhatsApp] }
        icon: { type: string, description: Icon image URL or empty string. }
        countries: { type: integer, description: Number of countries offering this service., examples: [120] }
        available: { type: integer, description: Numbers in stock across all countries., examples: [15320] }
    ServiceCountry:
      type: object
      required: [country, price_cents, currency, available, verification_type]
      properties:
        country: { $ref: "#/components/schemas/Country" }
        price_cents: { type: integer, description: Price per number in US cents., examples: [45] }
        currency: { type: string, const: USD }
        available: { type: integer, description: Numbers in stock right now., examples: [230] }
        verification_type: { $ref: "#/components/schemas/VerificationType" }
    OrderNumberRequest:
      type: object
      required: [service_id, country_id]
      properties:
        service_id: { type: string, format: uuid }
        country_id: { type: string, format: uuid }
        verification_type:
          $ref: "#/components/schemas/VerificationType"
          description: Defaults to `sms`.
    Number:
      type: object
      required:
        - id
        - phone_number
        - status
        - verification_type
        - service
        - country
        - price_cents
        - currency
        - sms_count
        - cancelable_after
        - created_at
      properties:
        id: { type: string, format: uuid }
        phone_number: { type: string, description: E.164 number., examples: ["+447700900123"] }
        status:
          type: string
          description: New values may be added; treat unknown values as not active.
          enum: [pending, active, expired, canceled]
        verification_type: { $ref: "#/components/schemas/VerificationType" }
        service: { $ref: "#/components/schemas/ServiceRef" }
        country: { $ref: "#/components/schemas/Country" }
        price_cents: { type: integer, examples: [45] }
        currency:
          type: string
          description: "Always `USD` for API orders. Numbers bought in the mobile app with coins report `COINS`, and then `price_cents` is a coin amount."
          enum: [USD, COINS]
        sms_count: { type: integer, examples: [0] }
        expires_at: { type: [string, "null"], format: date-time }
        cancelable_after: { type: string, format: date-time, description: Cancel is allowed from this time on. }
        last_sms_at: { type: [string, "null"], format: date-time }
        created_at: { type: string, format: date-time }
      example:
        id: 0d7c1f9e-2b3a-4c5d-8e9f-0a1b2c3d4e5f
        phone_number: "+447700900123"
        status: active
        verification_type: sms
        service: { id: 3f6c1d2e-8a4b-4c1e-9f2a-0b1c2d3e4f50, code: whatsapp, name: WhatsApp }
        country: { id: 7a8b9c0d-1e2f-4a3b-8c4d-5e6f7a8b9c0d, code: GB, name: United Kingdom, phone_prefix: "+44" }
        price_cents: 45
        currency: USD
        sms_count: 0
        expires_at: "2026-11-22T10:20:00Z"
        cancelable_after: "2026-11-22T10:02:00Z"
        last_sms_at: null
        created_at: "2026-11-22T10:00:00Z"
    Sms:
      type: object
      required: [id, from, text, verification_type, received_at]
      properties:
        id: { type: string, format: uuid }
        from: { type: string, examples: [WhatsApp] }
        text: { type: string, examples: ["Your WhatsApp code: 123-456"] }
        code: { type: [string, "null"], description: The extracted code when one was found., examples: ["123456"] }
        verification_type: { $ref: "#/components/schemas/VerificationType" }
        received_at: { type: string, format: date-time }
    WebhookEventType:
      type: string
      enum: [sms.received, number.canceled, number.expired, webhook.test]
    WebhookEvent:
      type: object
      required: [id, type, created_at, data]
      properties:
        id: { type: string, description: Unique event ID. Deliveries can repeat; deduplicate on it., examples: [evt_9b2c4e6f8a0b1c2d3e4f5a6b7c8d9e0f] }
        type: { $ref: "#/components/schemas/WebhookEventType" }
        created_at: { type: string, format: date-time }
        data: { type: object }
