Skip to content
Ona Docs

GetCreditUsageExport

billing.get_credit_usage_export(BillingGetCreditUsageExportParams**kwargs) -> BillingGetCreditUsageExportResponse
POST/gitpod.v1.BillingService/GetCreditUsageExport

Returns a signed download URL for a CSV export of credit usage.

The URL points to an HTTP endpoint that streams gzip-compressed CSV and is valid for five minutes. The download must be made by the same principal that requested it, carrying its own bearer token. The export range may cover up to a year.

For organizations without enterprise credit usage enabled (no billing contract start date), the export instead contains BYOK cost usage with a different column set, and groupBy=RESOURCE is rejected.

Use this method to:

  • Export per-user daily credit usage for external reporting
  • Export a per-environment and per-conversation resource breakdown

Examples

  • Export January’s daily summary:

    organizationId: "b0e12f6c-4c67-429d-a4a6-d9838b5da047"
    dateRange:
      startTime: "2024-01-01T00:00:00Z"
      endTime: "2024-01-31T00:00:00Z"
    groupBy: CREDIT_USAGE_EXPORT_GROUP_BY_DAILY_SUMMARY

Authorization

Requires billing:read_usage permission on the organization.

ParametersExpand Collapse
date_range: DateRange

Date range to export. Both start and end dates are inclusive; time-of-day is ignored. Unlike GetCreditUsageReport, the range may cover up to a year.

end_time: datetime

End time of the date range (exclusive).

formatdate-time
start_time: datetime

Start time of the date range (inclusive).

formatdate-time
organization_id: str
formatuuid
group_by: Optional[CreditUsageExportGroupBy]

How to group the export data. Defaults to DAILY_SUMMARY.

One of the following:
"CREDIT_USAGE_EXPORT_GROUP_BY_UNSPECIFIED"
"CREDIT_USAGE_EXPORT_GROUP_BY_DAILY_SUMMARY"
"CREDIT_USAGE_EXPORT_GROUP_BY_RESOURCE"
ReturnsExpand Collapse
class BillingGetCreditUsageExportResponse:
download_url: Optional[str]

Signed download URL for the CSV export. Valid for five minutes, and only for the principal that requested it.

GetCreditUsageExport

import os
from datetime import datetime
from gitpod import Gitpod

client = Gitpod(
    bearer_token=os.environ.get("GITPOD_API_KEY"),  # This is the default and can be omitted
)
response = client.billing.get_credit_usage_export(
    date_range={
        "end_time": datetime.fromisoformat("2024-01-31T00:00:00"),
        "start_time": datetime.fromisoformat("2024-01-01T00:00:00"),
    },
    organization_id="b0e12f6c-4c67-429d-a4a6-d9838b5da047",
    group_by="CREDIT_USAGE_EXPORT_GROUP_BY_DAILY_SUMMARY",
)
print(response.download_url)
{
  "downloadUrl": "downloadUrl"
}
Returns Examples
{
  "downloadUrl": "downloadUrl"
}