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

# Get a Telegram code

> Returns a Telegram code and its delivery status. The status is refreshed from Telegram when it may have changed.



## OpenAPI

````yaml api-reference/openapi.yaml GET /messages/telegram/{sid}
openapi: 3.1.0
info:
  title: OTPBay API
  version: 1.0.0
  description: >-
    Send one-time passwords over Telegram and SMS, verify the codes your users
    enter, and send transactional SMS from your own sender ID.
  contact:
    name: OTPBay support
    email: hello@otpbay.com
servers:
  - url: https://api.otpbay.com/v1
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Project
    description: The project that owns the API key.
  - name: Verify
    description: >-
      Send a code and check it. OTPBay generates the code and falls back from
      Telegram to SMS.
  - name: SMS
    description: Send any text message from one of your approved sender IDs.
  - name: Telegram
    description: Send a one-time code to a Telegram account through the Telegram Gateway.
paths:
  /messages/telegram/{sid}:
    get:
      tags:
        - Telegram
      summary: Get a Telegram code
      description: >-
        Returns a Telegram code and its delivery status. The status is refreshed
        from Telegram when it may have changed.
      operationId: getTelegramCode
      parameters:
        - $ref: '#/components/parameters/TelegramSid'
      responses:
        '200':
          description: The Telegram code.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TelegramMessage'
              example:
                sid: TG6650c52ad3e4f5a6b7c8d9e0
                status: read
                verification_status: null
                to: '+14155552671'
                code_length: 6
                cost: '0.02'
                date_created: '2026-09-26T10:22:40.011Z'
                expires_at: '2026-09-26T10:27:40.011Z'
                delivered_at: '2026-09-26T10:22:41.508Z'
                verified_at: null
                metadata:
                  user_id: usr_1042
        '400':
          $ref: '#/components/responses/InvalidSid'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/IpNotAllowed'
        '404':
          $ref: '#/components/responses/TelegramNotFound'
components:
  parameters:
    TelegramSid:
      name: sid
      in: path
      required: true
      description: The Telegram code `sid` returned by Send a Telegram code.
      schema:
        type: string
        pattern: ^TG[a-fA-F0-9]{24}$
        example: TG6650c52ad3e4f5a6b7c8d9e0
  schemas:
    TelegramMessage:
      type: object
      required:
        - sid
        - status
        - verification_status
        - to
        - code_length
        - cost
        - date_created
        - expires_at
        - delivered_at
        - verified_at
        - metadata
      properties:
        sid:
          type: string
          pattern: ^TG[a-f0-9]{24}$
          description: Unique Telegram code ID.
          example: TG6650c52ad3e4f5a6b7c8d9e0
        status:
          type: string
          enum:
            - sending
            - sent
            - delivered
            - read
            - expired
            - revoked
            - failed
          description: >-
            Delivery status reported by Telegram. `failed` means the code never
            reached Telegram.
        verification_status:
          type:
            - string
            - 'null'
          enum:
            - code_valid
            - code_invalid
            - code_max_attempts_exceeded
            - expired
            - null
          description: Result of the latest code check, or `null` before the first check.
        to:
          $ref: '#/components/schemas/PhoneNumber'
        code_length:
          type: integer
          description: Number of digits in the code.
          example: 6
        cost:
          allOf:
            - $ref: '#/components/schemas/Money'
          description: What this code currently costs. `0.00` after a refund.
          example: '0.02'
        date_created:
          type: string
          format: date-time
        expires_at:
          type: string
          format: date-time
        delivered_at:
          type:
            - string
            - 'null'
          format: date-time
        verified_at:
          type:
            - string
            - 'null'
          format: date-time
        metadata:
          $ref: '#/components/schemas/Metadata'
        last_error:
          type: string
          description: Why the code couldn't be sent. Only present when there is one.
    PhoneNumber:
      type: string
      description: >-
        Destination phone number in international format. OTPBay normalizes it
        to E.164, so `+1 (415) 555-2671` becomes `+14155552671`.
      example: '+14155552671'
    Money:
      type: string
      pattern: ^\d+\.\d{2}$
      description: Amount in US dollars as a decimal string.
      example: '0.02'
    Metadata:
      type: object
      description: >-
        Your own key-value data, returned in responses and webhooks. At most 32
        keys of 1–64 characters. Values are strings (up to 512 characters),
        numbers or booleans.
      maxProperties: 32
      additionalProperties:
        oneOf:
          - type: string
            maxLength: 512
          - type: number
          - type: boolean
      example:
        user_id: usr_1042
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: >-
                Stable, machine-readable error code. Branch on this, not on
                `message`.
              example: INSUFFICIENT_BALANCE
            message:
              type: string
              description: Human-readable explanation. The wording can change.
              example: Insufficient balance for this verification.
  responses:
    InvalidSid:
      description: >-
        `INVALID_MESSAGE_SID` — the `sid` doesn't have the right prefix and 24
        hex characters.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: INVALID_MESSAGE_SID
              message: '`sid` must match VExxxxxxxxxxxxxxxxxxxxxxxx (ObjectId hex).'
    Unauthorized:
      description: '`MISSING_API_KEY` or `INVALID_API_KEY`.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: INVALID_API_KEY
              message: Invalid API key.
    IpNotAllowed:
      description: >-
        `IP_NOT_ALLOWED` — the project's IP allowlist is on and your address
        isn't in it.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: IP_NOT_ALLOWED
              message: This IP address is not allowed for this project.
    TelegramNotFound:
      description: >-
        `TELEGRAM_MESSAGE_NOT_FOUND` — no Telegram code with this `sid` in your
        project.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: TELEGRAM_MESSAGE_NOT_FOUND
              message: Telegram message was not found for this account.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your project API key, sent as `Authorization: Bearer otp_live_...`.
        Create keys on the **API Keys** page of the dashboard.

````