```yaml
product: AlterLab
title: Billing API Reference
category: api
comparison_context: "AlterLab is an alternative to Firecrawl, ScrapingBee, and Bright Data."
source_url: https://alterlab.io/docs/api/generated/billing
```

# Billing API Reference

Auto-generated API reference for billing endpoints, built from the OpenAPI spec.

## GET /api/v1/billing/audit-log

Get billing audit log
Get a paginated audit trail of billing actions (deposits, refunds, etc.).

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `limit` | query | `integer` | no |  |
| `offset` | query | `integer` | no |  |

## DELETE /api/v1/billing/auto-recharge

Disable auto-recharge
Disable auto-recharge and clear the saved payment method configuration.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `X-Organization-Id` | header | `string` | no |  |

## GET /api/v1/billing/auto-recharge

Get auto-recharge settings
Get your current auto-recharge configuration: threshold, recharge amount, and payment method.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `X-Organization-Id` | header | `string` | no |  |

## PUT /api/v1/billing/auto-recharge

Update auto-recharge settings
Configure automatic balance top-ups. When your balance drops below the threshold, the specified amount is charged to your default payment method.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `X-Organization-Id` | header | `string` | no |  |
| `enabled` | body | `boolean` | no | Enable auto-recharge |
| `threshold_microcents` | body | `integer` | no | Recharge when balance drops below this (microcents). 1,000,000 = $1.00 |
| `recharge_amount_cents` | body | `integer` | no | Amount to charge in cents ($25-$2000) |
| `stripe_payment_method_id` | body | `string` | no |  |
| `consent_text` | body | `string` | no |  |
| `consent_source` | body | `"deposit_flow" \| "success_page" \| "settings"` | no |  |
| `terms_version` | body | `string` | no |  |

## GET /api/v1/billing/auto-recharge/history

Get auto-recharge history
Get paginated history of auto-recharge attempts for your account.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `page` | query | `integer` | no | Page number |
| `per_page` | query | `integer` | no | Results per page |
| `X-Organization-Id` | header | `string` | no |  |

## POST /api/v1/billing/auto-recharge/test

Test auto-recharge
Perform a dry-run auto-recharge to verify payment method and configuration are valid without actually charging.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `X-Organization-Id` | header | `string` | no |  |

## GET /api/v1/billing/b2b/summary

Get B2B billing summary
Returns usage and cost summary for the current period for enterprise B2B tenants. Requires an active tenant billing configuration (enterprise contract). Returns 404 for self-serve organizations.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `period_start` | query | `string` | no | Period start (inclusive, UTC). Defaults to first day of current calendar month. |
| `period_end` | query | `string` | no | Period end (inclusive, UTC). Defaults to last moment of current calendar month. |
| `X-Organization-Id` | header | `string` | no |  |

## GET /api/v1/billing/balance

Get current balance
Get your organization's current credit balance in microcents (1,000,000 microcents = $1.00). Includes formatted display values.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `X-Organization-Id` | header | `string` | no |  |

## POST /api/v1/billing/change-plan

Change Plan
Change subscription plan. DEPRECATED: AlterLab uses balance-based billing. There are no subscription plans to change. Scraping tier is determined automatically by each request. Use POST /billing/deposit to add funds to your balance.

Authentication: `Authorization: Bearer <session token>`

## POST /api/v1/billing/checkout

Create a checkout session (retired)
Retired. Core funding goes through POST /billing/deposit, which enforces the deposit cap, promo and affiliate rules. This endpoint always returns 410 Gone.

Authentication: `Authorization: Bearer <session token>`

## GET /api/v1/billing/cost-projection

Get cost projection
Get projected costs for the current billing period based on usage trends.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `X-Organization-Id` | header | `string` | no |  |

## GET /api/v1/billing/credit-transactions

Get credit transactions
Get credit ledger transactions (debits, refunds, grants) for your account. Supports filtering by reference type (e.g. 'crawl', 'scrape').

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `limit` | query | `integer` | no |  |
| `offset` | query | `integer` | no |  |
| `reference_type` | query | `string` | no | Filter by reference_type (e.g. 'crawl') |
| `X-Organization-Id` | header | `string` | no |  |

## POST /api/v1/billing/deposit

Create a deposit
Create a deposit checkout session for pay-as-you-go billing. Returns a Stripe payment URL. Credits are added to your balance after successful payment.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `X-Deposit-Intent-Id` | header | `string` | no |  |
| `X-Correlation-ID` | header | `string` | no |  |
| `X-Organization-Id` | header | `string` | no |  |
| `amount_cents` | body | `integer` | yes | Amount to deposit in cents ($10-$2000) |
| `success_url` | body | `string` | no |  |
| `cancel_url` | body | `string` | no |  |
| `promo_code` | body | `string` | no |  |
| `auto_recharge_enabled` | body | `boolean` | no | If true, enable auto-recharge after successful deposit |
| `auto_recharge_threshold_microcents` | body | `integer` | no |  |
| `auto_recharge_amount_cents` | body | `integer` | no |  |

## GET /api/v1/billing/deposit-bonus

Bonus granted for a deposit
Bonus ledger row for a Checkout session id or quick-deposit PaymentIntent id.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `reference_id` | query | `string` | yes |  |
| `X-Organization-Id` | header | `string` | no |  |

## GET /api/v1/billing/deposit-quote

Quote the credits a deposit would earn
Bonus and resulting tier for a deposit, from the rule the webhook grants with (#37694).

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `cents` | query | `integer` | yes | Deposit amount in cents |
| `X-Organization-Id` | header | `string` | no |  |

## GET /api/v1/billing/deposits

Get deposit history
Get completed deposit history for the authenticated user, most recent first. Returns checkout sessions (mode=payment, status=complete) joined with the corresponding credit_ledger grant for balance context and payment method info.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `limit` | query | `integer` | no |  |
| `offset` | query | `integer` | no |  |
| `X-Organization-Id` | header | `string` | no |  |

## GET /api/v1/billing/invoice/{invoice_id}

Download invoice PDF (first-party, no login required)
Public endpoint — no session required. Validates a signed, expiring token embedded in the purchase confirmation email. Fetches the Stripe-sourced PDF server-side and streams it back as ``application/pdf`` from alterlab.io, avoiding client-side JS requirements and Firefox COOP failures.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `invoice_id` | path | `string` | yes |  |
| `uid` | query | `string` | yes |  |
| `exp` | query | `integer` | yes |  |
| `token` | query | `string` | yes |  |

## GET /api/v1/billing/invoices

Get invoice history
Get your organization's invoice history, most recent first.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `limit` | query | `integer` | no |  |
| `X-Organization-Id` | header | `string` | no |  |

## GET /api/v1/billing/key-limits

Get the calling key's budget
Budget limit, spend and reset time of the credential making the request. The credential is resolved from the request itself (API key, or OAuth grant), never from a caller-supplied id, so it can only describe the caller's own limit. Limits are ``null`` when unset; a dashboard session has no key limit.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `X-Organization-Id` | header | `string` | no |  |

## GET /api/v1/billing/low-balance-threshold

Get credits.low webhook threshold
Balance at or below which the credits.low webhook fires.

Authentication: `Authorization: Bearer <session token>`

## PUT /api/v1/billing/low-balance-threshold

Update credits.low webhook threshold
Set the balance (microcents) at or below which credits.low fires; null resets to $1.00.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `threshold_microcents` | body | `integer` | no |  |

## GET /api/v1/billing/payment-methods

List payment methods
Get your organization's saved payment methods (cards, bank accounts).

Authentication: `X-API-Key: <your key>`

## POST /api/v1/billing/payment-methods

Add a payment method
Attach a payment method (from a completed SetupIntent) to your Stripe customer. Optionally set it as default.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `payment_method_id` | body | `string` | yes | Payment Method Id |

## DELETE /api/v1/billing/payment-methods/{payment_method_id}

Remove a payment method
Detach and remove a saved payment method from your account.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `payment_method_id` | path | `string` | yes |  |

## POST /api/v1/billing/payment-methods/{payment_method_id}/default

Set default payment method
Set a payment method as the default for future charges and auto-recharge.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `payment_method_id` | path | `string` | yes |  |

## POST /api/v1/billing/portal

Create a Stripe portal session
Create a Stripe Customer Portal session where users can manage payment methods, view invoices, and update billing details.

Authentication: `Authorization: Bearer <session token>`

## POST /api/v1/billing/promo/validate

Validate Promo Code
Validate a promo code for the current user. Rate-limited to 5 failed attempts per 10 minutes per user to prevent brute-force enumeration of valid codes. Only failed validations count against the limit — successful validations do not consume attempts.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `code` | body | `string` | yes | Code |

## POST /api/v1/billing/quick-deposit

One-click deposit with saved payment method
Charge a saved payment method directly via Stripe PaymentIntent (off_session=True, confirm=True). Eliminates the Stripe Checkout redirect for returning customers who already have a card on file. Credits are granted synchronously on success (non-3DS). Returns client_secret for 3DS-required cards.

Authentication: `X-API-Key: <your key>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `amount_cents` | body | `integer` | yes | Amount to deposit in cents ($10–$2000) |
| `payment_method_id` | body | `string` | yes | Internal payment_methods.id UUID — ownership verified server-side |

## GET /api/v1/billing/receipts/{receipt_id}

Resolve and redirect to a receipt (resolve-on-click)
Resolves the Stripe-hosted receipt URL for a deposit or auto-recharge row that doesn't yet have one cached, persists it, and redirects. A row that already has a cached URL redirects immediately with no Stripe API call. Scoped to the organization's billing principal rows.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `receipt_id` | path | `string` | yes |  |
| `X-Organization-Id` | header | `string` | no |  |

## GET /api/v1/billing/recent-activity

Get recent billing activity
Get recent billing activity for dashboard display.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `limit` | query | `integer` | no |  |
| `offset` | query | `integer` | no |  |

## POST /api/v1/billing/setup-intent

Create a setup intent
Create a Stripe SetupIntent for saving a new payment method without an immediate charge. Returns a client secret for the frontend Stripe Elements flow.

Authentication: `X-API-Key: <your key>`

## GET /api/v1/billing/subscription

Get Subscription
Get subscription details. DEPRECATED: AlterLab uses balance-based billing. There are no subscriptions. Use GET /billing/balance and GET /billing/usage/realtime instead.

Authentication: `Authorization: Bearer <session token>`

## POST /api/v1/billing/topup-link/open

Record that a signed top-up link from an insufficient-balance error was opened
Verifies the `tl` token carried by the `topup_url` in 402 errors (signature, expiry and owner) and emits `topup_link_opened`. Never charges: the quick top-up banner still needs an explicit confirm.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `token` | body | `string` | yes | Token |

## GET /api/v1/billing/usage-alerts

Get usage alert settings
Get your current usage alert thresholds and notification preferences.

Authentication: `Authorization: Bearer <session token>`

## PUT /api/v1/billing/usage-alerts

Update usage alert settings
Update usage alert thresholds and notification preferences.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `enabled` | body | `boolean` | no | Enabled |
| `threshold_50_enabled` | body | `boolean` | no | Threshold 50 Enabled |
| `threshold_75_enabled` | body | `boolean` | no | Threshold 75 Enabled |
| `threshold_90_enabled` | body | `boolean` | no | Threshold 90 Enabled |
| `threshold_100_enabled` | body | `boolean` | no | Threshold 100 Enabled |
| `email_enabled` | body | `boolean` | no | Email Enabled |
| `webhook_url` | body | `string` | no |  |

## GET /api/v1/billing/usage-breakdown

Get usage breakdown
Get usage breakdown by request type for the current billing period.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `X-Organization-Id` | header | `string` | no |  |

## GET /api/v1/billing/usage-chart

Get usage chart data
Get daily usage data for charts over a configurable time window (1-365 days).

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `days` | query | `integer` | no |  |
| `X-Organization-Id` | header | `string` | no |  |

## GET /api/v1/billing/usage-realtime

Get real-time usage
Get real-time usage statistics for the current billing period. Includes request counts, credit consumption, and cost projections.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `X-Organization-Id` | header | `string` | no |  |

## POST /api/v1/billing/verify/confirm

Verify Code
Verify a 2FA code.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `challenge_id` | body | `string` | yes | Challenge Id |
| `code` | body | `string` | yes | Code |

## POST /api/v1/billing/verify/initiate

Initiate Verification
Initiate a 2FA verification challenge for a protected billing action. Returns a challenge ID and sends a verification code via the specified method.

Authentication: `Authorization: Bearer <session token>`

| Parameter | In | Type | Required | Description |
|-----------|----|------|----------|-------------|
| `action` | body | `string` | yes | Action |
| `method` | body | `string` | no | Method |
