openapi: 3.1.0
info:
  title: DiOTP API
  version: 1.1.0
  summary: Send and verify one-time passwords by SMS or WhatsApp in India.
  description: |-
    The DiOTP REST API sends a one-time password to a mobile number and checks the code the user types. DiOTP generates, stores and checks the code, so your server never sees it. Codes expire after 5 minutes, allow 5 attempts and can be verified only once.

    Authenticate every request with your API key as a Bearer token. Keep the key on your server, never in a browser or app. Every error uses one envelope: branch on `error.code`, show or log `error.message`, and quote `error.request_id` to support.
  contact:
    name: DiOTP support
    email: otp-support@diorbit.com
    url: https://diotp.diorbit.com/contact
  termsOfService: https://diotp.diorbit.com/terms
externalDocs:
  description: DiOTP API documentation
  url: https://diotp.diorbit.com/docs
servers:
  - url: https://api-diotp.diorbit.com/v1
    description: Production
security:
  - bearerAuth: []
tags:
  - name: OTP
    description: Send a code and verify it.
  - name: Account
    description: Check the key and read usage.
paths:
  /otp/send:
    post:
      operationId: sendOtp
      tags:
        - OTP
      summary: Send an OTP
      description: "Generates a code and sends it to the number. Keep the returned `request_id`: you need it to verify. Every limit is checked before sending; a send stopped by a limit returns 429 and is neither sent nor charged. Send an `Idempotency-Key` so a retried request never sends a second code."
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OtpSendRequest"
            examples:
              sms:
                summary: SMS to an Indian number
                value:
                  to: "9876543210"
                  country_code: 91
                  channel: sms
                  purpose: signup
              whatsapp:
                summary: WhatsApp, once switched on for the account
                value:
                  to: "9876543210"
                  country_code: 91
                  channel: whatsapp
                  purpose: login
      responses:
        "200":
          description: The code was generated and handed over for sending.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OtpSendResponse"
              example:
                request_id: 7c9e6679-7425-40de-944b-e07fc1f90ae7
                channel: sms
                expires_at: '2026-11-16T10:05:00+00:00'
        "401":
          description: "`unauthorized`: The Authorization header is missing, or the API key is wrong or revoked."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                unauthorized:
                  summary: The Authorization header is missing, or the API key is wrong or revoked.
                  value:
                    error:
                      code: unauthorized
                      message: invalid api key
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "402":
          description: |-
            `trial_used_up`: The free test messages are used up. Ask to go live from the dashboard.

            `insufficient_balance`: The prepaid wallet cannot cover this message. Recharge to keep sending.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                trial_used_up:
                  summary: The free test messages are used up. Ask to go live from the dashboard.
                  value:
                    error:
                      code: trial_used_up
                      message: your free test messages are used up; ask to go live to keep sending
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
                insufficient_balance:
                  summary: The prepaid wallet cannot cover this message. Recharge to keep sending.
                  value:
                    error:
                      code: insufficient_balance
                      message: your wallet balance is too low; recharge to keep sending
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "403":
          description: |-
            `trial_restricted`: In test mode a code can only go to the mobile number verified at sign-up.

            `account_suspended`: Sending is paused on this account. Contact support.

            `template_not_approved`: The template is in the library but not yet approved for this account. Request it from the Templates page.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                trial_restricted:
                  summary: In test mode a code can only go to the mobile number verified at sign-up.
                  value:
                    error:
                      code: trial_restricted
                      message: in test mode you can only send to the number you signed up with; switch to live to send anywhere
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
                account_suspended:
                  summary: Sending is paused on this account. Contact support.
                  value:
                    error:
                      code: account_suspended
                      message: this account is suspended; contact support
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
                template_not_approved:
                  summary: The template is in the library but not yet approved for this account. Request it from the Templates page.
                  value:
                    error:
                      code: template_not_approved
                      message: request this template from the Templates page in your dashboard; it is available after our team approves it
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "409":
          description: |-
            `channel_not_enabled`: The channel (for example whatsapp) is not switched on for this account yet.

            `idempotency_key_reused`: The same Idempotency-Key was sent earlier with a different body.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                channel_not_enabled:
                  summary: The channel (for example whatsapp) is not switched on for this account yet.
                  value:
                    error:
                      code: channel_not_enabled
                      message: this channel is not enabled on your account yet; contact support to turn it on
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
                idempotency_key_reused:
                  summary: The same Idempotency-Key was sent earlier with a different body.
                  value:
                    error:
                      code: idempotency_key_reused
                      message: idempotency_key_reused
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "422":
          description: |-
            `invalid_request`: A field is missing or malformed. The message names the field.

            `template_not_available`: The template id is unknown or cannot be used on this account.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                invalid_request:
                  summary: A field is missing or malformed. The message names the field.
                  value:
                    error:
                      code: invalid_request
                      message: "to: String should match pattern '^[0-9]{6,15}$'"
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
                template_not_available:
                  summary: The template id is unknown or cannot be used on this account.
                  value:
                    error:
                      code: template_not_available
                      message: that template is not available for sending on this account
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "429":
          description: |-
            `resend_cooldown`: A code went to this number less than 30 seconds ago. Nothing was sent or charged.

            `phone_hourly_limit`: This number has had 3 codes in the last hour. Nothing was sent or charged.

            `phone_daily_limit`: This number has had 10 codes today. Nothing was sent or charged.

            `api_key_minute_limit`: This API key sent more than 30 codes in a minute. Nothing was sent or charged.

            `rate_limited`: The account is sending faster than its per-minute ceiling. Nothing was sent or charged.

            `test_limit`: A live account in test mode reached its daily test allowance.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                resend_cooldown:
                  summary: A code went to this number less than 30 seconds ago. Nothing was sent or charged.
                  value:
                    error:
                      code: resend_cooldown
                      message: a code went to this number moments ago; wait before sending another
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
                phone_hourly_limit:
                  summary: This number has had 3 codes in the last hour. Nothing was sent or charged.
                  value:
                    error:
                      code: phone_hourly_limit
                      message: this number has had its hourly allowance
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
                phone_daily_limit:
                  summary: This number has had 10 codes today. Nothing was sent or charged.
                  value:
                    error:
                      code: phone_daily_limit
                      message: this number has had its daily allowance
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
                api_key_minute_limit:
                  summary: This API key sent more than 30 codes in a minute. Nothing was sent or charged.
                  value:
                    error:
                      code: api_key_minute_limit
                      message: this API key is sending faster than its per-minute ceiling
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
                rate_limited:
                  summary: The account is sending faster than its per-minute ceiling. Nothing was sent or charged.
                  value:
                    error:
                      code: rate_limited
                      message: you are sending faster than allowed; slow down
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
                test_limit:
                  summary: A live account in test mode reached its daily test allowance.
                  value:
                    error:
                      code: test_limit
                      message: test mode allows 10 messages a day; switch to live to keep sending
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "503":
          description: "`sending_unavailable`: The message could not be sent right now. Retry with the same Idempotency-Key."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                sending_unavailable:
                  summary: The message could not be sent right now. Retry with the same Idempotency-Key.
                  value:
                    error:
                      code: sending_unavailable
                      message: we could not send this message right now; try again shortly
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
  /otp/verify:
    post:
      operationId: verifyOtp
      tags:
        - OTP
      summary: Verify an OTP
      description: Checks the code the user typed against the request. A 200 means the number is verified. Verifying is free. A code can be verified only once, within 5 minutes, and with at most 5 attempts.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/OtpVerifyRequest"
            example:
              request_id: 7c9e6679-7425-40de-944b-e07fc1f90ae7
              code: "482913"
      responses:
        "200":
          description: The code matched. The number is verified.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OtpVerifyResponse"
              example:
                request_id: 7c9e6679-7425-40de-944b-e07fc1f90ae7
                verified: true
                verified_at: '2026-11-16T10:01:12+00:00'
        "400":
          description: "`invalid_code`: The code does not match. The user can try again until 5 attempts are used."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                invalid_code:
                  summary: The code does not match. The user can try again until 5 attempts are used.
                  value:
                    error:
                      code: invalid_code
                      message: the code is not correct
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "401":
          description: "`unauthorized`: The Authorization header is missing, or the API key is wrong or revoked."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                unauthorized:
                  summary: The Authorization header is missing, or the API key is wrong or revoked.
                  value:
                    error:
                      code: unauthorized
                      message: invalid api key
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "404":
          description: "`not_found`: No OTP request with this request_id exists for your account."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                not_found:
                  summary: No OTP request with this request_id exists for your account.
                  value:
                    error:
                      code: not_found
                      message: unknown request_id
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "409":
          description: |-
            `already_verified`: This code was already verified. A code can be verified only once.

            `not_pending`: The request has already ended (for example, the message failed). Send a new code.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                already_verified:
                  summary: This code was already verified. A code can be verified only once.
                  value:
                    error:
                      code: already_verified
                      message: this request is already verified
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
                not_pending:
                  summary: The request has already ended (for example, the message failed). Send a new code.
                  value:
                    error:
                      code: not_pending
                      message: request is failed
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "410":
          description: "`expired`: More than 5 minutes have passed since the code was sent. Send a new one."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                expired:
                  summary: More than 5 minutes have passed since the code was sent. Send a new one.
                  value:
                    error:
                      code: expired
                      message: the code has expired
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "422":
          description: "`invalid_request`: A field is missing or malformed. The message names the field."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                invalid_request:
                  summary: A field is missing or malformed. The message names the field.
                  value:
                    error:
                      code: invalid_request
                      message: "to: String should match pattern '^[0-9]{6,15}$'"
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "429":
          description: "`too_many_attempts`: All 5 attempts were used. Send a new code."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                too_many_attempts:
                  summary: All 5 attempts were used. Send a new code.
                  value:
                    error:
                      code: too_many_attempts
                      message: too many verification attempts
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "503":
          description: "`sending_unavailable`: The code could not be checked right now. Try again shortly."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                sending_unavailable:
                  summary: The code could not be checked right now. Try again shortly.
                  value:
                    error:
                      code: sending_unavailable
                      message: we could not send this message right now; try again shortly
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
  /me:
    get:
      operationId: getMe
      tags:
        - Account
      summary: Check your API key
      description: Returns the account and the API key the request was made with. Use it to confirm a key works before sending anything, and to read the account status.
      responses:
        "200":
          description: The account and key.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Me"
              example:
                client:
                  id: 42
                  name: Example Store
                  status: live
                key:
                  id: 7
                  name: Production server
                  last_four: a1b2
        "401":
          description: "`unauthorized`: The Authorization header is missing, or the API key is wrong or revoked."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                unauthorized:
                  summary: The Authorization header is missing, or the API key is wrong or revoked.
                  value:
                    error:
                      code: unauthorized
                      message: invalid api key
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
  /usage:
    get:
      operationId: getUsage
      tags:
        - Account
      summary: Read monthly usage
      description: Returns the attempts, accepted messages, billable units and amount for one calendar month. Without `period`, the current month.
      parameters:
        - name: period
          in: query
          required: false
          description: The month, as YYYY-MM. Defaults to the current month.
          schema:
            type: string
            pattern: ^[0-9]{4}-[0-9]{2}$
            examples:
              - 2026-11
          example: 2026-11
      responses:
        "200":
          description: Usage for the month.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Usage"
              example:
                period: 2026-11
                attempts: 42
                accepted: 40
                billable_units: 40
                amount: "16.00"
        "401":
          description: "`unauthorized`: The Authorization header is missing, or the API key is wrong or revoked."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                unauthorized:
                  summary: The Authorization header is missing, or the API key is wrong or revoked.
                  value:
                    error:
                      code: unauthorized
                      message: invalid api key
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
        "422":
          description: "`invalid_request`: The period is not in YYYY-MM form."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              examples:
                invalid_request:
                  summary: The period is not in YYYY-MM form.
                  value:
                    error:
                      code: invalid_request
                      message: period must be YYYY-MM
                      request_id: 3f1a9c0b2d4e4f6a8b7c5d1e0f2a3b4c
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: "Your API key from API keys in the dashboard, sent as `Authorization: Bearer <API key>`. Keep it server-side."
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: Any unique string, such as a UUID per user action. A retry with the same key and the same body returns the first response and sends nothing new. The same key with a different body returns 409 `idempotency_key_reused`.
      schema:
        type: string
        maxLength: 128
      example: 5f2b8c1e-4d3a-4e7b-9a1c-0e6f7d8b9a2c
  schemas:
    OtpSendRequest:
      type: object
      required:
        - to
      additionalProperties: false
      properties:
        to:
          type: string
          pattern: ^[0-9]{6,15}$
          description: The mobile number, digits only. For India, the 10-digit number without +91.
          examples:
            - "9876543210"
        country_code:
          type: integer
          default: 91
          description: The country calling code, without +.
          examples:
            - 91
        channel:
          type: string
          enum:
            - sms
            - whatsapp
          default: sms
          description: How the code is sent. WhatsApp must be switched on for the account; until then a send returns 409 `channel_not_enabled`.
        purpose:
          type: string
          default: login
          description: A free label for your own reporting, such as login, signup or payment.
          examples:
            - signup
        template:
          type:
            - string
            - "null"
          maxLength: 64
          description: Optional id of a ready-made OTP template from the Templates page in the dashboard. Library templates work once our team approves them for your account; request one on the Templates page. Omit it to use the account default.
        digits:
          type: integer
          enum: [4, 6, 8]
          default: 6
          description: How many digits the code has. 4, 6 or 8. Defaults to 6. Any other value is refused with 422 invalid_request.
          examples:
            - 8
    OtpSendResponse:
      type: object
      required:
        - request_id
        - channel
        - expires_at
      properties:
        request_id:
          type: string
          description: The id of this OTP request. Pass it to /otp/verify.
          examples:
            - 7c9e6679-7425-40de-944b-e07fc1f90ae7
        channel:
          type: string
          enum:
            - sms
            - whatsapp
          description: The channel the code was sent on.
        expires_at:
          type: string
          format: date-time
          description: "When the code stops working: 5 minutes after sending."
    OtpVerifyRequest:
      type: object
      required:
        - request_id
        - code
      additionalProperties: false
      properties:
        request_id:
          type: string
          description: The request_id returned by /otp/send.
          examples:
            - 7c9e6679-7425-40de-944b-e07fc1f90ae7
        code:
          type: string
          minLength: 4
          maxLength: 10
          description: The code the user typed, as a string.
          examples:
            - "482913"
    OtpVerifyResponse:
      type: object
      required:
        - request_id
        - verified
        - verified_at
      properties:
        request_id:
          type: string
          description: The OTP request that was verified.
        verified:
          type: boolean
          const: true
          description: Always true on a 200.
        verified_at:
          type: string
          format: date-time
          description: When the code was verified.
    Me:
      type: object
      required:
        - client
        - key
      properties:
        client:
          type: object
          required:
            - id
            - name
            - status
          properties:
            id:
              type: integer
              description: Your account id.
            name:
              type: string
              description: Your account name.
            status:
              type: string
              enum:
                - trial
                - pending_review
                - live
                - suspended
              description: "trial: test mode. pending_review: asked to go live, being checked. live: sends to any number. suspended: sending paused."
        key:
          type: object
          required:
            - id
            - name
            - last_four
          properties:
            id:
              type: integer
              description: The API key id.
            name:
              type: string
              description: The name you gave the key.
            last_four:
              type: string
              minLength: 4
              maxLength: 4
              description: The last four characters of the key.
    Usage:
      type: object
      required:
        - period
        - attempts
        - accepted
        - billable_units
        - amount
      properties:
        period:
          type: string
          description: The month, as YYYY-MM.
          examples:
            - 2026-11
        attempts:
          type: integer
          description: Sends attempted in the month.
        accepted:
          type: integer
          description: Sends accepted for delivery.
        billable_units:
          type: integer
          description: Messages charged.
        amount:
          type: string
          description: The amount charged for the month in rupees, as a decimal string.
          examples:
            - "16.00"
    Error:
      type: object
      required:
        - error
      description: Every error has this shape. Branch on code; it never changes.
      properties:
        error:
          type: object
          required:
            - code
            - message
            - request_id
          properties:
            code:
              type: string
              description: A stable, machine-readable code such as invalid_code.
            message:
              type: string
              description: A sentence for people. Its wording can change.
            request_id:
              type: string
              description: The id of this HTTP request (also in the X-Request-Id header). Quote it to support.
