More endpoints
Billing

Billing

Billing runs on Stripe. These endpoints create Stripe Checkout sessions for plan upgrades and Stripe Billing Portal sessions for managing existing subscriptions.

All billing endpoints require a valid API key.

Credit meter

  • Billable work debits your credit balance. Endpoints charge on a hit only: an empty result costs 0. An async batch holds one credit per URL while it runs and returns the credits of failed URLs when it ends. A crawl is charged per page as it runs.
  • Read your balance with GET /v1/credits: pools.scrape is what scrape, crawl, map, batch, search and the other page endpoints spend, and pools.enrich is what /v1/enrich/* spends. GET /v1/credits/ledger lists every grant, hold, refund and charge. GET /v1/usage counts pages against your monthly page quota; pages are not credits.
  • Responses include X-Credits-Consumed and, when available, X-Credits-Remaining.
  • On Free, a request the balance cannot cover is refused with HTTP 402 before any work runs.
  • On a paid plan, auto-reload charges your card $5 for the next block of credits when you run out, so requests keep working. Plan credits are used first; top-up credits roll over. See Auto-reload.

See GET /v1/pricing for the live catalog and units per endpoint.

Endpoints

EndpointMethodDescription
/v1/billing/checkoutPOSTStart a Stripe Checkout session to subscribe to a plan
/v1/billing/portalGETOpen the Stripe Billing Portal for an existing subscription
/v1/billing/usageGETUsage and quota (alias for GET /v1/usage)
/v1/billing/auto-reloadGETAuto-reload setting, monthly limit, this month's spend, top-up credits and recent charges
/v1/billing/auto-reloadPUTTurn auto-reload on or off, or set a monthly limit (monthly_cap_usd: a multiple of 5, 0 = off, null = no limit)

POST /v1/billing/checkout

Creates a Stripe Checkout session for a plan subscription. Returns a url that redirects the user to Stripe's hosted checkout page.

If the tenant does not yet have a Stripe customer, one is created automatically using the email stored against the tenant in the database.

Request

POST /v1/billing/checkout
Content-Type: application/json
x-api-key: YOUR_KEY

Body

FieldTypeRequiredDescription
planstringYesWhich plan to subscribe to. See the note below.
intervalstringNo"month" (default) or "year".
uiModestringNo"hosted" (default) or "embedded".
successUrlstringHosted onlyURL Stripe redirects the user to after a successful payment. Must be http(s)://.
cancelUrlstringHosted onlyURL Stripe redirects the user to if they cancel. Must be http(s)://.
returnUrlstringEmbedded onlyURL Stripe returns the user to after an embedded checkout. Must be http(s)://.

plan accepts either public names (hobby, pro, scale) or legacy ids (starter, pro, business). Prefer the public names.

Example request

curl -X POST https://api.superscraper.dev/v1/billing/checkout \
  -H "x-api-key: ss_live_xxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "plan": "pro",
    "successUrl": "https://app.superscraper.dev/billing/success",
    "cancelUrl": "https://app.superscraper.dev/billing"
  }'

Response

HTTP 200 on success.

FieldTypeDescription
urlstringHosted: Stripe Checkout session URL. Redirect the user to this URL to complete payment.
clientSecretstringEmbedded: pass to Stripe's embedded checkout on your page
sessionIdstringEmbedded: the Checkout session id
uiModestring"hosted" or "embedded"

Example response

{
  "url": "https://checkout.stripe.com/c/pay/cs_test_a1b2c3...",
  "uiMode": "hosted"
}

Errors

StatusErrorCause
400`plan` is requiredplan field missing
400`successUrl` is requiredsuccessUrl field missing
400`cancelUrl` is requiredcancelUrl field missing
400`returnUrl` is required for embedded checkoutuiMode: "embedded" without returnUrl
400successUrl/cancelUrl must be an allowed http(s) URLNon-https:// scheme (e.g. javascript:) or origin not in ALLOWED_REDIRECT_ORIGINS allowlist
400Unknown plan: <plan>plan is not a known plan name or id. The body lists the accepted values.
400Plan `<plan>` is not available for self-serve checkout.Free and Enterprise cannot be bought through checkout
400Invalid JSON bodyMalformed request body
400invalid_intervalinterval is not "month" or "year"
401API key requiredMissing x-api-key header
404Tenant not foundAuthenticated tenant does not exist in the database
409subscription_exists (code: "use_portal")The account already has a subscription. Change plan or interval in the billing portal.
500Internal server errorStripe API error or database error

GET /v1/billing/portal

Opens a Stripe Billing Portal session for the authenticated tenant. Returns a url that redirects the user to Stripe's self-service portal where they can update payment methods, view invoices, change plan, switch between monthly and yearly billing, and cancel subscriptions.

Upgrades take effect right away: you pay the prorated difference and get the matching share of the new plan's extra credits for the rest of the billing period. Downgrades take effect at the end of your billing period. The extra credits are added once the upgrade's invoice is paid: the difference between the two plans' monthly credits, times the share of the billing period that is left. From the next month you get the new plan's full monthly credits. A downgrade keeps your current plan and credits until the period ends, with no refund for the unused time.

Requires that the tenant already has a Stripe customer ID (i.e. they have previously subscribed via /v1/billing/checkout).

Request

GET /v1/billing/portal
x-api-key: YOUR_KEY

No request body.

Example request

curl https://api.superscraper.dev/v1/billing/portal \
  -H "x-api-key: ss_live_xxxxxxxxxxxxxxxxxxxx"

Response

HTTP 200 on success.

FieldTypeDescription
urlstringStripe Billing Portal session URL. Redirect the user to this URL.

Example response

{
  "url": "https://billing.stripe.com/p/session/live_abcd1234..."
}

Errors

StatusErrorCause
400No billing account found for this tenantTenant has no Stripe customer ID (it has never subscribed)
401API key requiredMissing x-api-key header
404Tenant not foundAuthenticated tenant does not exist in the database
500Internal server errorStripe API error or database error
503billing_unavailableThe billing portal is misconfigured on the server. Try again later.

Credit grants per plan

Each plan includes a monthly grant of credits per type, granted once per calendar month. These match the credits quoted on Pricing:

PlanScrape creditsEnrich credits
Free1,0001,000
Hobby5,0005,000
Pro100,000100,000
Scale500,000500,000

Credits are prepaid: each plan grants a monthly balance, and usage draws it down. Whether this period's grant landed is reported in credits.state on GET /v1/usage. On a paid plan, auto-reload adds $5 blocks when you run out; on Free, upgrade for more.


Notes

  • The Stripe Checkout session is created in subscription mode with a flat plan line item that grants the plan's monthly credit balance.
  • Open-redirect protection: successUrl and cancelUrl must use http:// or https:// schemes. If ALLOWED_REDIRECT_ORIGINS (comma-separated) is configured in the environment, both URLs must originate from an allowlisted origin.
  • Plan upgrades are processed asynchronously via the Stripe webhook (POST /webhooks/stripe). Your plan changes when Stripe reports the checkout as completed.
  • Plan changes made in the billing portal arrive the same way. Credits for an upgrade are added when Stripe reports its prorated invoice as paid, never before.