Organization
- class lightning_sdk.Organization(name=None)
Bases:
OwnerRepresents an organization owner of teamspaces and studios.
Note
Arguments will be automatically inferred from environment variables if possible, unless explicitly specified
- create_teamspace(name)
Create a new teamspace owned by this organization.
- get_activity(teamspace=None, teamspaces=None, filters=None, cursor=None)
Get billing activity for this organization, or one or more of its teamspaces.
Returns paginated rollup rows, one per resource over the queried range, keyed by raw teamspace/user/cloud account IDs. For a resolved-name, non-paginated report meant for reading or exporting, use
get_session_activity()(one row per session) orget_resource_activity()(one row per resource) instead.- Parameters:
teamspace (
Union[str,Teamspace,None]) – A single teamspace to scope the query to.teamspaces (
Optional[List[Union[str,Teamspace]]]) – Multiple teamspaces to scope the query to. Provide at most one ofteamspace/teamspaces. If neither is given, the query covers the whole organization.filters (
Optional[BillingActivityFilters]) – Optional filters to narrow down the query.cursor (
Optional[BillingActivityCursor]) – Optional pagination cursor to continue a previous query.filters (BillingActivityFilters | None)
cursor (BillingActivityCursor | None)
- Returns:
The usage report response.
- Return type:
- get_activity_breakdown(writer, format=ActivityFileFormat.JSON, teamspace=None, teamspaces=None, filters=None)
Get the billing activity cost breakdown report for this organization, as CSV or JSON.
One row per UTC day, resource type, user and teamspace with usage, with the columns
Date,Resource type,User,Teamspace,CostandSaved cost. This is the data behindget_activity_group_totals()andget_activity_group_daily_totals()at its finest grain, with resolved names, for regrouping elsewhere. Usage not assigned to a user or teamspace is listed underUnassigned.- Parameters:
writer (
IO[str]) – Writable text stream to write the report to, e.g. an open file, anio.StringIObuffer, orsys.stdout. To get the JSON as a string rather than writing it to a file, pass anio.StringIO()and read it back with.getvalue().format (
ActivityFileFormat) – File format to return the report in, either CSV or JSON. Defaults to JSON.teamspace (
Union[str,Teamspace,None]) – A single teamspace to scope the report to.teamspaces (
Optional[List[Union[str,Teamspace]]]) – Multiple teamspaces to scope the report to. Provide at most one ofteamspace/teamspaces.filters (
Optional[BillingActivityFilters]) – Optional filters to narrow down the report.format (ActivityFileFormat)
filters (BillingActivityFilters | None)
- Return type:
- get_activity_filter_resource_names(teamspace=None, search_query=None, page_size=None, page_token=None)
Get one page of the resource IDs a billing activity query can be filtered by.
Only covers Studios, jobs, multi-machine jobs and deployments, ordered by resource ID. Pass the returned
next_page_tokenback aspage_tokento fetch the next page.- Parameters:
teamspace (
Union[str,Teamspace,None]) – Optionally scope to a single teamspace. If omitted, covers the whole organization.search_query (
Optional[str]) – Only return resources whose name matches this.page_size (
Optional[int]) – Maximum number of resources to return. The server defaults to 20.page_token (
Optional[str]) –next_page_tokenfrom the previous page, to continue from it.search_query (str | None)
page_size (int | None)
page_token (str | None)
- Returns:
The page of resource IDs.
- Return type:
- get_activity_filter_values(teamspace=None)
Get the set of values a billing activity query can be filtered by.
- get_activity_group_daily_totals(group_by, teamspace=None, teamspaces=None, filters=None)
Get billing activity cost for this organization split by UTC day and resource type, user or teamspace.
Use
get_activity_group_totals()for each group’s cost summed over the whole queried range instead.- Parameters:
group_by (
BillingActivityGroupBy) – Dimension to split cost by: resource type, user or teamspace.teamspace (
Union[str,Teamspace,None]) – A single teamspace to scope the query to.teamspaces (
Optional[List[Union[str,Teamspace]]]) – Multiple teamspaces to scope the query to. Provide at most one ofteamspace/teamspaces. If neither is given, the query covers the whole organization.filters (
Optional[BillingActivityFilters]) – Optional filters to narrow down the query.limitis ignored.group_by (BillingActivityGroupBy)
filters (BillingActivityFilters | None)
- Returns:
Cost per day and group, newest day first. Days without usage are left out.
- Return type:
- get_activity_group_totals(group_by, teamspace=None, teamspaces=None, filters=None)
Get billing activity cost for this organization split by resource type, user or teamspace.
Each group’s cost is summed over the whole queried range. Use
get_activity_group_daily_totals()for the same split per UTC day, orget_activity_breakdown()for every dimension at once with resolved names.- Parameters:
group_by (
BillingActivityGroupBy) – Dimension to split cost by: resource type, user or teamspace.teamspace (
Union[str,Teamspace,None]) – A single teamspace to scope the query to.teamspaces (
Optional[List[Union[str,Teamspace]]]) – Multiple teamspaces to scope the query to. Provide at most one ofteamspace/teamspaces. If neither is given, the query covers the whole organization.filters (
Optional[BillingActivityFilters]) – Optional filters to narrow down the query.limitis ignored.group_by (BillingActivityGroupBy)
filters (BillingActivityFilters | None)
- Returns:
Cost per group, highest first, and the totals across groups.
- Return type:
- get_monthly_summary(start=None, end=None)
Returns a monthly summary of credits purchased, used, and remaining.
Exactly one of
startandendmust be supplied, or both together:only
start: grabs monthly summaries for months afterpivot=start.only
end: grabs monthly summaries for months beforepivot=end.both
startandend: acts as a normal range.
- Parameters:
- Return type:
- Returns:
A list of
MonthlySummarydicts, one per month in the requested range:[ { "period_start": datetime, "period_end": datetime, "total_credits_remaining": float, "total_credits_purchased": float, }, ... ]- Raises:
ValueError – If neither
startnorendis provided, ifstartis afterend, or if an “AFTER” pivot (derived from a lonestart) is in the future.
- get_resource_activity(writer, format=ActivityFileFormat.JSON, teamspace=None, teamspaces=None, filters=None)
Get the resource-level billing activity report for this organization, as CSV or JSON.
One row per resource (e.g. a Studio or Job) that was active in the queried time range, rather than one row per session; use
get_session_activity()for the finer-grained, per-session breakdown of a resource’s activity.- Parameters:
writer (
IO[str]) – Writable text stream to write the report to, e.g. an open file, anio.StringIObuffer, orsys.stdout. To get the JSON as a string rather than writing it to a file, pass anio.StringIO()and read it back with.getvalue().format (
ActivityFileFormat) – File format to return the report in, either CSV or JSON. Defaults to JSON.teamspace (
Union[str,Teamspace,None]) – A single teamspace to scope the report to.teamspaces (
Optional[List[Union[str,Teamspace]]]) – Multiple teamspaces to scope the report to. Provide at most one ofteamspace/teamspaces.filters (
Optional[BillingActivityFilters]) – Optional filters to narrow down the report.format (ActivityFileFormat)
filters (BillingActivityFilters | None)
- Return type:
- get_session_activity(writer, format=ActivityFileFormat.JSON, teamspace=None, teamspaces=None, filters=None)
Get the session-level billing activity report for this organization, as CSV or JSON.
One row per session. A resource (e.g. a Studio or Job) can have many sessions within the queried time range, so this report is the finer-grained of the two; use
get_resource_activity()for one row per resource instead.- Parameters:
writer (
IO[str]) – Writable text stream to write the report to, e.g. an open file, anio.StringIObuffer, orsys.stdout. To get the JSON as a string rather than writing it to a file, pass anio.StringIO()and read it back with.getvalue().format (
ActivityFileFormat) – File format to return the report in, either CSV or JSON. Defaults to JSON.teamspace (
Union[str,Teamspace,None]) – A single teamspace to scope the report to.teamspaces (
Optional[List[Union[str,Teamspace]]]) – Multiple teamspaces to scope the report to. Provide at most one ofteamspace/teamspaces.filters (
Optional[BillingActivityFilters]) – Optional filters to narrow down the report.format (ActivityFileFormat)
filters (BillingActivityFilters | None)
- Return type:
- property default_cloud_account: str | None
The organization’s preferred cloud account ID, or None if not set.
- Returns:
The preferred cloud account ID.
- Return type:
str | None
- property id: str
The organization’s ID.
- property name: str
The organization’s name.
- class lightning_sdk.api.org_api.MonthlySummary
Bases:
TypedDictA single month’s billing summary of credits purchased, used, and remaining.
- period_start
Start of the billing period (typically the first of the month).
- period_end
End of the billing period (typically the end of the month).
- total_credits_remaining
Total credits remaining at the end of the monthly period.
- total_credits_purchased
Total credits purchased during the monthly period.
- class lightning_sdk.BillingActivityFilters(resource_types=None, resource_ids=None, user_ids=None, cluster_ids=None, subfilters=None, start=None, end=None, limit=None)
Bases:
objectFilters for narrowing down a billing activity query.
The values each filter accepts are listed by
Organization.get_activity_filter_values(), and resource IDs byOrganization.get_activity_filter_resource_names().- Parameters:
- resource_types
Only include activity for these resource types (e.g. “lightning_code” for Studios, “job”).
- resource_ids
Only include activity for these specific resource IDs.
- user_ids
Only include activity generated by these users.
- cluster_ids
Only include activity on these cloud accounts.
- subfilters
Narrow individual resource types further, by tag or API key.
- start
Only include activity on or after this time.
- end
Only include activity on or before this time.
- limit
Maximum number of entries to return. Only applies to
Organization.get_activity(); the grouped totals and the session, resource and breakdown activity reports always return every entry.
- class lightning_sdk.BillingActivityCursor(search_after=None, search_after_resource_id=None, search_after_resource_type=None)
Bases:
objectPagination cursor for continuing a billing activity query.
- Parameters:
- search_after
Only include entries strictly after this time.
- search_after_resource_id
Resource ID of the last entry from the previous page. Required alongside
search_afterto break ties between resources sharing the same time.
- search_after_resource_type
Resource type of the last entry from the previous page. Required alongside
search_afterto break ties between resources sharing the same time.
- class lightning_sdk.BillingActivity(total_cost=None, total_saved_cost=None, usage=<factory>, daily_usage=<factory>, has_more=False, search_after=None, search_after_resource_id=None, search_after_resource_type=None)
Bases:
objectBilling activity for an org/teamspace scope, as returned by the V2 usage report endpoint.
- Parameters:
total_cost (float | None)
total_saved_cost (float | None)
usage (List[BillingResourceUsage])
daily_usage (List[BillingDailyUsage])
has_more (bool)
search_after (datetime | None)
search_after_resource_id (str | None)
search_after_resource_type (str | None)
- total_cost
Total credits spent by all filtered resources during the queried time range.
- total_saved_cost
Total credits saved by all filtered resources during the queried time range.
- usage
Per-resource usage/cost, one entry per filtered resource.
- daily_usage
Usage/cost aggregated by day.
- has_more
Whether more entries are available past
limit. IfTrue, pass aBillingActivityCursorbuilt fromsearch_after,search_after_resource_id, andsearch_after_resource_typeto fetch the next page.
- search_after
Cursor value to continue pagination from. Only set when
limitwas provided on the request.
- search_after_resource_id
Paired with
search_afterto break ties between resources sharing the samesearch_aftertime.
- search_after_resource_type
Paired with
search_afterto break ties between resources sharing the samesearch_aftertime.
- class lightning_sdk.BillingActivityFilterValues(project_ids=<factory>, user_ids=<factory>, resource_types=<factory>, cluster_ids=<factory>, subfilters=<factory>)
Bases:
objectThe set of values a billing activity query can be filtered by, for a given scope.
Resource IDs aren’t included, since an org can have too many to return at once; page through them with
Organization.get_activity_filter_resource_names()instead.- Parameters:
resource_types (List[BillingNamedFilterValue])
subfilters (BillingActivitySubfilterValues)
- project_ids
Teamspace (project) IDs with billing activity in the queried scope.
- user_ids
User IDs with billing activity in the queried scope.
- resource_types
Resource types with billing activity in the queried scope, paired with their display names, e.g. ID “lightning_code” with name “Studio”. Pass their IDs as
resource_typeswhen filtering.
- cluster_ids
Cloud account IDs with billing activity in the queried scope.
- subfilters
Values for the filters that only apply to one resource type.
- class lightning_sdk.BillingActivityGroupTotals(groups=<factory>, total_cost=None, total_saved_cost=None)
Bases:
objectBilling activity cost split by group, as returned by the group totals endpoint.
- Parameters:
groups (List[BillingActivityGroupTotal])
total_cost (float | None)
total_saved_cost (float | None)
- groups
Cost per group, ordered by cost, highest first.
- total_cost
Total credits spent, summed across all groups.
- total_saved_cost
Total credits saved, summed across all groups.
- class lightning_sdk.BillingActivityGroupTotal(group_value='', cost=None, saved_cost=None)
Bases:
objectCost for a single group, summed over the whole queried time range.
- group_value
The group this entry covers, depending on the
BillingActivityGroupByit was queried with: a raw resource type (e.g. “lightning_code” for Studios), a user ID or a teamspace (project) ID. Usage not assigned to a teamspace is grouped under an empty teamspace ID, and usage not assigned to a user under the nil-UUID user ID.
- cost
Total credits spent by this group.
- saved_cost
Total credits saved by this group.
- class lightning_sdk.BillingActivityGroupDailyTotals(daily_totals=<factory>)
Bases:
objectBilling activity cost split by UTC day and group, as returned by the group daily totals endpoint.
- Parameters:
daily_totals (List[BillingActivityGroupDailyTotal])
- daily_totals
One entry per day and group with usage, newest day first. Days without usage are left out.
- class lightning_sdk.BillingActivityGroupDailyTotal(day=None, group_value='', cost=None, saved_cost=None)
Bases:
objectCost for a single group on a single UTC day.
- day
The UTC day this entry covers.
- group_value
The group this entry covers, as in
BillingActivityGroupTotal.group_value.
- cost
Credits spent by this group on this day.
- saved_cost
Credits saved by this group on this day.
- class lightning_sdk.BillingResourceUsage(id=None, user_id=None, project_id=None, cluster_id=None, resource_type=None, resource_name=None, created_at=None, deleted_at=None, billed_time_seconds=None, cost=None, saved_cost=None, bucket_start=None)
Bases:
objectA single resource’s usage/cost within a billing activity report.
- Parameters:
id (str | None)
user_id (str | None)
project_id (str | None)
cluster_id (str | None)
resource_type (str | None)
resource_name (str | None)
created_at (datetime | None)
deleted_at (datetime | None)
billed_time_seconds (int | None)
cost (float | None)
saved_cost (float | None)
bucket_start (datetime | None)
- id
ID of the resource.
- user_id
ID of the user that owns/started the resource.
- project_id
ID of the teamspace (project) the resource belongs to.
- cluster_id
ID of the cloud account the resource ran on.
- resource_type
Type of the resource (e.g. “lightning_code” for a Studio, “job”).
- resource_name
Name of the resource.
- created_at
When the resource was created.
- deleted_at
When the resource was deleted, if it has been.
- billed_time_seconds
Total billed time for this resource, in seconds.
- cost
Total credits spent by this resource.
- saved_cost
Total credits saved by this resource.
- bucket_start
Start of the usage rollup bucket this row represents.
- class lightning_sdk.BillingDailyUsage(day=None, total_cost=None, total_saved_cost=None, total_prompt_tokens=None, total_completion_tokens=None, total_num_messages=None)
Bases:
objectAggregated usage/cost for a single day within a billing activity report.
- Parameters:
- day
The day this entry aggregates.
- total_cost
Total credits spent on this day.
- total_saved_cost
Total credits saved on this day.
- total_prompt_tokens
Total prompt tokens consumed on this day.
- total_completion_tokens
Total completion tokens consumed on this day.
- total_num_messages
Total number of messages sent on this day.
- class lightning_sdk.BillingActivitySubfilters(job=None, multi_machine_job=None, deployment=None, assistant_message=None)
Bases:
objectFilters that only apply to one resource type, one field per type.
Setting a field keeps only the rows of its resource type that match it. With several set, a row matching any of them is kept. Once any field is set, rows of resource types without a subfilter are dropped.
- Parameters:
job (BillingWorkloadTagSubfilter | None)
multi_machine_job (BillingWorkloadTagSubfilter | None)
deployment (BillingWorkloadTagSubfilter | None)
assistant_message (BillingAssistantMessageSubfilter | None)
- job
Applies to job rows.
- multi_machine_job
Applies to multi-machine job rows.
- deployment
Applies to deployment rows.
- assistant_message
Applies to assistant message rows.
- class lightning_sdk.BillingWorkloadTagSubfilter(tag_ids=<factory>, match_all_tags=False)
Bases:
objectKeeps only the workloads of one resource type that carry the given tags.
- tag_ids
Keep workloads with any of these tags. Available tags are listed in
BillingActivityFilterValues.subfilters. Empty means no subfilter for this resource type.
- match_all_tags
Require every tag in
tag_idsrather than any.
- class lightning_sdk.BillingAssistantMessageSubfilter(api_key_ids=<factory>)
Bases:
objectKeeps only the assistant messages billed through the given API keys.
- api_key_ids
Keep messages billed through any of these API keys. Available keys are listed in
BillingActivityFilterValues.subfilters. Empty means no subfilter for assistant messages.
- class lightning_sdk.BillingActivitySubfilterValues(job=<factory>, multi_machine_job=<factory>, deployment=<factory>, assistant_message=<factory>)
Bases:
objectFilter values that only apply to one resource type, one field per type.
- Parameters:
multi_machine_job (BillingWorkloadSubfilterValues)
deployment (BillingWorkloadSubfilterValues)
assistant_message (BillingAssistantMessageSubfilterValues)
- job
Tags available to filter jobs by.
- multi_machine_job
Tags available to filter multi-machine jobs by.
- deployment
Tags available to filter deployments by.
- assistant_message
API keys available to filter assistant messages by.
- class lightning_sdk.BillingWorkloadSubfilterValues(resource_type=None, tags=<factory>)
Bases:
objectTags a workload resource type (jobs, multi-machine jobs or deployments) can be filtered by.
- Parameters:
resource_type (str | None)
tags (List[BillingNamedFilterValue])
- resource_type
Display name of the resource type these tags belong to, e.g. “Job”.
- tags
Tags on at least one workload of this type. Pass their IDs as
BillingWorkloadTagSubfilter.tag_ids.
- class lightning_sdk.BillingAssistantMessageSubfilterValues(api_key_ids=<factory>)
Bases:
objectAPI keys assistant messages can be filtered by.
- Parameters:
api_key_ids (List[BillingNamedFilterValue])
- api_key_ids
API keys that billed at least one message.
nameis the key’s display name, never its secret. Pass their IDs asBillingAssistantMessageSubfilter.api_key_ids.
- class lightning_sdk.BillingActivityResourceNames(resource_ids=<factory>, next_page_token=None)
Bases:
objectOne page of resource IDs a billing activity query can be filtered by.
- Parameters:
resource_ids (List[BillingNamedFilterValue])
next_page_token (str | None)
- resource_ids
Resource IDs paired with their display names.
- next_page_token
Pass as
page_tokento fetch the next page. Empty on the last page.
Was this page helpful?
Thanks for the feedback.