> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.trygateway.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.trygateway.ai/_mcp/server.

# Usage & Billing

## Credit-based billing

Gateway AI uses a prepaid credit model. You purchase credits, and each API request deducts from your balance based on token usage and model pricing.

### How costs are calculated

For each request, the gateway tracks:

* **Prompt tokens** — tokens in your input/messages
* **Completion tokens** — tokens in the model's response
* **Cached tokens** — tokens served from provider cache (reduced cost)

The cost is calculated using the model's per-token pricing, which has two components:

* **Your cost** — the discounted rate you pay through Gateway AI
* **Market rate** — what you would pay going directly to the provider

The difference is your savings.

### Viewing your savings

Your dashboard overview shows:

* **Total Spend** — what you actually paid
* **Market Rate** — what you would have paid at standard provider rates
* **You Saved** — the dollar amount and percentage below market rate

These metrics are available for any time period and can be broken down by key, provider, model, or date.

## Purchasing credits

Go to **Settings > Billing** in your dashboard.

Available credit packages are displayed with their price and credit amount. Click a package to purchase:

* **Production mode** — redirects to Stripe checkout for secure payment
* **Development mode** — credits are granted instantly (no payment required)

## Usage tracking

The **Usage** page in your dashboard provides:

* **Summary metrics** — total requests, tokens, cost, and savings
* **Breakdown** — group by date, key, provider, or model
* **Charts** — spend over time, cost by model, cost by provider

### Per-key usage

Each key tracks its own spend. View per-key usage in the keys table or via the management API at `GET /v1/keys/{id}/usage`.

## Transaction history

Every credit change is recorded in an append-only ledger:

| Type          | Description                       |
| ------------- | --------------------------------- |
| `purchase`    | Credits added via payment         |
| `usage_debit` | Credits deducted for API usage    |
| `adjustment`  | Manual credit adjustment by admin |

View your transaction history in **Settings > Billing**.

## Audit trail

Every API request is logged with:

* Timestamp, provider, model
* Token counts (prompt, completion, cached)
* Cost (your rate and provider rate)
* Latency, HTTP status
* Key name, client IP
* Streaming flag, user agent

View the full audit trail in the **Audit** page. Export as CSV or JSON for compliance reporting.

No prompt or completion content is stored — only metadata.