feat(billing): add billing manager for the current billing period - #826
Merged
Conversation
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
marked this pull request as ready for review
August 18, 2026 12:01
LinoGiger
approved these changes
Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
billingmodule to the SDK with aRapidataBillingManager, reachable asclient.billing.What it returns
BillingPeriodis a frozen dataclass withid,start_date,end_date,status,outstanding_cost,gross_cost,discount,response_countandcredits.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_costis the net cost (gross minus discounts), i.e. what the period would be invoiced for today.GET /billing/summary—availableAmount, 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.availableAmountis only populated when the organization is on a prepaid plan (CreditLine == 0), socreditsisNoneon a usage-billed plan rather than a misleading0.Both endpoints are
IsAuthenticated-only for the caller's own organization, so no extra role is needed.Notes
get_current_billing_period()raises the usualRapidataError(404, "No active billing period found") for an organization that has never run a billable job. Documented in the guide.PaymentServiceto the service layer (matching the existing per-backend-service grouping) — no manager reached the payment service before.docs/billing.md, linked from the nav and the llms.txt sections.tests/rapidata_client/audience/are unrelated — they fail onmaintoo.🔗 Session: https://poseidon.rapidata.internal/chat/session-93f851b0