Skip to main content
REST API 现已经过版本控制。 有关详细信息,请参阅“关于 API 版本控制”。

适用于企业计费的 REST API 终结点

使用 REST API 检索 GitHub Enterprise Server 实例的计费信息。

这些终结点仅支持使用 personal access token (classic) 进行身份验证。 有关详细信息,请参阅“管理个人访问令牌”。

personal access tokens (classic) 访问这些终结点需要 manage_billing:enterprise 范围。

Get GitHub Actions billing for an enterprise

Gets the summary of the free and paid GitHub Actions minutes used.

Paid minutes only apply to workflows in private repositories that use GitHub-hosted runners. Minutes used is listed for each GitHub-hosted runner operating system. Any job re-runs are also included in the usage. The usage does not include the multiplier for macOS and Windows runners and is not rounded up to the nearest whole minute. For more information, see "Managing billing for GitHub Actions".

The authenticated user must be an enterprise admin.

“Get GitHub Actions billing for an enterprise”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Enterprise administration" business permissions (write)

“Get GitHub Actions billing for an enterprise”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

“Get GitHub Actions billing for an enterprise”的 HTTP 响应状态代码

状态代码说明
200

OK

“Get GitHub Actions billing for an enterprise”的示例代码

如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。

请求示例

get/enterprises/{enterprise}/settings/billing/actions
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/enterprises/ENTERPRISE/settings/billing/actions

Response

Status: 200
{ "total_minutes_used": 305, "total_paid_minutes_used": 0, "included_minutes": 3000, "minutes_used_breakdown": { "UBUNTU": 205, "MACOS": 10, "WINDOWS": 90 } }

Get GitHub Advanced Security active committers for an enterprise

Gets the GitHub Advanced Security active committers for an enterprise per repository.

Each distinct user login across all repositories is counted as a single Advanced Security seat, so the total_advanced_security_committers is not the sum of active_users for each repository.

The total number of repositories with committer information is tracked by the total_count field.

“Get GitHub Advanced Security active committers for an enterprise”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Enterprise administration" business permissions (write)

“Get GitHub Advanced Security active committers for an enterprise”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

查询参数
名称, 类型, 说明
per_page integer

The number of results per page (max 100). For more information, see "Using pagination in the REST API."

默认: 30

page integer

The page number of the results to fetch. For more information, see "Using pagination in the REST API."

默认: 1

“Get GitHub Advanced Security active committers for an enterprise”的 HTTP 响应状态代码

状态代码说明
200

Success

“Get GitHub Advanced Security active committers for an enterprise”的示例代码

如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。

请求示例

get/enterprises/{enterprise}/settings/billing/advanced-security
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/enterprises/ENTERPRISE/settings/billing/advanced-security

Success

Status: 200
{ "total_advanced_security_committers": 2, "total_count": 2, "maximum_advanced_security_committers": 4, "purchased_advanced_security_committers": 4, "repositories": [ { "name": "octocat-org/Hello-World", "advanced_security_committers": 2, "advanced_security_committers_breakdown": [ { "user_login": "octocat", "last_pushed_date": "2021-11-03", "last_pushed_email": "octocat@github.com" }, { "user_login": "octokitten", "last_pushed_date": "2021-10-25", "last_pushed_email": "octokitten@github.com" } ] }, { "name": "octocat-org/server", "advanced_security_committers": 1, "advanced_security_committers_breakdown": [ { "user_login": "octokitten", "last_pushed_date": "2021-10-26", "last_pushed_email": "octokitten@github.com" } ] } ] }

Get all cost centers for an enterprise

Gets a list of all the cost centers for an enterprise.

“Get all cost centers for an enterprise”的细粒度访问令牌

此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。

“Get all cost centers for an enterprise”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

“Get all cost centers for an enterprise”的 HTTP 响应状态代码

状态代码说明
200

Response when getting cost centers

400

Bad Request

403

Forbidden

500

Internal Error

503

Service unavailable

“Get all cost centers for an enterprise”的示例代码

如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。

请求示例

get/enterprises/{enterprise}/settings/billing/cost-centers
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers

Response when getting cost centers

Status: 200
{ "costCenters": [ { "id": "2eeb8ffe-6903-11ee-8c99-0242ac120002", "name": "Cost Center Name", "resources": [ { "type": "User", "name": "Monalisa" } ] } ] }

Add users to a cost center

Adds users to a cost center.

The usage for the users will be charged to the cost center's budget. The authenticated user must be an enterprise admin in order to use this endpoint.

“Add users to a cost center”的细粒度访问令牌

此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。

“Add users to a cost center”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

cost_center_id string 必须

The ID corresponding to the cost center.

正文参数
名称, 类型, 说明
users array of strings 必须

The usernames of the users to add to the cost center.

“Add users to a cost center”的 HTTP 响应状态代码

状态代码说明
200

Response when adding resources to a cost center

400

Bad Request

403

Forbidden

409

Conflict

500

Internal Error

503

Service unavailable

“Add users to a cost center”的示例代码

如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。

请求示例

post/enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}/resource
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_ID/resource \ -d '{"users":["monalisa"]}'

Response when adding resources to a cost center

Status: 200
{ "message": "Resources successfully added to the cost center." }

Remove users from a cost center

Remove users from a cost center.

The usage for the users will no longer be charged to the cost center's budget. The authenticated user must be an enterprise admin in order to use this endpoint.

“Remove users from a cost center”的细粒度访问令牌

此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。

“Remove users from a cost center”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

cost_center_id string 必须

The ID corresponding to the cost center.

正文参数
名称, 类型, 说明
users array of strings 必须

The usernames of the users to remove from the cost center.

“Remove users from a cost center”的 HTTP 响应状态代码

状态代码说明
200

Response when removing resources from a cost center

400

Bad Request

403

Forbidden

500

Internal Error

503

Service unavailable

“Remove users from a cost center”的示例代码

如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。

请求示例

delete/enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}/resource
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_ID/resource \ -d '{"users":["monalisa"]}'

Response when removing resources from a cost center

Status: 200
{ "message": "Resources successfully removed from the cost center." }

Get GitHub Packages billing for an enterprise

Gets the free and paid storage used for GitHub Packages in gigabytes.

Paid minutes only apply to packages stored for private repositories. For more information, see "Managing billing for GitHub Packages."

The authenticated user must be an enterprise admin.

“Get GitHub Packages billing for an enterprise”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Enterprise administration" business permissions (write)

“Get GitHub Packages billing for an enterprise”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

“Get GitHub Packages billing for an enterprise”的 HTTP 响应状态代码

状态代码说明
200

OK

“Get GitHub Packages billing for an enterprise”的示例代码

如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。

请求示例

get/enterprises/{enterprise}/settings/billing/packages
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/enterprises/ENTERPRISE/settings/billing/packages

Response

Status: 200
{ "total_gigabytes_bandwidth_used": 50, "total_paid_gigabytes_bandwidth_used": 40, "included_gigabytes_bandwidth": 10 }

Get shared storage billing for an enterprise

Gets the estimated paid and estimated total storage used for GitHub Actions and GitHub Packages.

Paid minutes only apply to packages stored for private repositories. For more information, see "Managing billing for GitHub Packages."

The authenticated user must be an enterprise admin.

“Get shared storage billing for an enterprise”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Enterprise administration" business permissions (write)

“Get shared storage billing for an enterprise”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

“Get shared storage billing for an enterprise”的 HTTP 响应状态代码

状态代码说明
200

OK

“Get shared storage billing for an enterprise”的示例代码

如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。

请求示例

get/enterprises/{enterprise}/settings/billing/shared-storage
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/enterprises/ENTERPRISE/settings/billing/shared-storage

Response

Status: 200
{ "days_left_in_billing_cycle": 20, "estimated_paid_storage_for_month": 15, "estimated_storage_for_month": 40 }

Get billing usage report for an enterprise

Gets a report of usage by cost center for an enterprise. To use this endpoint, you must be an administrator or billing manager of the enterprise. By default this endpoint will return usage that does not have a cost center.

Note: This endpoint is only available to enterprises with access to the enhanced billing platform. For more information, see "About the enhanced billing platform for enterprises."

“Get billing usage report for an enterprise”的细粒度访问令牌

此终结点不适用于 GitHub 应用程序用户访问令牌、GitHub 应用程序安装访问令牌或细粒度个人访问令牌。

“Get billing usage report for an enterprise”的参数

标头
名称, 类型, 说明
accept string

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
enterprise string 必须

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

查询参数
名称, 类型, 说明
year integer

If specified, only return results for a single year. The value of year is an integer with four digits representing a year. For example, 2024. Default value is the current year.

month integer

If specified, only return results for a single month. The value of month is an integer between 1 and 12.

day integer

If specified, only return results for a single day. The value of day is an integer between 1 and 31.

hour integer

If specified, only return results for a single hour. The value of hour is an integer between 0 and 23.

cost_center_id string

The ID corresponding to a cost center. The default value is no cost center.

“Get billing usage report for an enterprise”的 HTTP 响应状态代码

状态代码说明
200

Response when getting a billing usage report

400

Bad Request

403

Forbidden

500

Internal Error

503

Service unavailable

“Get billing usage report for an enterprise”的示例代码

如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。

请求示例

get/enterprises/{enterprise}/settings/billing/usage
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/enterprises/ENTERPRISE/settings/billing/usage

Response when getting a billing usage report

Status: 200
{ "usageItems": [ { "date": "2023-08-01", "product": "Actions", "sku": "Actions Linux", "quantity": 100, "unitType": "minutes", "pricePerUnit": 0.008, "grossAmount": 0.8, "discountAmount": 0, "netAmount": 0.8, "organizationName": "GitHub", "repositoryName": "github/example" } ] }