{"meta":{"title":"成本中心","intro":"使用 REST API 获取成本中心信息。","product":"REST API","breadcrumbs":[{"href":"/zh/enterprise-cloud@latest/rest","title":"REST API"},{"href":"/zh/enterprise-cloud@latest/rest/billing","title":"计费"},{"href":"/zh/enterprise-cloud@latest/rest/billing/cost-centers","title":"成本中心"}],"documentType":"article"},"body":"# 成本中心\n\n使用 REST API 获取成本中心信息。\n\n## 必需的角色\n\n以下角色可以访问成本中心 API 终结点：\n\n* **企业所有者**\n* **计费经理**\n* **组织所有者**\n\n> [!NOTE]\n> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2026-03-10`. Curl examples below omit these standard headers for brevity.\n\n## Get all cost centers for an enterprise\n\n```\nGET /enterprises/{enterprise}/settings/billing/cost-centers\n```\n\nGets a list of all the cost centers for an enterprise. Enterprise owners and billing managers can view all cost centers, and organization owners can view cost centers associated with resources they administer. A custom role holder with fine-grained read access to enterprise billing can also view cost centers. An installation access token for a GitHub App installed on the enterprise with read access to enterprise billing can list all cost centers in the enterprise.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`enterprise`** (string) (required)\n  The slug version of the enterprise name.\n\n- **`state`** (string)\n  Set to active or deleted to only list cost centers in a specific state.\n  Can be one of: `active`, `deleted`\n\n### HTTP response status codes\n\n- **200** - Response when getting cost centers\n\n- **400** - Bad Request\n\n- **403** - Forbidden\n\n- **500** - Internal Error\n\n- **503** - Service unavailable\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers\n```\n\n**Response schema (Status: 200):**\n\n* `costCenters`: array of objects:\n  * `id`: required, string\n  * `name`: required, string\n  * `state`: string, enum: `active`, `deleted`\n  * `azure_subscription`: string or null\n  * `ai_credit_pool_enabled`: boolean\n  * `ai_credit_pool_state`: object:\n    * `target_amount`: number or null\n    * `current_amount`: number or null\n  * `resources`: required, array of objects:\n    * `type`: required, string\n    * `name`: required, string\n\n## Create a new cost center\n\n```\nPOST /enterprises/{enterprise}/settings/billing/cost-centers\n```\n\nCreates a new cost center for an enterprise. Enterprise owners and billing managers can create cost centers. A custom role holder with fine-grained write access to enterprise billing can also create cost centers. An installation access token for a GitHub App installed on the enterprise with write access to enterprise billing can create cost centers in the enterprise.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`enterprise`** (string) (required)\n  The slug version of the enterprise name.\n\n#### Body parameters\n\n- **`name`** (string) (required)\n  The name of the cost center (max length 255 characters)\n\n- **`ai_credit_pool_enabled`** (boolean)\n  Whether the cost center draws from the AI credit pool.\nThis can only be enabled for cost centers that contain only user or team resources.\n\nfalse — no cap; the cost center draws from the shared enterprise pool.\ntrue — the cost center is capped at an amount derived from its members' license entitlements.\n\n### HTTP response status codes\n\n- **200** - Cost center created successfully\n\n- **400** - Bad request\n\n- **409** - Conflict\n\n- **500** - Internal server error\n\n### Code examples\n\n#### Example request to create a cost center\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers \\\n  -d '{\n  \"name\": \"Engineering Team\"\n}'\n```\n\n**Response schema (Status: 200):**\n\n* `id`: string\n* `name`: string\n* `azure_subscription`: string or null\n* `state`: string, enum: `active`, `deleted`\n* `resources`: array of objects:\n  * `type`: string\n  * `name`: string\n* `ai_credit_pool_enabled`: boolean\n* `ai_credit_pool_state`: object:\n  * `target_amount`: number or null\n  * `current_amount`: number or null\n\n## Get a cost center by ID\n\n```\nGET /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}\n```\n\nGets a cost center by ID. Enterprise owners and billing managers can view any cost center, and organization owners can view cost centers associated with resources they administer. A custom role holder with fine-grained read access to enterprise billing can also view the cost center. An installation access token for a GitHub App installed on the enterprise with read access to enterprise billing can get any cost center in the enterprise.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`enterprise`** (string) (required)\n  The slug version of the enterprise name.\n\n- **`cost_center_id`** (string) (required)\n  The ID corresponding to the cost center.\n\n- **`page`** (integer)\n  The page number of the results to fetch. For more information, see \"Using pagination in the REST API.\"\n  Default: `1`\n\n- **`per_page`** (integer)\n  The number of results per page (max 100). For more information, see \"Using pagination in the REST API.\"\n  Default: `30`\n\n### HTTP response status codes\n\n- **200** - Response when getting a cost center\n\n- **400** - Bad Request\n\n- **403** - Forbidden\n\n- **500** - Internal Error\n\n- **503** - Service unavailable\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_ID\n```\n\n**Response schema (Status: 200):**\n\n* `id`: required, string\n* `name`: required, string\n* `azure_subscription`: string or null\n* `state`: string, enum: `active`, `deleted`\n* `resources`: required, array of objects:\n  * `type`: required, string\n  * `name`: required, string\n* `has_next_page`: boolean\n* `ai_credit_pool_enabled`: boolean\n* `ai_credit_pool_state`: object:\n  * `target_amount`: number or null\n  * `current_amount`: number or null\n\n## Update a cost center\n\n```\nPATCH /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}\n```\n\nUpdates an existing cost center. Enterprise owners and billing managers can update any cost center, and organization owners can update cost centers associated with resources they administer. A custom role holder with fine-grained write access to enterprise billing can also update cost centers. An installation access token for a GitHub App installed on the enterprise with write access to enterprise billing can update any cost center in the enterprise.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`enterprise`** (string) (required)\n  The slug version of the enterprise name\n\n- **`cost_center_id`** (string) (required)\n  The unique identifier of the cost center\n\n#### Body parameters\n\n- **`name`** (string)\n  The new name for the cost center\n\n- **`ai_credit_pool_enabled`** (boolean)\n  Whether the cost center draws from the AI credit pool.\nThis can only be enabled for cost centers that contain only user or team resources.\n\nfalse — no cap; the cost center draws from the shared enterprise pool.\ntrue — the cost center is capped at an amount derived from its members' license entitlements.\n\n### HTTP response status codes\n\n- **200** - Response when updating a cost center\n\n- **400** - Bad Request\n\n- **403** - Forbidden\n\n- **404** - Resource not found\n\n- **409** - Conflict\n\n- **422** - Validation failed, or the endpoint has been spammed.\n\n- **500** - Internal Error\n\n- **503** - Service unavailable\n\n### Code examples\n\n#### Update cost center name example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PATCH \\\n  https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_ID \\\n  -d '{\n  \"name\": \"New Cost Center Name\"\n}'\n```\n\n**Response schema (Status: 200):**\n\n* `id`: required, string\n* `name`: required, string\n* `azure_subscription`: string or null\n* `state`: string, enum: `active`, `deleted`\n* `resources`: required, array of objects:\n  * `type`: required, string\n  * `name`: required, string\n* `ai_credit_pool_enabled`: boolean\n* `ai_credit_pool_state`: object:\n  * `target_amount`: number or null\n  * `current_amount`: number or null\n\n#### Update cost center with AI credit pool enabled\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PATCH \\\n  https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_ID \\\n  -d '{\n  \"ai_credit_pool_enabled\": true\n}'\n```\n\n**Response schema (Status: 200):**\n\n* `id`: required, string\n* `name`: required, string\n* `azure_subscription`: string or null\n* `state`: string, enum: `active`, `deleted`\n* `resources`: required, array of objects:\n  * `type`: required, string\n  * `name`: required, string\n* `ai_credit_pool_enabled`: boolean\n* `ai_credit_pool_state`: object:\n  * `target_amount`: number or null\n  * `current_amount`: number or null\n\n## Delete a cost center\n\n```\nDELETE /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}\n```\n\nArchives a cost center by ID. Enterprise owners and billing managers can archive any cost center, and organization owners can archive cost centers associated with resources they administer. A custom role holder with fine-grained write access to enterprise billing can also archive cost centers. An installation access token for a GitHub App installed on the enterprise with write access to enterprise billing can archive any cost center in the enterprise.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`enterprise`** (string) (required)\n  The slug version of the enterprise name.\n\n- **`cost_center_id`** (string) (required)\n  The ID corresponding to the cost center.\n\n### HTTP response status codes\n\n- **200** - Response when deleting a cost center\n\n- **400** - Bad Request\n\n- **403** - Forbidden\n\n- **404** - Resource not found\n\n- **500** - Internal Error\n\n- **503** - Service unavailable\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_ID\n```\n\n**Response schema (Status: 200):**\n\n* `message`: required, string\n* `id`: required, string\n* `name`: required, string\n* `costCenterState`: required, string, enum: `CostCenterArchived`\n\n## Add resources to a cost center\n\n```\nPOST /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}/resource\n```\n\nAdds resources to a cost center.\nThe usage for the resources will be charged to the cost center's budget. Enterprise owners and billing managers can add any resource, and organization owners can add non-team resources to cost centers associated with resources they administer. A custom role holder with fine-grained write access to enterprise billing can add users in the enterprise who are visible to them and organizations or repositories they administer, but cannot add enterprise teams. An installation access token for a GitHub App installed on the enterprise with write access to enterprise billing can add resources to any cost center in the enterprise.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`enterprise`** (string) (required)\n  The slug version of the enterprise name.\n\n- **`cost_center_id`** (string) (required)\n  The ID corresponding to the cost center.\n\n#### Body parameters\n\n- **`users`** (array of strings)\n  The usernames of the users to add to the cost center.\n\n- **`organizations`** (array of strings)\n  The organizations to add to the cost center.\n\n- **`repositories`** (array of strings)\n  The repositories to add to the cost center.\n\n- **`enterprise_teams`** (array of strings)\n  The enterprise teams to add to the cost center.\n\n### HTTP response status codes\n\n- **200** - Response when adding resources to a cost center\n\n- **400** - Bad Request\n\n- **403** - Forbidden\n\n- **409** - Conflict\n\n- **500** - Internal Error\n\n- **503** - Service unavailable\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_ID/resource \\\n  -d '{\n  \"users\": [\n    \"monalisa\"\n  ]\n}'\n```\n\n**Response schema (Status: 200):**\n\n* `message`: string\n* `reassigned_resources`: array of objects or null:\n  * `resource_type`: string\n  * `name`: string\n  * `previous_cost_center`: string\n\n## Remove resources from a cost center\n\n```\nDELETE /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}/resource\n```\n\nRemove resources from a cost center.\nThe usage for the resources will no longer be charged to the cost center's budget. Enterprise owners and billing managers can remove any resource, and organization owners can remove non-team resources from cost centers associated with resources they administer. A custom role holder with fine-grained write access to enterprise billing can remove users and any organizations or repositories they administer; only enterprise owners and billing managers can remove enterprise teams. An installation access token for a GitHub App installed on the enterprise with write access to enterprise billing can remove users from any cost center in the enterprise.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`enterprise`** (string) (required)\n  The slug version of the enterprise name.\n\n- **`cost_center_id`** (string) (required)\n  The ID corresponding to the cost center.\n\n#### Body parameters\n\n- **`users`** (array of strings)\n  The usernames of the users to remove from the cost center.\n\n- **`organizations`** (array of strings)\n  The organizations to remove from the cost center.\n\n- **`repositories`** (array of strings)\n  The repositories to remove from the cost center.\n\n- **`enterprise_teams`** (array of strings)\n  The enterprise teams to remove from the cost center.\n\n### HTTP response status codes\n\n- **200** - Response when removing resources from a cost center\n\n- **400** - Bad Request\n\n- **403** - Forbidden\n\n- **500** - Internal Error\n\n- **503** - Service unavailable\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  https://api.github.com/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_ID/resource \\\n  -d '{\n  \"users\": [\n    \"monalisa\"\n  ]\n}'\n```\n\n**Response schema (Status: 200):**\n\n* `message`: string"}