How credit works
- Every amount is an integer in micro-USD. 1,000,000 micros is 1 US dollar and 10,000 micros is 1 cent.
balance_microsand a transaction’samount_microsare signed; every other amount is unsigned. - Your balance is credited minus spent minus held. Purchases and grants add to it, usage takes from it, and every run in flight holds its spend ceiling, at most 20,000 micros ($0.02), until it settles.
- A run needs 20,000 micros of available credit to start. It holds that whole ceiling while it runs, then settles at its real cost, which is usually far lower. If the balance after the hold would go below zero, the run is refused with
402 insufficient_credits. - New accounts start with $5 of credit (5,000,000 micros), granted once the email address is verified. There is one grant per email address. See Create an account.
Routes and who can call them
Which roles hold the two billing scopes:
A key can only hold scopes its creator holds, so only an owner, admin or billing user can create a key with
billing_write. A key that only sends runs needs neither billing scope. See Scopes and roles.
Read your balance
Each transaction has
id, kind, amount_micros (signed: credit is positive, usage is negative), description and created_at.
Transaction ids are
txn_ plus 32 hex characters, except daily usage rows. Timestamps are UTC, in exactly YYYY-MM-DDTHH:MM:SSZ form. For spend older than the last 50 rows, read usage reporting instead.
Buy credit
POST /v1/billing/checkout takes the amount to buy and returns a Stripe-hosted checkout page. The credit is not added by this call: it arrives after the payment succeeds.
1
Pay on the checkout page
Open
checkout_url in a browser. The line item reads OpenType credits. Paying also saves the card, which is what auto-recharge charges later.2
Return to the console
Whether you pay or cancel, the checkout page sends you back to the console’s Billing page.
3
Wait for the credit
The credit lands once the payment succeeds, as a
purchase transaction with the description Credit purchase. Poll GET /v1/billing until it appears.Wait for a purchase to land
Record the newest transaction id before you open checkout, then poll until a newpurchase row appears.
Cards, receipts and invoices
POST /v1/billing/portal takes no body and returns {"portal_url": string}, a Stripe billing portal where you add or change the saved card and download receipts and invoices. Leaving the portal returns you to the console’s Billing page. Add a card here if has_payment_method is false and you want auto-recharge without buying credit first.
What a run is charged
- A completed run is charged its settled
cost_micros: input and output tokens are each priced and rounded up to a whole micro separately, then summed. - A replay of an
Idempotency-Keyis never charged again. See Idempotency. - A refusal before any model call is free: every
400,402,409,413and429, and every503or504raised before a model answered. The run’s hold is released. - A run that fails after the model answered is charged for what the model consumed, for example
503 provider_malformed_response. - The hold is not a charge. The 20,000 micros held while a run is in flight return to the balance when it settles; only the settled cost is spent.
usage transaction records those charges for one UTC day. GET /v1/usage/ledger lists every charged model call, one row each. See Usage reporting.
Errors
Billing errors use the envelope{"error":{"code","message","request_id"}}. The scope is checked before billing availability, so a key without the scope gets 403 even where billing is off.
A malformed JSON body, a missing
Content-Type, or an unknown field such as {"amount": 25} is refused before these checks with a plain-text 400, 415 or 422 that has no request_id in the body. Fall back to the HTTP status and the x-request-id response header. See Error handling.
Related
- Auto-recharge - top up automatically when the balance runs low.
- Handling insufficient credits - what to do when a run gets
402. - Billing in the console - buy credit and change auto-recharge without code.
- Models and pricing - the Neon 1.1 price and how a cost is rounded.
- Usage reporting - spend per day, per run and per model call.