Organization

class lightning_sdk.Organization(name=None)

Bases: Owner

Represents an organization owner of teamspaces and studios.

Parameters:
  • name (Optional[str]) – the name of the organization

  • name (str | None)

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.

Parameters:
  • name (str) – The name for the new teamspace.

  • name (str)

Returns:

The newly created teamspace.

Return type:

Teamspace

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) or get_resource_activity() (one row per resource) instead.

Parameters:
Returns:

The usage report response.

Return type:

BillingActivity

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, Cost and Saved cost. This is the data behind get_activity_group_totals() and get_activity_group_daily_totals() at its finest grain, with resolved names, for regrouping elsewhere. Usage not assigned to a user or teamspace is listed under Unassigned.

Parameters:
  • writer (IO[str]) – Writable text stream to write the report to, e.g. an open file, an io.StringIO buffer, or sys.stdout. To get the JSON as a string rather than writing it to a file, pass an io.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 of teamspace/teamspaces.

  • filters (Optional[BillingActivityFilters]) – Optional filters to narrow down the report.

  • writer (IO[str])

  • format (ActivityFileFormat)

  • teamspace (str | Teamspace | None)

  • teamspaces (List[str | Teamspace] | None)

  • filters (BillingActivityFilters | None)

Return type:

None

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_token back as page_token to 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_token from the previous page, to continue from it.

  • teamspace (str | Teamspace | None)

  • search_query (str | None)

  • page_size (int | None)

  • page_token (str | None)

Returns:

The page of resource IDs.

Return type:

BillingActivityResourceNames

get_activity_filter_values(teamspace=None)

Get the set of values a billing activity query can be filtered by.

Parameters:
  • teamspace (Union[str, Teamspace, None]) – Optionally scope to a single teamspace. If omitted, covers the whole organization.

  • teamspace (str | Teamspace | None)

Returns:

The available filter values.

Return type:

BillingActivityFilterValues

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:
Returns:

Cost per day and group, newest day first. Days without usage are left out.

Return type:

BillingActivityGroupDailyTotals

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, or get_activity_breakdown() for every dimension at once with resolved names.

Parameters:
Returns:

Cost per group, highest first, and the totals across groups.

Return type:

BillingActivityGroupTotals

get_monthly_summary(start=None, end=None)

Returns a monthly summary of credits purchased, used, and remaining.

Exactly one of start and end must be supplied, or both together:

  • only start: grabs monthly summaries for months after pivot=start.

  • only end: grabs monthly summaries for months before pivot=end.

  • both start and end: acts as a normal range.

Parameters:
  • start (Optional[datetime]) – Start of the time range. If given without end, acts as an “AFTER” pivot.

  • end (Optional[datetime]) – End of the time range. If given without start, acts as a “BEFORE” pivot.

  • start (datetime | None)

  • end (datetime | None)

Return type:

list[MonthlySummary]

Returns:

A list of MonthlySummary dicts, 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 start nor end is provided, if start is after end, or if an “AFTER” pivot (derived from a lone start) 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, an io.StringIO buffer, or sys.stdout. To get the JSON as a string rather than writing it to a file, pass an io.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 of teamspace/teamspaces.

  • filters (Optional[BillingActivityFilters]) – Optional filters to narrow down the report.

  • writer (IO[str])

  • format (ActivityFileFormat)

  • teamspace (str | Teamspace | None)

  • teamspaces (List[str | Teamspace] | None)

  • filters (BillingActivityFilters | None)

Return type:

None

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, an io.StringIO buffer, or sys.stdout. To get the JSON as a string rather than writing it to a file, pass an io.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 of teamspace/teamspaces.

  • filters (Optional[BillingActivityFilters]) – Optional filters to narrow down the report.

  • writer (IO[str])

  • format (ActivityFileFormat)

  • teamspace (str | Teamspace | None)

  • teamspaces (List[str | Teamspace] | None)

  • filters (BillingActivityFilters | None)

Return type:

None

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: TypedDict

A 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: object

Filters for narrowing down a billing activity query.

The values each filter accepts are listed by Organization.get_activity_filter_values(), and resource IDs by Organization.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: object

Pagination cursor for continuing a billing activity query.

Parameters:
  • search_after (datetime | None)

  • search_after_resource_id (str | None)

  • search_after_resource_type (str | None)

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_after to 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_after to break ties between resources sharing the same time.

class lightning_sdk.ActivityFileFormat(*values)

Bases: str, Enum

File format to return a billing activity report in.

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: object

Billing activity for an org/teamspace scope, as returned by the V2 usage report endpoint.

Parameters:
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. If True, pass a BillingActivityCursor built from search_after, search_after_resource_id, and search_after_resource_type to fetch the next page.

search_after

Cursor value to continue pagination from. Only set when limit was provided on the request.

search_after_resource_id

Paired with search_after to break ties between resources sharing the same search_after time.

search_after_resource_type

Paired with search_after to break ties between resources sharing the same search_after time.

class lightning_sdk.BillingActivityFilterValues(project_ids=<factory>, user_ids=<factory>, resource_types=<factory>, cluster_ids=<factory>, subfilters=<factory>)

Bases: object

The 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:
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_types when 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.BillingActivityGroupBy(*values)

Bases: str, Enum

Dimension the grouped billing activity endpoints split cost by.

class lightning_sdk.BillingActivityGroupTotals(groups=<factory>, total_cost=None, total_saved_cost=None)

Bases: object

Billing activity cost split by group, as returned by the group totals endpoint.

Parameters:
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: object

Cost for a single group, summed over the whole queried time range.

Parameters:
  • group_value (str)

  • cost (float | None)

  • saved_cost (float | None)

group_value

The group this entry covers, depending on the BillingActivityGroupBy it 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: object

Billing 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: object

Cost for a single group on a single UTC day.

Parameters:
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: object

A 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: object

Aggregated usage/cost for a single day within a billing activity report.

Parameters:
  • day (datetime | None)

  • total_cost (float | None)

  • total_saved_cost (float | None)

  • total_prompt_tokens (int | None)

  • total_completion_tokens (int | None)

  • total_num_messages (int | None)

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.BillingNamedFilterValue(id=None, name=None)

Bases: object

A filterable ID paired with its display name.

Parameters:
  • id (str | None)

  • name (str | None)

id

The ID to filter by.

name

Display name for the ID. Falls back to the ID itself when no name could be resolved.

class lightning_sdk.BillingActivitySubfilters(job=None, multi_machine_job=None, deployment=None, assistant_message=None)

Bases: object

Filters 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

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: object

Keeps only the workloads of one resource type that carry the given tags.

Parameters:
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_ids rather than any.

class lightning_sdk.BillingAssistantMessageSubfilter(api_key_ids=<factory>)

Bases: object

Keeps only the assistant messages billed through the given API keys.

Parameters:

api_key_ids (List[str])

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: object

Filter values that only apply to one resource type, one field per type.

Parameters:
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: object

Tags a workload resource type (jobs, multi-machine jobs or deployments) can be filtered by.

Parameters:
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: object

API keys assistant messages can be filtered by.

Parameters:

api_key_ids (List[BillingNamedFilterValue])

api_key_ids

API keys that billed at least one message. name is the key’s display name, never its secret. Pass their IDs as BillingAssistantMessageSubfilter.api_key_ids.

class lightning_sdk.BillingActivityResourceNames(resource_ids=<factory>, next_page_token=None)

Bases: object

One page of resource IDs a billing activity query can be filtered by.

Parameters:
resource_ids

Resource IDs paired with their display names.

next_page_token

Pass as page_token to fetch the next page. Empty on the last page.

Was this page helpful?

What went wrong?

↑↓ Navigate↵ Open⌘↵ New tabesc Close