github-copilot
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub Copilot API
GitHub Copilot API
Use the GitHub Copilot REST API via direct calls to manage Copilot subscriptions and retrieve usage metrics for your organization.
curlOfficial docs:https://docs.github.com/en/rest/copilot
Note: This API is for managing Copilot subscriptions and viewing metrics, not for code generation.
你可以直接通过调用GitHub Copilot REST API,为你的组织管理Copilot订阅、获取使用指标。
curl官方文档:https://docs.github.com/en/rest/copilot
注意: 该API用于管理Copilot订阅和查看指标,不具备代码生成能力。
When to Use
使用场景
Use this skill when you need to:
- Manage Copilot seat assignments (add/remove users and teams)
- View Copilot billing information for an organization
- Retrieve usage metrics (active users, code completions, chat usage)
- Monitor Copilot adoption across teams
- Audit Copilot usage for compliance
当你需要完成以下操作时可使用该技能:
- 管理Copilot席位分配(添加/移除用户和团队)
- 查看组织的Copilot账单信息
- 获取使用指标(活跃用户、代码补全、聊天使用量)
- 监控Copilot在各团队的采纳情况
- 审核Copilot使用情况以满足合规要求
Prerequisites
前置要求
- You need a GitHub organization with Copilot Business or Enterprise
- Generate a Personal Access Token (PAT) or use a GitHub App
- Required permissions: or
manage_billing:copilotadmin:org - Store your token in the environment variable
GITHUB_TOKEN
bash
export GITHUB_TOKEN="ghp_xxxxxxxxxxxx"- 你需要有开通了Copilot Business或Enterprise的GitHub组织
- 生成个人访问令牌(PAT)或使用GitHub App
- 所需权限:或
manage_billing:copilotadmin:org - 将你的令牌存储在环境变量中
GITHUB_TOKEN
bash
export GITHUB_TOKEN="ghp_xxxxxxxxxxxx"Token Permissions
令牌权限
- - For billing and seat management
manage_billing:copilot - - For reading organization data
read:org - - For adding/removing users and teams
admin:org
Important: When usingin a command that pipes to another command, wrap the command containing$VARin$VAR. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"'
- - 用于账单和席位管理
manage_billing:copilot - - 用于读取组织数据
read:org - - 用于添加/移除用户和团队
admin:org
重要提示: 如果你在需要管道传输到其他命令的指令中使用,请将包含$VAR的命令包裹在$VAR中。由于Claude Code存在漏洞,直接使用管道时环境变量会被静默清除。bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"'
How to Use
使用方法
All examples below assume you have set.
GITHUB_TOKENBase URL:
https://api.github.comRequired headers:
Authorization: Bearer ${GITHUB_TOKEN}Accept: application/vnd.github+jsonX-GitHub-Api-Version: 2022-11-28
以下所有示例都假设你已经设置了。
GITHUB_TOKEN基础URL:
https://api.github.com必填请求头:
Authorization: Bearer ${GITHUB_TOKEN}Accept: application/vnd.github+jsonX-GitHub-Api-Version: 2022-11-28
1. Get Copilot Billing Information
1. 获取Copilot账单信息
Get seat breakdown and settings for an organization. Replace with your organization name:
your-org-namebash
bash -c 'curl -s -X GET "https://api.github.com/orgs/your-org-name/copilot/billing" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28"'Response:
json
{
"seat_breakdown": {
"total": 12,
"added_this_cycle": 2,
"pending_cancellation": 0,
"pending_invitation": 1,
"active_this_cycle": 12,
"inactive_this_cycle": 0
},
"seat_management_setting": "assign_selected",
"public_code_suggestions": "block"
}获取组织的席位明细和设置。将替换为你的组织名称:
your-org-namebash
bash -c 'curl -s -X GET "https://api.github.com/orgs/your-org-name/copilot/billing" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28"'响应示例:
json
{
"seat_breakdown": {
"total": 12,
"added_this_cycle": 2,
"pending_cancellation": 0,
"pending_invitation": 1,
"active_this_cycle": 12,
"inactive_this_cycle": 0
},
"seat_management_setting": "assign_selected",
"public_code_suggestions": "block"
}2. List All Copilot Seat Assignments
2. 列出所有Copilot席位分配情况
Get all users with Copilot seats. Replace with your organization name:
your-org-namebash
bash -c 'curl -s -X GET "https://api.github.com/orgs/your-org-name/copilot/billing/seats?per_page=50" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28"' | jq '.seats[] | {login: .assignee.login, last_activity: .last_activity_at}'获取所有拥有Copilot席位的用户。将替换为你的组织名称:
your-org-namebash
bash -c 'curl -s -X GET "https://api.github.com/orgs/your-org-name/copilot/billing/seats?per_page=50" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28"' | jq '.seats[] | {login: .assignee.login, last_activity: .last_activity_at}'3. Get Copilot Seat Details for a User
3. 获取单个用户的Copilot席位详情
Get specific user's Copilot seat information. Replace with your organization name and with the target username:
your-org-nameusernamebash
bash -c 'curl -s -X GET "https://api.github.com/orgs/your-org-name/members/username/copilot" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28"'获取指定用户的Copilot席位信息。将替换为你的组织名称,替换为目标用户名:
your-org-nameusernamebash
bash -c 'curl -s -X GET "https://api.github.com/orgs/your-org-name/members/username/copilot" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28"'4. Add Users to Copilot Subscription
4. 为用户添加Copilot订阅
Assign Copilot seats to specific users. Replace with your organization name:
your-org-nameWrite to :
/tmp/github_copilot_request.jsonjson
{
"selected_usernames": ["user1", "user2"]
}Then run:
bash
bash -c 'curl -s -X POST "https://api.github.com/orgs/your-org-name/copilot/billing/selected_users" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28" --header "Content-Type: application/json" -d @/tmp/github_copilot_request.json'Response:
json
{
"seats_created": 2
}为指定用户分配Copilot席位。将替换为你的组织名称:
your-org-name写入内容到:
/tmp/github_copilot_request.jsonjson
{
"selected_usernames": ["user1", "user2"]
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.github.com/orgs/your-org-name/copilot/billing/selected_users" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28" --header "Content-Type: application/json" -d @/tmp/github_copilot_request.json'响应示例:
json
{
"seats_created": 2
}5. Remove Users from Copilot Subscription
5. 移除用户的Copilot订阅
Remove Copilot seats from specific users. Replace with your organization name:
your-org-nameWrite to :
/tmp/github_copilot_request.jsonjson
{
"selected_usernames": ["user1", "user2"]
}Then run:
bash
bash -c 'curl -s -X DELETE "https://api.github.com/orgs/your-org-name/copilot/billing/selected_users" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28" --header "Content-Type: application/json" -d @/tmp/github_copilot_request.json'Response:
json
{
"seats_cancelled": 2
}收回指定用户的Copilot席位。将替换为你的组织名称:
your-org-name写入内容到:
/tmp/github_copilot_request.jsonjson
{
"selected_usernames": ["user1", "user2"]
}然后运行:
bash
bash -c 'curl -s -X DELETE "https://api.github.com/orgs/your-org-name/copilot/billing/selected_users" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28" --header "Content-Type: application/json" -d @/tmp/github_copilot_request.json'响应示例:
json
{
"seats_cancelled": 2
}6. Add Teams to Copilot Subscription
6. 为团队添加Copilot订阅
Assign Copilot to entire teams. Replace with your organization name:
your-org-nameWrite to :
/tmp/github_copilot_request.jsonjson
{
"selected_teams": ["engineering", "design"]
}Then run:
bash
bash -c 'curl -s -X POST "https://api.github.com/orgs/your-org-name/copilot/billing/selected_teams" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28" --header "Content-Type: application/json" -d @/tmp/github_copilot_request.json'为整个团队分配Copilot权限。将替换为你的组织名称:
your-org-name写入内容到:
/tmp/github_copilot_request.jsonjson
{
"selected_teams": ["engineering", "design"]
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.github.com/orgs/your-org-name/copilot/billing/selected_teams" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28" --header "Content-Type: application/json" -d @/tmp/github_copilot_request.json'7. Remove Teams from Copilot Subscription
7. 移除团队的Copilot订阅
Remove Copilot from teams. Replace with your organization name:
your-org-nameWrite to :
/tmp/github_copilot_request.jsonjson
{
"selected_teams": ["engineering"]
}Then run:
bash
bash -c 'curl -s -X DELETE "https://api.github.com/orgs/your-org-name/copilot/billing/selected_teams" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28" --header "Content-Type: application/json" -d @/tmp/github_copilot_request.json'收回整个团队的Copilot权限。将替换为你的组织名称:
your-org-name写入内容到:
/tmp/github_copilot_request.jsonjson
{
"selected_teams": ["engineering"]
}然后运行:
bash
bash -c 'curl -s -X DELETE "https://api.github.com/orgs/your-org-name/copilot/billing/selected_teams" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28" --header "Content-Type: application/json" -d @/tmp/github_copilot_request.json'8. Get Copilot Usage Metrics for Organization
8. 获取组织的Copilot使用指标
Get usage statistics (requires 5+ active users). Replace with your organization name:
your-org-namebash
bash -c 'curl -s -X GET "https://api.github.com/orgs/your-org-name/copilot/metrics?per_page=7" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28"' | jq '.[] | {date, total_active_users, total_engaged_users}'Response:
json
{
"date": "2024-06-24",
"total_active_users": 24,
"total_engaged_users": 20
}获取使用统计数据(需要≥5名活跃用户)。将替换为你的组织名称:
your-org-namebash
bash -c 'curl -s -X GET "https://api.github.com/orgs/your-org-name/copilot/metrics?per_page=7" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28"' | jq '.[] | {date, total_active_users, total_engaged_users}'响应示例:
json
{
"date": "2024-06-24",
"total_active_users": 24,
"total_engaged_users": 20
}9. Get Copilot Metrics for a Team
9. 获取单个团队的Copilot指标
Get team-specific usage metrics. Replace with your organization name and with the target team:
your-org-nameteam-namebash
bash -c 'curl -s -X GET "https://api.github.com/orgs/your-org-name/team/team-name/copilot/metrics" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28"'获取指定团队的使用指标。将替换为你的组织名称,替换为目标团队名称:
your-org-nameteam-namebash
bash -c 'curl -s -X GET "https://api.github.com/orgs/your-org-name/team/team-name/copilot/metrics" --header "Authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28"'Metrics Data Structure
指标数据结构
The metrics response includes:
| Field | Description |
|---|---|
| Users with Copilot activity |
| Users who accepted suggestions |
| Code completion stats by language/editor |
| IDE chat usage stats |
| GitHub.com chat usage |
| PR summary usage |
指标响应包含以下字段:
| 字段 | 描述 |
|---|---|
| 有Copilot活动记录的用户 |
| 接受了补全建议的用户 |
| 按语言/编辑器统计的代码补全数据 |
| IDE聊天功能的使用统计 |
| GitHub.com聊天功能的使用情况 |
| PR摘要功能的使用情况 |
Guidelines
使用规范
- Requires Copilot Business/Enterprise: Free tier users cannot use this API
- Metrics need 5+ users: Usage metrics only available with 5+ active Copilot users
- Data retention: Metrics available for up to 100 days
- Rate limits: Standard GitHub API rate limits apply
- API in preview: Some endpoints may change
- 需要Copilot Business/Enterprise版本:免费版用户无法使用该API
- 指标要求5名以上用户:只有当活跃Copilot用户数≥5时才可查看使用指标
- 数据保留期:指标最多保留100天
- 速率限制:遵循GitHub API标准速率限制
- API处于预览阶段:部分端点可能会变动