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

# Set auto-recharge

> Stores auto-recharge settings and returns the updated billing state. Requires `billing_write`.

When enabled, and a card is saved, the server checks after each run admission and after each `402`: if the available balance is below `threshold_micros`, it charges `amount_micros` to the saved card, at most once per organization per clock hour. The credit lands when the payment succeeds. See [Auto-recharge](/guides/auto-recharge).



## OpenAPI

````yaml /api-reference/openapi.json put /v1/billing/auto-recharge
openapi: 3.1.0
info:
  title: OpenType API
  version: 0.1.0
  license:
    name: Apache-2.0
  description: >-
    The OpenType HTTP API: decision runs on Neon 1.1, API keys, usage, quota and
    billing. Every `/v1` route takes `Authorization: Bearer <credential>`, where
    the credential is an API key (`otsk_` followed by 64 hex characters) or a
    console session token. Amounts are integers in micro-USD (1,000,000 = 1 US
    dollar). Errors share one envelope, `{"error": {"code", "message",
    "request_id"}}`. Stripe is named only where it hosts checkout, the billing
    portal and receipts.
servers:
  - url: https://api.opentype.dev
    description: Production
  - url: https://api.opentype.dev
    description: Production
security:
  - bearer: []
  - bearer: []
tags:
  - name: runs
    description: Create, list, retrieve and stream runs.
  - name: keys
    description: Create, list, rotate and revoke API keys.
  - name: usage
    description: Usage rollups, the daily series, the ledger and quota.
  - name: billing
    description: Credit balance, checkout, the billing portal and auto-recharge.
  - name: health
    description: Public liveness and readiness checks.
  - name: router
    description: >-
      Model Router: classify a task with Neon 1.1 and pick a model from the
      benchmark catalog.
paths:
  /v1/billing/auto-recharge:
    put:
      tags:
        - billing
      summary: Set auto-recharge
      description: >-
        Stores auto-recharge settings and returns the updated billing state.
        Requires `billing_write`.


        When enabled, and a card is saved, the server checks after each run
        admission and after each `402`: if the available balance is below
        `threshold_micros`, it charges `amount_micros` to the saved card, at
        most once per organization per clock hour. The credit lands when the
        payment succeeds. See [Auto-recharge](/guides/auto-recharge).
      operationId: set_auto_recharge
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AutoRechargeRequest'
        required: true
      responses:
        '200':
          description: The updated billing state.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BillingResponse'
        '400':
          description: >-
            `invalid_amount`: `amount_micros` outside the checkout bounds,
            `threshold_micros` above 1,000,000,000, or either number missing
            while `enabled` is `true`. Malformed JSON gets a plain-text `400`.
        '401':
          description: >-
            `missing_credentials` (no bearer credential) or `invalid_credential`
            (malformed, unknown or revoked).
        '403':
          description: >-
            `scope_denied`: the credential lacks `billing_write`. A session
            without an organization gets `no_active_organization`.
        '413':
          description: The body is over 1 MiB. Plain-text body.
        '503':
          description: >-
            `billing_not_configured`, `database_not_configured` or
            `database_unavailable`. Also `auth_not_configured` or
            `trust_keys_unavailable` when credentials cannot be verified.
      security:
        - bearer: []
        - bearer: []
components:
  schemas:
    AutoRechargeRequest:
      type: object
      required:
        - enabled
      properties:
        enabled:
          type: boolean
        threshold_micros:
          type:
            - integer
            - 'null'
          format: int64
          description: Required when `enabled` is `true`. At most 1,000,000,000.
          minimum: 0
        amount_micros:
          type:
            - integer
            - 'null'
          format: int64
          description: >-
            Required when `enabled` is `true`. 5,000,000 to 1,000,000,000, in
            whole cents.
          minimum: 0
      additionalProperties: false
    BillingResponse:
      type: object
      required:
        - organization_id
        - balance_micros
        - currency
        - auto_recharge
        - has_payment_method
        - transactions
      properties:
        organization_id:
          type: string
        balance_micros:
          type: integer
          format: int64
          description: >-
            Signed. Credits, minus settled spend, minus what unsettled runs
            hold.
        currency:
          $ref: '#/components/schemas/Currency'
        auto_recharge:
          $ref: '#/components/schemas/AutoRechargeSettings'
        has_payment_method:
          type: boolean
        transactions:
          type: array
          items:
            $ref: '#/components/schemas/BillingTransaction'
          description: Newest first, at most 50.
    Currency:
      type: string
      enum:
        - usd
    AutoRechargeSettings:
      type: object
      required:
        - enabled
      properties:
        enabled:
          type: boolean
        threshold_micros:
          type:
            - integer
            - 'null'
          format: int64
          minimum: 0
        amount_micros:
          type:
            - integer
            - 'null'
          format: int64
          minimum: 0
    BillingTransaction:
      type: object
      required:
        - id
        - kind
        - amount_micros
        - description
        - created_at
      properties:
        id:
          type: string
        kind:
          $ref: '#/components/schemas/BillingTransactionKind'
        amount_micros:
          type: integer
          format: int64
          description: 'Signed: positive adds credit, negative spends it.'
        description:
          type: string
        created_at:
          type: string
    BillingTransactionKind:
      type: string
      enum:
        - purchase
        - grant
        - usage
        - refund
        - adjustment
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      description: An API key (otsk_ + 64 hex) or a console session token.

````