Skip to content

feat(billing): add billing manager for the current billing period - #826

Merged
LinoGiger merged 2 commits into
mainfrom
feat(billing)/add-billing-manager
Aug 18, 2026
Merged

feat(billing): add billing manager for the current billing period#826
LinoGiger merged 2 commits into
mainfrom
feat(billing)/add-billing-manager

Conversation

@RapidPoseidon

Copy link
Copy Markdown
Contributor

Adds a billing module to the SDK with a RapidataBillingManager, reachable as client.billing.

period = client.billing.get_current_billing_period()

period.start_date, period.end_date   # the period's window
period.status                        # "Open" while it is still accruing
period.outstanding_cost              # net cost accrued so far, in USD
period.credits                       # remaining prepaid credit, or None

What it returns

BillingPeriod is a frozen dataclass with id, start_date, end_date, status, outstanding_cost, gross_cost, discount, response_count and credits.

Where the numbers come from

Two payment-service endpoints, folded into one object:

  • GET /billing-period/active — the period, its dates/status, and its costs. outstanding_cost is the net cost (gross minus discounts), i.e. what the period would be invoiced for today.
  • GET /billing/summaryavailableAmount, the remaining prepaid balance. Credits sit on the organization's billing account rather than on the period, which is why they need the second call.

availableAmount is only populated when the organization is on a prepaid plan (CreditLine == 0), so credits is None on a usage-billed plan rather than a misleading 0.

Both endpoints are IsAuthenticated-only for the caller's own organization, so no extra role is needed.

Notes

  • A billing period only opens once there is something to bill, so get_current_billing_period() raises the usual RapidataError (404, "No active billing period found") for an organization that has never run a billable job. Documented in the guide.
  • Adds a PaymentService to the service layer (matching the existing per-backend-service grouping) — no manager reached the payment service before.
  • New guide at docs/billing.md, linked from the nav and the llms.txt sections.
  • 4 pre-existing test failures under tests/rapidata_client/audience/ are unrelated — they fail on main too.

🔗 Session: https://poseidon.rapidata.internal/chat/session-93f851b0

RapidPoseidon and others added 2 commits August 18, 2026 09:18
Adds `client.billing`, a RapidataBillingManager whose
`get_current_billing_period()` returns a frozen `BillingPeriod` with the
period's dates and status, the cost accrued so far, and the remaining
prepaid credits.

The figures come from two payment-service endpoints, folded into one
object: `/billing-period/active` carries the period and its costs, while
credits live on the organization's billing account and so come from
`/billing/summary` (`availableAmount`). That field is only populated for
prepaid organizations, so `credits` is `None` on a usage-billed plan
rather than a misleading 0.

`outstanding_cost` maps to the period's net cost (gross minus
discounts) — what the period would be invoiced for today — with
`gross_cost` and `discount` exposed alongside it.

Also adds a `PaymentService` to the service layer, matching the existing
per-backend-service grouping, since no manager reached the payment
service before.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: lino <68745352+LinoGiger@users.noreply.github.com>
Cost accrues per response, so the raw totals carry far more decimals than
money has. Rounding in the SDK keeps the reported figures printable
without every caller doing it.

Adds `effective_limit` from the billing summary — the cap on what the
organization may spend this period, `None` when uncapped. Vouchers raise
it, so on a prepaid plan it is the total credit granted and `credits` is
what remains of it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: lino <68745352+LinoGiger@users.noreply.github.com>
@LinoGiger
LinoGiger marked this pull request as ready for review August 18, 2026 12:01
@LinoGiger
LinoGiger self-requested a review as a code owner August 18, 2026 12:01
@LinoGiger
LinoGiger merged commit a08e425 into main Aug 18, 2026
2 checks passed
@LinoGiger
LinoGiger deleted the feat(billing)/add-billing-manager branch August 18, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants