---
name: inspect-billstack-billing
description: "v2 (provider-neutral). Investigate BillStack invoices, subscriptions, customers, payments, and financial state using provider-neutral v2 reads or authenticated MCP tools, with correct pagination, currency, mode, and freshness interpretation."
---

# Inspect BillStack billing

**Generation: v2** (provider-neutral, `/api/billstack/v2/...`, `BillStackV2Client`). This skill covers v2 only. If the app calls `/api/billstack/teams/...` (legacy v1), load [legacy-billstack-integration](https://billing.w3dev.app/.well-known/agent-skills/legacy-billstack-integration/SKILL.md) instead.

Use this skill for read-only billing investigations. For changes use [manage-billstack-customers](https://billing.w3dev.app/.well-known/agent-skills/manage-billstack-customers/SKILL.md). Catalog access is public; billing records still require authorization.

Origin: `https://billing.w3dev.app`. REST uses `Authorization: Bearer <private-bs-key>` from a trusted backend. Publishable `pk_test_`/`pk_live_` keys cannot read private financials. V2 enforces IAM actions and project restrictions; scope labels on a key are ignored. A key created since 2026-12-01 is an app-runtime key and can read what this skill needs (invoices, analytics, `query:Execute`); an older "Full access (legacy)" key without IAM attachments receives an admin-equivalent fallback. Use an operator-approved principal and avoid unnecessary customer data disclosure.

Keys and environments: a `bs_test_` key reads only test data and a `bs_live_` key reads only live data. A legacy `bs_<hex>` key has no environment in its prefix and reads the environment stored for it (live for keys issued before environments, test for teams moved to test-only). Start with a test key. On v2 reads `mode` defaults to the key's environment; naming the other one returns `403 ENVIRONMENT_MISMATCH`, and a live key for a team not yet promoted to live returns `403 LIVE_ENVIRONMENT_NOT_ENABLED`. BillingQL and the mirror-backed MCP tools also read only the key's environment, so an empty result can simply mean the other environment holds the data.

## Choose the data source

- V2 `/api/billstack/v2/.../financials` reads canonical provider-neutral billing data. Retain provider, mode, accountIncarnationId, and project filters. Canonical reads are enabled per team and resource; before that they return `404 CANONICAL_READ_NOT_READY`, which is not "no data".
- While canonical reads are off for a resource, `financials` answers `404 CANONICAL_READ_NOT_READY` (not "no data"). A team with a connected Stripe account has its numbers in the synced copy of that account, which v2 reads through `T/stripe-account/{balance|payouts|payments|disputes|customers|invoices|subscriptions|products|webhook-events}` (lists and one object by Stripe id), `T/stripe-account/invoices/{id}/pdf` and the team metrics `T/metrics/overview`, `T/metrics/saas` and `T/metrics/series` (`analytics:GetAnalytics`). They are team scope: a project-bound key is refused with `403`. Their `state` says whether the copy answered (`ready`, `pending_first_sync`, `no_source`, `native_sandbox`), and `meta.freshness` how complete it is. Canonical records start in late October 2026 and can be incomplete for older teams, so do not compare them with the copy as if they were the same set.
- A project's own invoices and payments are `GET T/projects/{projectId}/invoices` (`invoice:ListInvoices`) and `GET T/projects/{projectId}/payments` (`billing:GetBilling`). Each names its `source`: `canonical` records, `stripe-account` (the synced Stripe copy, only for customers BillStack linked to this project and to no other, and only for a team-level credential; a project-bound key gets `source: "none"` with `team-access-required`), or `none` with a `reason`. `coverage` and `excludedSharedCustomers` say what may be missing, `accountSync` the Stripe sync status when it may be known, and `stats` has one line per currency. Project payments are not a BillingQL dataset. These are reads; voiding or marking an invoice uncollectible is a write covered by [manage-billstack-customers](https://billing.w3dev.app/.well-known/agent-skills/manage-billstack-customers/SKILL.md).
- BillingQL has v2 routes too: `POST T/stripe-account/query` over the team's Stripe account copy and `POST T/projects/{projectId}/query` over the project's canonical records (a smaller catalog; `GET` lists the datasets). The v1 BillingQL routes and the MCP tools whose description starts with `Legacy:` read the legacy Stripe mirror and project billing records; they are covered by [legacy-billstack-integration](https://billing.w3dev.app/.well-known/agent-skills/legacy-billstack-integration/SKILL.md) and do not automatically represent all canonical v2 providers.
- Never interpret a complete response from one surface as proof that another surface is complete or up to date. No fallback to live provider data is implied.

## V2 financial reads

Prefix `T = /api/billstack/v2/teams/{teamId}`:

```text
GET T/financials/overview?projectId={projectId}
GET T/financials/invoices?projectId={projectId}&limit=50
GET T/financials/invoices/{externalId}?projectId={projectId}&provider=stripe&accountIncarnationId={incarnationId}
```

Resources are balances, payments, payouts-settlements, disputes, customers, invoices, subscriptions. Available filters include provider, accountIncarnationId, mode, currency, status, projectId, from, to, cursor, limit. `mode` is optional and defaults to the key's environment (invalid values return 400 `INVALID_FILTER`). Include projectId for project-restricted keys, including detail requests; they are refused without it. URL-encode IDs and query values. Financial permissions depend on the selected resource: `customer:ListCustomers` (customers), `invoice:ListInvoices` (invoices), `subscription:ListSubscriptions` (subscriptions), and `billing:GetBilling` (overview, balances, payments, payouts-settlements, disputes). A key that can create checkout need not be able to read team financials.

Success uses `{ data, meta }`. Lists have `data.items` and `data.nextCursor`; detail has `data.item` (404 `FINANCIAL_ITEM_NOT_FOUND`, or 409 `FINANCIAL_ITEM_AMBIGUOUS` when the ID matches several accounts: add provider and accountIncarnationId). Overview has `balances` (per provider account and currency: availableMinor, pendingMinor) plus paymentCount, subscriptionCount, and disputeCount. A bad cursor returns 400 `INVALID_CURSOR`. Use returned nextCursor until null, keeping filters fixed. Do not stop just because a page is short, reuse cursors across different filters, or silently turn an error into an empty list.

A server-only fetch example for one invoice page:

```ts
const url = new URL(`/api/billstack/v2/teams/${encodeURIComponent(teamId)}/financials/invoices`, "https://billing.w3dev.app");
url.search = new URLSearchParams({ projectId, limit: "50" }).toString(); // mode defaults to the key's environment
const response = await fetch(url, {
  headers: { Authorization: `Bearer ${apiKey}` },
  cache: "no-store",
});
const page = await response.json();
if (!response.ok) throw new Error(`BillStack ${response.status}: ${page.error?.code}; request ${page.meta?.requestId}`);
// Inspect page.data.items, page.data.nextCursor, and page.meta.freshness.
```

Provide teamId/projectId/apiKey from validated server configuration, never from an untrusted caller. Do not log full page contents by default.

## Interpretation and limits

- Keep amountMinor values as integers and report the currency; do not add currencies together or assume a fixed two-decimal exponent.
- Inspect `meta.freshness.completeness` (complete, partial, stale), lastSyncedAt, sourceCursor, and affectedProviders when present. Surface caveats in the answer.
- Missing data can reflect environment (test versus live key), scope, account incarnation, sync lag, or rollout readiness. Do not automatically conclude “no charges” or “no subscribers.”
- `actions` on a financial row are capability hints, not permission to invent mutation endpoints.
- Errors are `{ error: { code, message }, meta }`; capture sanitized requestId. Fix 403 authorization or 400 filters rather than retrying them. Use bounded backoff for transient read failures, and report persistent failure.

## Revenue by currency (multi-region teams)

`GET T/financials/currency-report` (`billing:GetBilling`; filters `mode`, `projectId`, `from`, `to`) groups collected payments, fees, net and refunds per provider account and currency, labelled with the account's region and merchant entity. There is no FX conversion: report each currency on its own. It answers `200` with `enabled: false` and no rows unless two or more regions are active in the requested mode, so a single-region team should use `financials/overview`. It reads the canonical `billing_*` records only, so an empty report can mean provider events are not projected yet. The dashboard shows the same data at billing, "View revenue by currency". The MCP tools `list_regions` and `get_region_coverage` exist only for teams with more than one enabled region.

## MCP alternative

The billing MCP endpoint is `https://billing.w3dev.app/mcp`. Use a compatible client with its supported OAuth flow or a private key. Discover actual tools with tools/list. Tool descriptions start with the generation they read: `v2:` for provider-neutral tools (regions, payouts, referrals, `create_lifetime_deal`), `Legacy:` for the Stripe-mirror list, metrics and BillingQL tools (`query_billing_data`), which are covered by legacy-billstack-integration, and no prefix for the campaign tools that serve both generations (`list_lifetime_campaigns`, `get_lifetime_campaign_status`, `update_lifetime_campaign`, `set_lifetime_campaign_status`: they read, edit, launch and end Catalog lifetime deals and legacy campaigns; see legacy-billstack-lifetime-deals). OAuth callers supply teamId (discover memberships with list_teams); private-key callers default to the key's team where supported. A private key works in its own environment only: a tool call that names another `environment` is rejected, while OAuth callers get the environment they ask for or the team default. Tool permissions still apply.

Do not confuse `/mcp` with the separate `/chatgpt/mcp` presentation surface or `/api/adminx/mcp`. Loading a SKILL.md neither installs an MCP client nor authenticates it, and the catalog does not make private tools public.

## Report evidence

State origin, source surface, team/project scope, provider/mode, filters/time range, currency, pagination completeness, and freshness. Separate confirmed observations from likely causes. Read-only investigation does not authorize cancellations, refunds, credential changes, or billing configuration changes.
