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

# Inference permits

> How users bound credit spending while Tulip reserves, meters, and settles inference requests.

An inference permit is a model-bound deposit of credits in `TulipInferenceEscrow`. It limits how much the Gateway can settle for a user's requests without giving the Gateway arbitrary wallet access.

## Permit fields

Each permit records:

* Owner.
* Credit token and model ID.
* Optional pinned provider offer.
* Remaining credit balance.
* Expiration time.
* Close request and closed state.

The escrow verifies that the deposited token is the canonical credit for the selected model.

## Request lifecycle

<Steps>
  <Step title="Quote">
    The Gateway tokenizes the prompt, assumes the requested maximum output, checks whether the endpoint must wake, and obtains the maximum charge from the on-chain tariff.
  </Step>

  <Step title="Reserve">
    The Gateway atomically reserves that maximum against the permit in its durable store. Concurrent requests cannot reuse the same available balance.
  </Step>

  <Step title="Serve and meter">
    The selected endpoint serves the request. The Gateway requires actual prompt and completion token usage from the upstream response.
  </Step>

  <Step title="Sign receipt">
    The Gateway releases the unused part of the reservation and signs an EIP-712 receipt containing the exact model, offer, tariff version, token usage, timestamps, and wake state.
  </Step>

  <Step title="Settle on-chain">
    Receipts are submitted to the escrow. The contract recomputes the charge, rejects replayed request IDs, debits the permit, and transfers credits to the recipients.
  </Step>
</Steps>

## Close and refund

The owner may top up an open, unexpired permit. To withdraw unused credits, the owner first requests closure. The contract enforces a 30-minute delay before `closePermit` refunds the remaining balance.

The delay gives already issued receipts time to settle. A close request can be cancelled before final closure.

## Open or pinned provider selection

* An **open permit** has a zero offer ID. The Gateway may select any eligible offer and may perform pre-output failover.
* A **pinned permit** names one offer. Settlement rejects receipts from every other offer.

<Warning>
  A permit is not an unlimited approval. Credits are transferred into escrow when the permit opens or is topped up. Only the unused escrow balance is refundable.
</Warning>
