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

# Start a credit top-up

> Opens a hosted checkout session. Credits are granted by the webhook when payment succeeds, NEVER on return from the redirect: crediting on redirect would let anyone with the return URL mint credits.



## OpenAPI

````yaml /api-reference/billing.json post /api/billing/checkout
openapi: 3.1.0
info:
  title: truscan billing
  version: 1.0.0
  description: >-
    Credits, metering and top-ups. Money is counted in MICRO-DOLLARS (millionths
    of a dollar) as integers everywhere, so $7.00 per 1,000 requests is exactly
    7,000 micros per request. Floats drift, and a billing system that drifts
    gets disputed. Every amount is accompanied by a pre-formatted display string
    so no client reimplements money formatting. All responses use the {success,
    result, message} envelope except health and the webhook.
servers:
  - url: https://api.truscan.co
    description: Production
security: []
paths:
  /api/billing/checkout:
    post:
      summary: Start a credit top-up
      description: >-
        Opens a hosted checkout session. Credits are granted by the webhook when
        payment succeeds, NEVER on return from the redirect: crediting on
        redirect would let anyone with the return URL mint credits.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - amount_cents
              properties:
                amount_cents:
                  type: integer
                  minimum: 500
                  maximum: 500000
                  description: >-
                    The unit the payment provider charges in. Sent as an integer
                    so no rounding happens client-side.
      responses:
        '201':
          description: Checkout session created
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                  result:
                    $ref: '#/components/schemas/Checkout'
        '422':
          $ref: '#/components/responses/Failure'
        '502':
          $ref: '#/components/responses/Failure'
        '503':
          $ref: '#/components/responses/Failure'
components:
  schemas:
    Checkout:
      type: object
      properties:
        payment_id:
          type: string
        checkout_url:
          type: string
          format: uri
        amount_cents:
          type: integer
        credits_micros:
          type: integer
        credits_display:
          type: string
    Failure:
      type: object
      properties:
        success:
          type: boolean
          const: false
        message:
          type: string
          description: Written for a person.
        result:
          type: object
          properties:
            code:
              type: string
              enum:
                - insufficient_credits
                - payments_unavailable
                - invalid_amount
                - unauthorized
                - validation_failed
                - internal_error
                - upstream_unavailable
  responses:
    Failure:
      description: >-
        The envelope with success false. result carries the machine-readable
        code and nothing else.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Failure'

````