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

> Get one credit purchase attempt by ID to poll it to a terminal state and read the decline reason recorded on failure.

# Get a credit purchase



## OpenAPI

````yaml openapi/ai-gateway.yaml GET /credits/purchases/{id}
openapi: 3.0.3
info:
  title: AI Gateway APIs
  version: 0.1.0
  description: |
    Control-plane HTTP APIs served by the ai-gateway-control service.
servers:
  - url: https://api.ngrok.ai
security:
  - bearerAuth: []
tags:
  - name: AI Gateway Access Key Configurations
    description: Manage reusable access key configurations (scope and routing rules).
  - name: AI Gateway Access Keys
    description: Manage ngrok-managed access keys associated with AI Gateway endpoints.
  - name: AI Gateway Configuration
    description: >-
      Manage per-account AI Gateway configuration (timeouts, token caps,
      metadata).
  - name: AI Gateway API Keys
    description: Manage customer-facing AI Gateway API Keys.
  - name: AI Gateway Credits
    description: >-
      Purchase AI Gateway credits, via Stripe Checkout or a charge of the saved
      card, and read purchase/transaction history.
  - name: AI Gateway Providers
    description: Manage AI Gateway providers and the models they expose.
  - name: AI Gateway Custom Providers
    description: Manage custom AI Gateway providers and the models they expose.
  - name: AI Gateway Models
    description: >-
      Read-only listing of AI Gateway models available to the authenticated
      account.
  - name: AI Gateway Provider Keys
    description: Manage provider keys attached to AI Gateway managed access keys.
  - name: AI Gateway Usage
    description: >-
      Read-only AI Gateway usage events and aggregated usage overview for the
      authenticated account.
paths:
  /credits/purchases/{id}:
    parameters:
      - $ref: '#/components/parameters/CreditPurchaseID'
    get:
      tags:
        - AI Gateway Credits
      summary: Get a credit purchase
      description: >
        Get a credit purchase by ID. Use this endpoint to poll the purchase
        until

        it reaches a terminal state and to read the decline reason if it fails.


        `pending` means the payment outcome has not been recorded yet. A
        purchase

        may remain `pending` briefly after the charge has settled.
      operationId: GetCreditPurchase
      responses:
        '200':
          description: The credit purchase attempt.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreditPurchase'
        default:
          $ref: '#/components/responses/Error'
components:
  parameters:
    CreditPurchaseID:
      name: id
      in: path
      required: true
      description: Unique identifier for a credit purchase attempt.
      schema:
        type: string
  schemas:
    CreditPurchase:
      type: object
      additionalProperties: false
      required:
        - id
        - status
        - amountCents
        - currency
        - createdAt
        - expiresAt
      properties:
        id:
          type: string
          description: Unique identifier for this credit purchase attempt.
        status:
          type: string
          enum:
            - pending
            - actionRequired
            - succeeded
            - failed
          description: >
            Current state of the purchase. Poll GET until it reaches a terminal

            state (succeeded or failed).


            An asynchronous webhook records `succeeded` and `actionRequired`,
            and

            a periodic sweep backstops a lost webhook. A purchase can therefore

            stay `pending` until the next sweep runs, after the charge itself

            settles.
        amountCents:
          type: integer
          format: int64
          description: Amount purchased, in cents.
        currency:
          type: string
          description: ISO 4217 currency code, lowercase.
        createdAt:
          type: string
          format: date-time
          description: When the purchase attempt was started.
        expiresAt:
          type: string
          format: date-time
          description: When the purchased credits stop being usable.
        failureCode:
          type: string
          nullable: true
          description: |
            Machine-readable decline reason. Set when status is failed, and also
            set to `ambiguous_upstream` while status is pending if a prior
            attempt's outcome could not be determined.
        failureMessage:
          type: string
          nullable: true
          description: Human-readable decline detail, set only when status is failed.
    Error:
      type: object
      additionalProperties: false
      required:
        - statusCode
        - msg
        - details
      properties:
        errorCode:
          type: string
          description: Stable ngrok error code when available.
        statusCode:
          type: integer
          format: int32
          description: HTTP status code for this error.
        msg:
          type: string
          description: Human-readable error message.
        details:
          type: object
          description: Structured error details.
          additionalProperties:
            type: string
  responses:
    Error:
      description: API error response.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````