Skip to main content

Billing page

The Billing page is where you charge a team, an organization or a customer for what it used on the gateway. A billing account sets the markup, tax and payment terms for one scope, and each invoice is built from that scope's daily spend in a period, issued by hand or through Stripe, and settled or voided from here. It is for platform teams that charge departments back and for companies that resell gateway access to their own customers. Open it at /ui/billing. In the left nav it sits in the Settings group, inside the Settings item, as Billing. The nav item is shown to the Admin and Admin Viewer roles (proxyAdminTierRoles, which covers proxy_admin and proxy_admin_viewer).

A real-world scenario​

A platform team charges each department 10 percent on top of provider cost. On the first working day of October the admin opens the Billing page, clicks Generate for all accounts for September, reads the list of drafts, opens each one to check its line items against the Usage page, and issues them. Stripe emails each issued invoice to the departments billed through Stripe and collects the payment. One department pays by bank transfer, so when the money arrives the admin marks its invoice paid. When Stripe reports that a department's payment failed after the grace period, the account turns Past due, or, because its account has Auto-suspend on, Suspended, and its requests are refused until an admin reinstates it. Paying alone does not lift the suspension.

Create an account and issue its first invoice​

  1. Open Settings, then Billing, and click Create Account. Choose Team under Bills a, pick the team, enter a Display name and a Billing email, set Markup (%) to 10, pick Stripe or Manual under Payment provider, turn on Auto-suspend if a failed Stripe payment should block the team after the grace period, and click Create Account.

    Expected result: a toast confirms the account, and the row shows Active, the provider and 10% / 0% under Markup / Tax. The same step from a script, as a proxy admin:

    curl -X POST http://localhost:4000/billing/account/new \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"scope_type": "team", "scope_id": "team-nlp", "display_name": "NLP team", "billing_email": "nlp-finance@example.com", "markup_percent": 10, "payment_provider": "stripe", "auto_suspend": true}'

    Expected result: the account with its account_id, status: "active" and grace_period_days: 7.

  2. Open the Invoices tab and click Generate invoice. Pick the account, leave Period start on the first day of last month and Period end (first day not billed) on the first day of this month, read the Preview, and click Generate draft.

    Expected result: a toast reading Draft invoice with its number, and a Draft row in the list. From a script, POST /billing/invoice/generate with the account_id, period_start and period_end returns the same draft.

  3. Click the row, check the line items, then open the row menu and click Issue and confirm.

    Expected result: the badge turns Open, Issued and Due are filled in, and for a Stripe account Open in Stripe appears in the menu. From a script, POST /billing/invoice/issue with the invoice_id returns the invoice with status: "open".

  4. When a manual payment arrives, open the row menu and click Mark paid. A Stripe payment marks the invoice Paid on its own through the webhook. Download CSV saves the line items for the books.

The whole page needs the license feature billing (shown as "Billing and invoicing"). Without it the page shows "Billing needs a Spanway Enterprise license", names the missing feature and links to Get a trial license. The proxy enforces the same feature on every /billing route. If the Admin UI cannot read the license at all, it fails closed and shows "Billing is hidden until the license can be checked" with a hint to check that GET /health/license answers.

The page opens with a short description. When you cannot change anything it adds "You can view accounts and invoices, but only a proxy admin can change them." It has two tabs, Accounts (the default) and Invoices, and the selected tab is kept in the URL.

Accounts tab​

The Accounts tab lists billing accounts, newest first, 25 per page. Filters and paging are applied by the proxy and kept in the URL.

ControlTypeWhat it does
All scopesFilterNarrows the list to Team, Organization or Customer accounts.
All statusesFilterNarrows the list to Active, Past due or Suspended accounts.
Clear allButtonRemoves every active filter. Each filter also shows as a chip you can remove on its own.
RefreshIcon buttonLoads the list again.
ColumnsMenuShows or hides table columns.
Create AccountButtonOpens the Create Billing Account dialog. Shown only to proxy admins.
ColumnMeaning
AccountThe display name, with the billing email (or the account ID when there is no email) under it.
ScopeA badge with the scope type and the ID of the team, organization or customer it bills.
StatusA badge, Active (green), Past due (amber) or Suspended (red).
ProviderManual or Stripe. Hover to see the Stripe customer ID when there is one.
Markup / TaxThe markup and tax percentages.
Grace daysHow many days after issue an invoice falls due.
Auto-suspendOn or Off.
CreatedWhen the account was created.
ActionsA menu with Edit, Suspend (or Reinstate for a suspended account) and Delete. Shown only to proxy admins.

Create Billing Account and Edit Account dialogs​

Create Account opens the dialog titled Create Billing Account, which says there is one account per team, organization or customer and that invoices are built from its daily spend. Edit opens the dialog titled Edit Account: followed by the account name, which says pricing, provider and suspension terms can change but the scope the account bills cannot.

FieldTypeWhat it does
Bills aDropdownTeam, Organization or Customer. The default is Team. Changing it clears the next field. Locked when editing.
Team, Organization or CustomerDropdown or text inputThe ID to bill. You pick from the teams, organizations or customers the UI has loaded, each shown with its alias and ID. Click Enter an ID manually to type it instead, and Pick from the list instead to go back. When none is loaded the field is a text input with the hint "No team is loaded, so enter its ID." (or organization or customer). Required, with the error "Choose or enter the ID to bill". Read-only when editing.
Display nameText inputPlaceholder "Shown on invoices". Required, with the error "Enter a display name". Must stay under 200 characters.
Billing emailText inputPlaceholder "Optional". Help: "Stripe emails each invoice here. On Manual it is only recorded, so share the invoice yourself". The UI does not check the address format.
CurrencyText inputHelp: "Three-letter code printed on invoices and charged by Stripe. Defaults to USD". Upper-cased on save. A wrong value shows "Use a three-letter code, like USD".
Markup (%)Number inputHelp: "Added on top of the model cost, for example 10 to recover overhead. 0 bills cost only". The default is 0. Must be 0 or more, with the error "Enter a markup of 0% or more".
Tax (%)Number inputHelp: "Applied after markup as its own line. 0, the default, adds no tax". Must be 0 or more, with the error "Enter a tax rate of 0% or more".
Payment providerDropdownHelp: "Manual: you collect and mark invoices paid. Stripe: needs STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET". Manual is the default. With Stripe, issuing sends the invoice through the gateway's Stripe account, which emails and charges the customer.
Grace period (days)Number inputHelp: "Days an issued invoice has before it is due and before auto-suspend may act. Defaults to 7". Must be a whole number, with the error "Enter a whole number of days".
Auto-suspendSwitchHelp: "On: when Stripe reports a failed or uncollectible payment after the grace period, every request from this scope is refused until an admin reinstates it. Off, the default: the account only shows Past due". It never acts on a Manual account. Turn it on only when cutting off traffic is acceptable for this customer.

Cancel closes the dialog without saving. Create Account (or Save Account when editing) saves and reads Creating... or Saving... while it runs. An edit sends only the fields you changed, and saving with no change just closes the dialog. A toast confirms the account was created or updated, or shows "Could not create the account" or "Could not update the account" with the proxy's reason.

Suspend, reinstate and delete confirmations​

Each row action asks for confirmation in a dialog that repeats the account name, scope and status.

ActionWhat happens
Suspend"Suspend this account?" Requests from the scope are refused until the account is reinstated. Open invoices stay open. A scope already blocked for another reason, for example after a leaked key, stays blocked for that reason.
Reinstate"Reinstate this account?" The account becomes active, whatever invoices remain open, and the block billing placed is lifted. A block someone else placed, such as a security block, stays until it is lifted where it was set.
Delete"Delete this account?" The account is removed and settled invoices are kept for the books. An account with a draft or open invoice cannot be deleted, so void or settle those first. There is no way to restore a deleted account from the UI.

Cancel closes the dialog. The confirm button reads Suspending..., Reinstating... or Deleting... while the request runs, and a refusal is shown in the dialog.

Invoices tab​

The Invoices tab lists invoices, newest first, 25 per page. Click a row or its invoice number to open the invoice details.

ControlTypeWhat it does
All accountsFilterNarrows the list to one account. The choices are the first 100 accounts.
All statusesFilterNarrows the list to Draft, Open, Paid, Void or Uncollectible invoices.
RefreshIcon buttonLoads the list again.
ColumnsMenuShows or hides table columns.
Generate for all accountsButtonOpens the Generate invoices for all accounts dialog. Shown only to proxy admins.
Generate invoiceButtonOpens the Generate invoice dialog, with the account preselected when the account filter is set. Shown only to proxy admins.
ColumnMeaning
InvoiceThe invoice number. Click it to open the details.
AccountThe account name, or its ID when the account is not among the first 100.
PeriodThe billed period, from its start date to its end date.
StatusA badge (see the table below).
TotalThe invoice total in its currency.
Issued, Due, PaidThe dates, or - when not reached yet.
ActionsA menu, described below.
BadgeMeaning
Draft (grey)Built but not sent.
Open (blue)Issued and waiting for payment.
Paid (green)Settled.
Void (grey)Cancelled. Its period can be invoiced again.
Uncollectible (red)Marked as not collectable. It can still be marked paid or voided.

The row menu always has View line items and Download CSV, which saves the invoice as <invoice number>.csv. It has Open in Stripe when Stripe hosts the invoice. Proxy admins also see the actions the invoice's status allows. The menu offers only actions the proxy would accept.

ActionOffered forWhat happens
IssueDraft"Issue this invoice?" The draft becomes an open invoice due after the account's grace period. For a Stripe account the gateway also creates the invoice in Stripe and asks Stripe to send it, so Stripe emails it to the billing email. A manual account's invoice is not emailed.
Mark paidOpen, Uncollectible"Mark this invoice paid?" Records a payment taken outside Stripe. A past-due account returns to active once none of its other open invoices is overdue. A suspended account stays suspended until you click Reinstate.
VoidDraft, Open, Uncollectible"Void this invoice?" Cancels the unpaid invoice, in Stripe too when it was issued there. A voided invoice cannot be reopened, but its period can be invoiced again.

Each confirmation repeats the invoice number, account, period and total, and reads Issuing..., Marking paid... or Voiding... while it runs.

Generate invoice dialog​

The dialog titled Generate invoice builds a draft from the account's daily spend in a half-open period. Nothing is sent until you issue it.

FieldTypeWhat it does
AccountDropdownThe account to bill, each shown with its scope type and ID. The placeholder is "Select an account", or "No billing accounts yet" when there are none.
Period startDateThe first day billed. The default is the first day of last month.
Period end (first day not billed)DateThe day after the last day billed. The default is the first day of this month.

Both dates are required ("Enter both dates") and the end must come after the start ("The period end must be after its start"). Once an account and a valid period are chosen, a Preview section loads the usage the invoice would bill, with the same line items table as the invoice details. "No usage in this period. The invoice would be empty." appears when there is none, and Could not preview usage appears when the preview fails.

Generate draft stays disabled until the preview has loaded, and reads Generating... while it runs. A toast confirms "Draft invoice" with its number. Could not generate the invoice shows the proxy's reason, for example when an invoice already covers the period. Cancel closes the dialog.

Generate invoices for all accounts dialog​

This dialog does what the monthly job does, for any period. The monthly job is off by default. To turn it on, open Router Settings, then General, and switch on billing_auto_generate_invoices. It then drafts last month's invoices at 00:30 UTC on the first of each month, never issues them, and needs the billing license feature, see Draft invoices every month on their own. It builds a draft for every active account with usage in the period that is not already invoiced. It has the same Period start and Period end (first day not billed) fields and defaults as the single invoice dialog. Generate drafts reads Generating... while it runs and is disabled while the period is invalid.

When it finishes, the title changes to Drafts generated. The dialog lists how many drafts were built for the period and their invoice numbers, and how many accounts were skipped for having no usage or an invoice already covering the period. It reminds you to review each draft on the Invoices tab, then issue it. Done closes the dialog.

Invoice details panel​

The side panel shows the invoice number and status badge, then the account and period. A summary lists Account, Period, Provider, Created, Issued, Due, Paid and, when there is one, the Stripe invoice ID.

The line items table has one row per model group and provider, so a model group served by two providers has two rows. Usage logged without a model group is listed under its model name, or unknown.

ColumnMeaning
Model groupThe model group, with the provider under it.
RequestsHow many requests were made, with the failed count under it when some failed.
TokensInput tokens, with output tokens under them.
Provider spendWhat the requests cost at provider prices, shown to six decimal places so tiny usage is still visible.
AmountWhat the invoice charges for the row, to the cent.

Below the table are Subtotal, Markup, Tax and Total. The panel footer has Open in Stripe when Stripe hosts the invoice and Download CSV, which reads Preparing... while the file is built.

Errors​

What you seeMeaningFix
Billing needs a Spanway Enterprise license.The license does not include billing.Add a license with the feature. The proxy answers 403 on every /billing route until then.
Billing is hidden until the license can be checked.The Admin UI could not read GET /health/license.Check that the proxy is reachable and answers that route.
"No billing accounts yet." or "No invoices yet. Generate one from an account's usage."Nothing exists yet.Create an account, then generate an invoice.
"No usage was recorded in this period." or "No usage in this period. The invoice would be empty."The scope had no spend in the period.Pick another period, or check cost tracking.
"Could not create the account" with team team-nlp not found.The scope does not exist.Create the team, organization or customer first.
"Could not create the account" with already has billing account.The scope already has an account.Edit the existing account instead.
"Could not generate the invoice" with invoice ... already covers ....A non-void invoice overlaps the period.Void it, or pick another period.
"Could not issue the invoice", "Could not suspend the account" or a similar toast with the proxy's reason.The action is not allowed in the current status, for example issuing an invoice that is not a draft, or Stripe refused the call (stripe: ...).Read the reason, fix the status or the Stripe key, and retry.
"Could not download the CSV".GET /billing/invoice/export failed.Retry, then check the gateway log.
"No invoices were generated".Generate for all accounts found no active account with usage that is not already invoiced.Nothing to do, or check the period.
Generate draft stays disabled.An account, a valid period or the usage preview is missing.Pick an account and a period whose end is after its start, and wait for the preview. Dialogs cannot be closed while a request is still running.

Differences by role and license​

Only the Admin and Admin Viewer roles see the nav item, and the proxy lets only admins read billing data. A proxy admin (proxy_admin) sees Create Account, the account row actions, Generate invoice, Generate for all accounts and the invoice status actions. Other roles that can open the page can browse accounts and invoices, open invoice details, download the CSV and open the Stripe invoice. The proxy enforces the split, so every change needs a proxy admin or a custom role that grants the write. An Admin Viewer (proxy_admin_viewer) has the session role Admin Viewer, so the change buttons are hidden for them.

The page is locked without the billing license feature, and the data loads only when the session belongs to a licensed gateway.

Logs​

This page writes no log lines of its own. The billing routes and the monthly invoice job log what the Logs section of the billing guide lists.

  • Billing and invoicing for how accounts, invoices, Stripe and auto-suspend work on the proxy, with the routes behind every button.
  • Cost tracking for how the daily spend that invoices are built from is recorded.
  • Customers and end users for the customers an account can bill.
  • Usage page for checking a draft's line items against the usage charts.