Budgets
使用 REST API 获取预算信息。
重要
下面的请求正文架构缺少必填字段。 当 budget_scope 为 user 时,还必须包含一个 user 字段,并将其设置为该预算适用的 GitHub 用户名。 如果省略此字段,API 将 HTTP 400: Missing required fields: budget_entity_name返回 。 对于用户作用域预算,budget_entity_name 可以为空字符串。
以下示例创建一个用户范围的预算,该预算将单个用户的每月 CopilotAI credits 限制为 30 美元:
{
"budget_amount": 30,
"prevent_further_usage": true,
"budget_scope": "user",
"budget_entity_name": "",
"budget_type": "BundlePricing",
"budget_product_sku": "ai_credits",
"budget_alerting": {
"will_alert": false,
"alert_recipients": []
},
"user": "USERNAME"
}
Get all budgets
Gets all budgets for an enterprise. The authenticated actor must have permission to view enterprise billing. Each page returns up to 100 budgets.
“Get all budgets”的细粒度访问令牌
此端点支持以下精细令牌类型:
细粒度令牌必须具有以下权限集:
- "Enterprise billing" enterprise permissions (read)
“”Get all budgets 的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name. |
| 名称, 类型, 说明 |
|---|
page integer The page number of results to fetch. 默认: |
per_page integer The number of results per page (max 100). 默认: |
scope string Filter budgets by scope type.
可以是以下选项之一: |
user string Filter consumed amount details for budgets by the specified user login. |
“Get all budgets”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Response when getting all budgets |
403 | Forbidden |
404 | Resource not found |
“Get all budgets”的代码示例
如果你在 GHE.com 上访问 GitHub,请将 api.github.com 替换为企业的专用子域,位于 api.SUBDOMAIN.ghe.com。
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/budgetsResponse when getting all budgets
Status: 200{
"budgets": [
{
"id": "2066deda-923f-43f9-88d2-62395a28c0cdd",
"budget_type": "ProductPricing",
"budget_product_skus": [
"actions"
],
"budget_scope": "enterprise",
"budget_amount": 1000,
"prevent_further_usage": true,
"budget_alerting": {
"will_alert": true,
"alert_recipients": [
"enterprise-admin",
"billing-manager"
]
}
},
{
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"budget_type": "SkuPricing",
"budget_product_skus": [
"actions_linux"
],
"budget_scope": "organization",
"budget_amount": 500,
"prevent_further_usage": false,
"budget_alerting": {
"will_alert": true,
"alert_recipients": [
"org-owner"
]
}
},
{
"id": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
"budget_type": "ProductPricing",
"budget_product_skus": [
"packages"
],
"budget_scope": "cost_center",
"budget_amount": 250,
"prevent_further_usage": true,
"budget_alerting": {
"will_alert": false,
"alert_recipients": []
}
}
],
"has_next_page": false,
"total_count": 3
}Create a budget
Creates a new budget for an enterprise. The authenticated user must be an enterprise admin, organization admin, or billing manager of the enterprise.
“Create a budget”的细粒度访问令牌
此终结点不适用于GitHub应用用户访问令牌、GitHub应用安装访问令牌或精细的个人访问令牌。
“”Create a budget 的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name. |
| 名称, 类型, 说明 | |||
|---|---|---|---|
budget_amount integer 必须The budget amount in whole dollars. For license-based products, this represents the number of licenses. | |||
prevent_further_usage boolean 必须Whether to prevent additional spending once the budget is exceeded. For | |||
budget_alerting object 必须 | |||
Properties of |
| 名称, 类型, 说明 |
|---|
will_alert boolean 必须Whether alerts are enabled for this budget |
alert_recipients array of strings 必须Array of user login names who will receive alerts |
budget_scope string 必须The scope of the budget.
enterprise: Apply the budget to the entire enterprise.organization: Apply the budget to a specific organization in the enterprise.repository: Apply the budget to a specific repository.cost_center: Apply the budget to a specific cost center.multi_user_customer: Apply a universal budget to all users in the enterprise.multi_user_cost_center: Apply a universal budget to all users in a cost center.user: Apply the budget to a single user.
user, multi_user_customer, and multi_user_cost_center scopes are only supported when budget_product_sku is ai_credits or premium_requests.
可以是以下选项之一: enterprise, organization, repository, cost_center, multi_user_customer, multi_user_cost_center, user
budget_entity_name string The name of the entity to apply the budget to
默认: ""
budget_type string 必须The type of pricing model used by the budget. Determines how budget_product_sku is interpreted.
BundlePricing: Covers all AI credit SKUs. Setbudget_product_skutoai_credits.ProductPricing: Covers all SKUs that belong to a product. Setbudget_product_skuto a product such asactionsorpackages.SkuPricing: Covers a single, specific SKU. Setbudget_product_skuto a SKU such asactions_linux.
budget_product_sku string A single product or SKU that will be covered in the budget
user string The username of the user for user scope budgets. This field is required when budget_scope is user.
“Create a budget”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Budget created successfully |
400 | Bad Request |
401 | Requires authentication |
403 | Forbidden |
404 | Feature not enabled |
422 | Validation failed, or the endpoint has been spammed. |
500 | Internal server error |
“Create a budget”的代码示例
如果你在 GHE.com 上访问 GitHub,请将 api.github.com 替换为企业的专用子域,位于 api.SUBDOMAIN.ghe.com。
请求示例
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/budgets \
-d '{"budget_amount":200,"prevent_further_usage":true,"budget_scope":"enterprise","budget_entity_name":"","budget_type":"ProductPricing","budget_product_sku":"actions","budget_alerting":{"will_alert":false,"alert_recipients":[]}}'Budget created successfully
Status: 200{
"message": "Budget successfully created.",
"budget": {
"id": "f5236c62-157f-4d8f-a79e-ffb91058ee97",
"budget_type": "ProductPricing",
"budget_product_sku": "actions",
"budget_scope": "organization",
"budget_entity_name": "example-organization",
"budget_amount": 100,
"prevent_further_usage": true,
"budget_alerting": {
"will_alert": false,
"alert_recipients": []
}
}
}Get a budget by ID
Gets a budget by ID. The authenticated actor must have permission to view enterprise billing.
“Get a budget by ID”的细粒度访问令牌
此端点支持以下精细令牌类型:
细粒度令牌必须具有以下权限集:
- "Enterprise billing" enterprise permissions (read)
“”Get a budget by ID 的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name. |
budget_id string 必须The ID corresponding to the budget. |
“Get a budget by ID”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Response when updating a budget |
400 | Bad Request |
403 | Forbidden |
404 | Resource not found |
500 | Internal Error |
503 | Service unavailable |
“Get a budget by ID”的代码示例
如果你在 GHE.com 上访问 GitHub,请将 api.github.com 替换为企业的专用子域,位于 api.SUBDOMAIN.ghe.com。
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/budgets/BUDGET_IDResponse when updating a budget
Status: 200{
"id": "2066deda-923f-43f9-88d2-62395a28c0cdd",
"budget_type": "ProductPricing",
"budget_product_sku": "actions_linux",
"budget_scope": "repository",
"budget_entity_name": "example-repo-name",
"budget_amount": 0,
"prevent_further_usage": true,
"budget_alerting": {
"will_alert": true,
"alert_recipients": [
"mona",
"lisa"
]
}
}Update a budget
Updates an existing budget for an enterprise. The authenticated user must be an enterprise admin, organization admin, or billing manager of the enterprise.
“Update a budget”的细粒度访问令牌
此终结点不适用于GitHub应用用户访问令牌、GitHub应用安装访问令牌或精细的个人访问令牌。
“”Update a budget 的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name |
budget_id string 必须The unique identifier of the budget |
| 名称, 类型, 说明 | |||
|---|---|---|---|
budget_amount integer The budget amount in whole dollars. For license-based products, this represents the number of licenses. | |||
prevent_further_usage boolean Whether to prevent additional spending once the budget is exceeded. For budgets with | |||
budget_alerting object | |||
Properties of |
| 名称, 类型, 说明 |
|---|
will_alert boolean Whether alerts are enabled for this budget |
alert_recipients array of strings Array of user login names who will receive alerts |
budget_scope string The scope of the budget.
enterprise: Apply the budget to the entire enterprise.organization: Apply the budget to a specific organization in the enterprise.repository: Apply the budget to a specific repository.cost_center: Apply the budget to a specific cost center.multi_user_customer: Apply a universal budget to all users in the enterprise.multi_user_cost_center: Apply a universal budget to all users in a cost center.user: Apply the budget to a single user.
可以是以下选项之一: enterprise, organization, repository, cost_center, multi_user_customer, multi_user_cost_center, user
budget_entity_name string The name of the entity to apply the budget to
budget_type string The type of pricing model used by the budget. Determines how budget_product_sku is interpreted.
BundlePricing: Covers all AI credit SKUs. Setbudget_product_skutoai_credits.ProductPricing: Covers all SKUs that belong to a product. Setbudget_product_skuto a product such asactionsorpackages.SkuPricing: Covers a single, specific SKU. Setbudget_product_skuto a SKU such asactions_linux.
budget_product_sku string A single product or SKU that will be covered in the budget
user string The username of the user for user scope budgets.
“Update a budget”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Budget updated successfully |
400 | Bad Request |
401 | Requires authentication |
403 | Forbidden |
404 | Budget not found or feature not enabled |
422 | Validation failed, or the endpoint has been spammed. |
500 | Internal server error |
503 | Service unavailable |
“Update a budget”的代码示例
如果你在 GHE.com 上访问 GitHub,请将 api.github.com 替换为企业的专用子域,位于 api.SUBDOMAIN.ghe.com。
请求示例
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/budgets/BUDGET_ID \
-d '{"prevent_further_usage":false,"budget_amount":10,"budget_alerting":{"will_alert":false,"alert_recipients":[]}}'Budget updated successfully
Status: 200{
"message": "Budget successfully updated.",
"budget": {
"id": "2066deda-923f-43f9-88d2-62395a28c0cdd",
"budget_type": "ProductPricing",
"budget_product_sku": "actions_linux",
"budget_scope": "repository",
"budget_entity_name": "org-name/example-repo-name",
"budget_amount": 10,
"prevent_further_usage": true,
"budget_alerting": {
"will_alert": true,
"alert_recipients": [
"mona",
"lisa"
]
}
}
}Delete a budget
Deletes a budget by ID. The authenticated user must be an enterprise admin.
“Delete a budget”的细粒度访问令牌
此终结点不适用于GitHub应用用户访问令牌、GitHub应用安装访问令牌或精细的个人访问令牌。
“”Delete a budget 的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name. |
budget_id string 必须The ID corresponding to the budget. |
“Delete a budget”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Response when deleting a budget |
400 | Bad Request |
403 | Forbidden |
404 | Resource not found |
500 | Internal Error |
503 | Service unavailable |
“Delete a budget”的代码示例
如果你在 GHE.com 上访问 GitHub,请将 api.github.com 替换为企业的专用子域,位于 api.SUBDOMAIN.ghe.com。
请求示例
curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/budgets/BUDGET_IDResponse when deleting a budget
Status: 200{
"message": "Budget successfully deleted.",
"budget_id": "2c1feb79-3947-4dc8-a16e-80cbd732cc0b"
}Get user states for a multi-user budget
Lists per-user budget state for a multi-user customer scoped budget. The authenticated actor must have permission to view enterprise billing.
“Get user states for a multi-user budget”的细粒度访问令牌
此端点支持以下精细令牌类型:
细粒度令牌必须具有以下权限集:
- "Enterprise billing" enterprise permissions (read)
“”Get user states for a multi-user budget 的参数
| 名称, 类型, 说明 |
|---|
accept string Setting to |
| 名称, 类型, 说明 |
|---|
enterprise string 必须The slug version of the enterprise name. |
budget_id string 必须The ID corresponding to the budget. |
| 名称, 类型, 说明 |
|---|
page integer The page number of results to fetch. |
per_page integer The number of results per page. |
sort_order string Sort order for results. 可以是以下选项之一: |
user string Filter user states to a specific user login. |
threshold_lower_bound integer Filter user states whose threshold percentage is at or above this value. |
threshold_upper_bound integer Filter user states whose threshold percentage is at or below this value. |
“Get user states for a multi-user budget”的 HTTP 响应状态代码
| 状态代码 | 说明 |
|---|---|
200 | Response when getting per-user states for a multi-user budget |
403 | Forbidden |
404 | Resource not found |
500 | Internal Error |
503 | Service unavailable |
“Get user states for a multi-user budget”的代码示例
如果你在 GHE.com 上访问 GitHub,请将 api.github.com 替换为企业的专用子域,位于 api.SUBDOMAIN.ghe.com。
请求示例
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/enterprises/ENTERPRISE/settings/billing/budgets/BUDGET_ID/user-statesResponse when getting per-user states for a multi-user budget
Status: 200{
"user_states": [
{
"user": "octocat",
"consumed_amount": 50.5,
"target_amount": 1000
},
{
"user": "monalisa",
"consumed_amount": 250,
"target_amount": 1000,
"override_budget_id": "2066deda-923f-43f9-88d2-62395a28c0cdd"
}
],
"has_next_page": false,
"total_count": 2
}