{
  "openapi": "3.0.3",
  "info": {
    "title": "OnayNet REST API",
    "version": "1.0.0",
    "description": "Allocate phone numbers for SMS verification and read the received codes over HTTPS JSON.\n\nNotes:\n- Authenticated endpoints need your API key (`onay_live_...`) in `Authorization: Bearer` or `X-API-Key`. Keys in the URL are rejected.\n- Response fields are at the top level (no `data` wrapper). Only `GET /orders` returns a `data` array with `has_more` and `next_cursor`.\n- Rate limits: 120 read and 30 write requests per minute per API key, plus 300 requests per minute per IP address (HTTP 429 with `Retry-After`; responses carry `RateLimit-*` headers).\n- Errors always have the shape `{ success: false, code, error }`. Branch on `code`.\n- Browser (cross-origin) calls are not supported; call the API from your server.\n- Stock numbers are indicative, not a guarantee that a number can be allocated. Refunds follow the refund policy on the website.\n- Documentation: https://onaynet.co/en/api-docs",
    "contact": {
      "name": "OnayNet",
      "url": "https://onaynet.co/en/api-docs"
    }
  },
  "servers": [
    {
      "url": "https://onaynet.co/api/v1"
    }
  ],
  "tags": [
    {
      "name": "Account"
    },
    {
      "name": "Catalog"
    },
    {
      "name": "Orders"
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key, e.g. `Authorization: Bearer onay_live_...`"
      },
      "ApiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "success",
          "code",
          "error"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "example": false
          },
          "code": {
            "type": "string",
            "description": "Machine-readable code. Branch on this, not on `error`. Codes: MISSING_PARAMETERS, INVALID_PARAMETER, ORDER_HAS_SMS, NO_SMS_RECEIVED, INVALID_IDEMPOTENCY_KEY, IDEMPOTENCY_IN_PROGRESS, IDEMPOTENCY_KEY_REUSED, ORDER_CLOSED, UNAUTHORIZED, INVALID_API_KEY, API_KEY_IN_URL, API_KEY_SCOPE, AUTH_FAILED, INSUFFICIENT_BALANCE, ACCOUNT_SUSPENDED, ORDER_NOT_FOUND, ACCOUNT_NOT_FOUND, NOT_FOUND, NO_STOCK, INVALID_PRICE, ALLOCATION_FAILED, RATE_LIMITED, INTERNAL_ERROR, UPSTREAM_UNAVAILABLE. Provider-specific codes can also appear on POST /orders/buy."
          },
          "error": {
            "type": "string",
            "description": "English message for humans."
          }
        }
      },
      "Sms": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "text": {
            "type": "string"
          }
        }
      },
      "OrderStatus": {
        "type": "string",
        "enum": [
          "PENDING",
          "RECEIVED",
          "FINISHED",
          "CANCELED",
          "TIMEOUT",
          "BANNED",
          "EXPIRED",
          "REFUNDED"
        ]
      },
      "Balance": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "account_id": {
            "type": "integer"
          },
          "email": {
            "type": "string"
          },
          "balance_usd": {
            "type": "number"
          },
          "currency": {
            "type": "string",
            "example": "USD"
          },
          "webhook_url": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "Operator": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "activation": {
            "type": "boolean"
          },
          "hosting": {
            "type": "boolean"
          }
        }
      },
      "Country": {
        "type": "object",
        "properties": {
          "country": {
            "type": "string",
            "example": "turkey",
            "description": "Slug to use as the `country` value in other calls."
          },
          "name": {
            "type": "string"
          },
          "iso": {
            "type": "string",
            "example": "TR"
          },
          "dial_code": {
            "type": "string",
            "example": "+90"
          },
          "operators": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Operator"
            }
          }
        }
      },
      "Countries": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "count": {
            "type": "integer"
          },
          "countries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Country"
            }
          }
        }
      },
      "Service": {
        "type": "object",
        "properties": {
          "service": {
            "type": "string",
            "example": "whatsapp"
          },
          "category": {
            "type": "string",
            "example": "activation"
          },
          "stock": {
            "type": "integer",
            "description": "Indicative total. Not a guarantee that a number can be allocated."
          },
          "price_usd": {
            "type": "number"
          },
          "o1_stock": {
            "type": "integer"
          },
          "o1_price_usd": {
            "type": "number"
          },
          "o1_rate": {
            "type": "integer",
            "nullable": true,
            "description": "Always null: no measured success rate is available for O1."
          },
          "o2_stock": {
            "type": "integer"
          },
          "o2_price_usd": {
            "type": "number"
          },
          "o2_rate": {
            "type": "integer",
            "nullable": true,
            "description": "Success rate reported by the upstream provider, when available."
          }
        }
      },
      "Services": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "country": {
            "type": "string"
          },
          "operator": {
            "type": "string"
          },
          "count": {
            "type": "integer"
          },
          "services": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Service"
            }
          }
        }
      },
      "BuyRequest": {
        "type": "object",
        "required": [
          "country",
          "service"
        ],
        "properties": {
          "country": {
            "type": "string",
            "example": "usa",
            "description": "Country slug from GET /countries."
          },
          "service": {
            "type": "string",
            "example": "openai",
            "description": "Service slug from GET /services. `product` is accepted as an alias."
          },
          "operator": {
            "type": "string",
            "default": "any",
            "description": "`any`, `o1`, `o2_pool`, or an operator name from GET /countries."
          },
          "max_price": {
            "type": "number",
            "description": "Maximum price in USD you are willing to pay (alias `maxPrice`)."
          },
          "voice": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "BuyResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "order_id": {
            "type": "integer"
          },
          "phone": {
            "type": "string"
          },
          "service": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "operator": {
            "type": "string"
          },
          "price_usd": {
            "type": "number"
          },
          "status": {
            "$ref": "#/components/schemas/OrderStatus"
          },
          "sms": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Sms"
            }
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "remaining_balance_usd": {
            "type": "number"
          }
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "order_id": {
            "type": "integer"
          },
          "status": {
            "$ref": "#/components/schemas/OrderStatus"
          },
          "phone": {
            "type": "string"
          },
          "service": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "price_usd": {
            "type": "number"
          },
          "sms": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Sms"
            }
          },
          "latest_code": {
            "type": "string",
            "nullable": true
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "upgrade_offer": {
            "$ref": "#/components/schemas/UpgradeOffer"
          }
        }
      },
      "OrderListItem": {
        "type": "object",
        "properties": {
          "order_id": {
            "type": "integer"
          },
          "status": {
            "$ref": "#/components/schemas/OrderStatus"
          },
          "phone": {
            "type": "string"
          },
          "service": {
            "type": "string"
          },
          "country": {
            "type": "string"
          },
          "price_usd": {
            "type": "number"
          },
          "sms": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Sms"
            }
          },
          "latest_code": {
            "type": "string",
            "nullable": true
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "OrderList": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderListItem"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": "integer",
            "nullable": true
          }
        }
      },
      "CancelResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "order_id": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "example": "CANCELED"
          },
          "refunded_usd": {
            "type": "number"
          },
          "balance_usd": {
            "type": "number"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "FinishResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "order_id": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "example": "FINISHED"
          }
        }
      },
      "UpgradeOffer": {
        "type": [
          "object",
          "null"
        ],
        "description": "Present when the order is a HeroSMS order that closed without a code (fee refunded), within 2 hours of the order and not upgraded before. A higher price does not guarantee a code.",
        "properties": {
          "price_usd": {
            "type": "number",
            "description": "Price of the next, higher-priced option in USD."
          }
        }
      },
      "UpgradeRequest": {
        "type": "object",
        "properties": {
          "expected_price_usd": {
            "type": "number",
            "description": "upgrade_offer.price_usd you accepted. If the current price differs, nothing is charged and 409 PRICE_CHANGED is returned."
          }
        }
      },
      "UpgradeResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "replayed": {
            "type": "boolean",
            "description": "true if this order was already upgraded; the existing new order is returned and nothing is charged again."
          },
          "order_id": {
            "type": "integer",
            "description": "The new order."
          },
          "upgraded_from": {
            "type": "integer"
          },
          "phone": {
            "type": "string"
          },
          "price_usd": {
            "type": "number"
          },
          "status": {
            "type": "string",
            "example": "PENDING"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  },
  "paths": {
    "/balance": {
      "get": {
        "tags": [
          "Account"
        ],
        "summary": "Wallet balance and account info",
        "operationId": "getBalance",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyHeader": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Balance"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/countries": {
      "get": {
        "tags": [
          "Catalog"
        ],
        "summary": "List countries",
        "operationId": "listCountries",
        "description": "Public. Returns country slugs, ISO codes, dial codes and operators. Cached for about an hour.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Countries"
                }
              }
            }
          },
          "502": {
            "description": "Country directory temporarily unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/services": {
      "get": {
        "tags": [
          "Catalog"
        ],
        "summary": "Services, indicative stock and prices for a country",
        "operationId": "listServices",
        "description": "Public. An unknown country returns 200 with an empty list.",
        "parameters": [
          {
            "name": "country",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "usa"
            },
            "description": "Country slug from GET /countries."
          },
          {
            "name": "operator",
            "in": "query",
            "schema": {
              "type": "string",
              "default": "any"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Services"
                }
              }
            }
          },
          "502": {
            "description": "Service inventory unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/orders/buy": {
      "post": {
        "tags": [
          "Orders"
        ],
        "summary": "Allocate a number",
        "operationId": "buyNumber",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyHeader": []
          }
        ],
        "description": "Charges your balance and returns the allocated number. Send an optional `Idempotency-Key` header (1-64 characters: letters, digits, - _ : .) to make retries safe: if a request times out, retry with the same key and parameters and the successful purchase is replayed with the response header `Idempotent-Replayed: true` instead of being charged again. Keys are scoped to your account and kept for 24 hours; a failed purchase releases the key. Without a key, check GET /orders before retrying to avoid a duplicate purchase.",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64,
              "pattern": "^[A-Za-z0-9_\\-:.]{1,64}$"
            },
            "description": "Optional. Reusing a key with different parameters returns 422 IDEMPOTENCY_KEY_REUSED; a request still being processed returns 409 IDEMPOTENCY_IN_PROGRESS."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BuyRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Number allocated.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BuyResponse"
                }
              }
            }
          },
          "400": {
            "description": "MISSING_PARAMETERS or INVALID_IDEMPOTENCY_KEY",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "INSUFFICIENT_BALANCE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "IDEMPOTENCY_IN_PROGRESS: a request with the same Idempotency-Key is still being processed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "NO_STOCK, INVALID_PRICE, ALLOCATION_FAILED or IDEMPOTENCY_KEY_REUSED (provider-specific codes may appear).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "RATE_LIMITED or rate limit exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/orders": {
      "get": {
        "tags": [
          "Orders"
        ],
        "summary": "List your orders (newest first)",
        "operationId": "listOrders",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyHeader": []
          }
        ],
        "description": "Shows the last known state stored on our side. Poll GET /orders/{id} for the live status of one order.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/OrderStatus"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "description": "Use `next_cursor` from the previous page."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid limit, status or cursor.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/orders/{id}": {
      "get": {
        "tags": [
          "Orders"
        ],
        "summary": "Order status and received SMS",
        "operationId": "getOrder",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyHeader": []
          }
        ],
        "description": "Poll while the status is PENDING. A closed order without SMS is refunded automatically.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Order ID returned by POST /orders/buy."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "404": {
            "description": "Order not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/orders/{id}/cancel": {
      "post": {
        "tags": [
          "Orders"
        ],
        "summary": "Cancel an order that has not received an SMS",
        "operationId": "cancelOrder",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Order ID returned by POST /orders/buy."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CancelResponse"
                }
              }
            }
          },
          "400": {
            "description": "ORDER_HAS_SMS: an order that already received an SMS cannot be cancelled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Order not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/orders/{id}/ban": {
      "post": {
        "tags": [
          "Orders"
        ],
        "summary": "Report a number as unusable and refund the order",
        "operationId": "banOrder",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyHeader": []
          }
        ],
        "description": "Only for orders that have not received an SMS (otherwise ORDER_HAS_SMS). The refund is immediate; the number is released at the provider in the background. Banning an already closed order returns its current status.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Order ID returned by POST /orders/buy."
          }
        ],
        "responses": {
          "200": {
            "description": "Order banned and refunded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CancelResponse"
                }
              }
            }
          },
          "400": {
            "description": "ORDER_HAS_SMS: an order that already received an SMS cannot be banned.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Order not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/orders/{id}/finish": {
      "post": {
        "tags": [
          "Orders"
        ],
        "summary": "Mark an order that received an SMS as finished",
        "operationId": "finishOrder",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyHeader": []
          }
        ],
        "description": "Rejected with NO_SMS_RECEIVED when no SMS arrived (cancel the order instead) and with ORDER_CLOSED when the order is already closed. Finishing an already finished order succeeds.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Order ID returned by POST /orders/buy."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FinishResponse"
                }
              }
            }
          },
          "400": {
            "description": "NO_SMS_RECEIVED or ORDER_CLOSED.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Order not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/orders/{id}/upgrade": {
      "post": {
        "tags": [
          "Orders"
        ],
        "summary": "Buy a new number from a higher-priced option after an order closed without a code",
        "operationId": "upgradeOrder",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyHeader": []
          }
        ],
        "description": "Only when GET /orders/{id} returns a non-null upgrade_offer. Send the accepted price as expected_price_usd. Once per order; repeating the request returns the same new order (replayed: true). A higher price does not guarantee a code; if no code arrives, this fee is refunded too.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Order ID returned by POST /orders/buy."
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpgradeRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "New number allocated and charged.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpgradeResponse"
                }
              }
            }
          },
          "200": {
            "description": "Already upgraded: the existing new order (replayed: true).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpgradeResponse"
                }
              }
            }
          },
          "402": {
            "description": "INSUFFICIENT_BALANCE (required_usd, balance_usd).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "ORDER_NOT_FOUND.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "NO_UPGRADE (no higher-priced option for this order) or PRICE_CHANGED (price_usd has the new price; nothing charged).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "NO_STOCK: no numbers at this price option right now.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
