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

# Top up credits (x402, USDC on Base)

> Buy credits for the API key's account, paid in USDC on Base mainnet over the x402 v2 protocol. Without a payment the call returns 402 with a PAYMENT-REQUIRED header carrying the exact-scheme terms (amount = credits × $0.05); an x402 client signs an EIP-3009 transferWithAuthorization (gasless for the payer) and retries with a PAYMENT-SIGNATURE header. Credits are granted only after on-chain settlement, exactly once per payment authorization — retrying a settled payment replays the original result instead of double-crediting. The payer must be a plain EOA holding USDC on Base.



## OpenAPI

````yaml /openapi.json post /api/v1/credits/topup
openapi: 3.0.3
info:
  title: Chance Verification API
  version: 1.0.0
  description: >-
    Verify an AI agent's proposed action against its stated intent, and get back
    a verdict with a provable receipt — hash-chained, signed by an attested
    judge key, and anchored onchain.
servers:
  - url: https://harness.chance.cc
    description: Production
security:
  - ApiKeyAuth: []
paths:
  /api/v1/credits/topup:
    post:
      summary: Top up credits (x402, USDC on Base)
      description: >-
        Buy credits for the API key's account, paid in USDC on Base mainnet over
        the x402 v2 protocol. Without a payment the call returns 402 with a
        PAYMENT-REQUIRED header carrying the exact-scheme terms (amount =
        credits × $0.05); an x402 client signs an EIP-3009
        transferWithAuthorization (gasless for the payer) and retries with a
        PAYMENT-SIGNATURE header. Credits are granted only after on-chain
        settlement, exactly once per payment authorization — retrying a settled
        payment replays the original result instead of double-crediting. The
        payer must be a plain EOA holding USDC on Base.
      operationId: topupCredits
      parameters:
        - name: credits
          in: query
          required: true
          description: >-
            How many credits to buy (1 credit = $0.05). Default bounds:
            20–10000.
          schema:
            type: integer
            minimum: 20
            maximum: 10000
        - name: account
          in: query
          required: false
          description: >-
            Public account code (chance_topup_…) naming the account to credit.
            Use this instead of an x-api-key header when paying on someone
            else's behalf; the code can only add credits.
          schema:
            type: string
      responses:
        '200':
          description: >-
            Payment settled and credits granted. The PAYMENT-RESPONSE header
            carries the x402 settlement (tx hash, payer, network).
          headers:
            PAYMENT-RESPONSE:
              description: Base64-encoded x402 v2 settlement response.
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TopupReceipt'
        '400':
          description: Missing or out-of-bounds credits parameter.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing, invalid, or revoked API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '402':
          description: >-
            Payment required (no payment attached), or the attached payment
            failed verification/settlement — the body's `error` explains which.
            Sign the terms in the PAYMENT-REQUIRED header and retry with a
            PAYMENT-SIGNATURE header.
          headers:
            PAYMENT-REQUIRED:
              description: >-
                Base64-encoded x402 v2 PaymentRequired (exact scheme,
                eip155:8453, USDC).
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: >-
            This payment authorization was already submitted for a different
            account.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '502':
          description: >-
            The payment facilitator is unavailable — retry with the SAME payment
            header; crediting is idempotent.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: Top-ups are not enabled on this deployment.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    TopupReceipt:
      type: object
      properties:
        credited:
          type: integer
          description: Credits added by this payment.
          example: 200
        usd:
          type: string
          example: '10.00'
        creditsRemaining:
          type: integer
          description: New balance.
          example: 203
        txHash:
          type: string
          nullable: true
          description: Base settlement transaction hash.
        payer:
          type: string
          description: Wallet that paid (recovered from the signature).
        replayed:
          type: boolean
          description: >-
            True when this response replays an already-credited payment
            (idempotent retry).
    Error:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: Your Chance API key (chance_sk_…), created in the dashboard.

````