Repository navigation
feat(account-tree): add usage attribution types and attributed usage - #427
Open
lovrocolic wants to merge 3 commits into
Open
lovrocolic wants to merge 3 commits into
lovrocolic wants to merge 3 commits into
Conversation
vincent-pochet
left a comment
Contributor
There was a problem hiding this comment.
Checked against the API (main) and the spec in getlago/lago-openapi#665. The usage attribution type models and payload match the API. Only minor issues in attributed_usage.
… param Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vincent-pochet
approved these changes
Oct 29, 2026
| if not charge_codes: | ||
| # An empty list would send no param, which the API reads as all charges | ||
| raise ValueError("charge_codes must not be empty") | ||
| query_params["charge_codes[]"] = list(charge_codes) |
Contributor
There was a problem hiding this comment.
A single string passed here, charge_codes="tokens", gets split into characters by list(charge_codes) and sends charge_codes[]=t&charge_codes[]=o&.... The API then returns a 404 "charge not found", which looks like a missing charge rather than a misuse of the client. Could we wrap a string in a list ([charge_codes] if isinstance(charge_codes, str) else list(charge_codes)) or raise a clear error?
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.
Context
The account tree feature lets usage be tracked under custom types, such as teams or users. The API exposes CRUD endpoints for usage attribution types (getlago/lago-api#6415) and an endpoint that reads attributed usage (getlago/lago-api#6566).
Description
Usage attribution types
client.usage_attribution_typesclient withcreate,update,find,destroyandfind_all. Each one is keyed bycode.UsageAttributionTypeinput model andUsageAttributionTypeResponseresponse model.find_allacceptspage,per_page,roleandsearch_termoptions.Attributed usage
client.customers.attributed_usage(external_customer_id, external_subscription_id, group_by, filters=None, charge_codes=None, options=None).group_byis required, as it is in the API. It callsGET /customers/:external_customer_id/attributed_usage.filters, a string value is sent asfilters[key]=valueand a list value as repeatedfilters[key][]=value.charge_codesis sent ascharge_codes[]=value. An empty list in either one raisesValueError, because it would send no param and the API would drop the filter or read it as all charges. The other query params (from_datetime,to_datetime,split_charge_code,search_term,basis,page,per_page) go throughoptions.{"attributed_usage": AttributedUsageResponse, "meta": {...}}. The response includes the rows, the unattributed usage and the totals, and each one is split into charge usage.Fixtures and tests cover each endpoint.
🤖 Generated with Claude Code