GitHub v3 REST API
GitHub v3 REST API
GitHub REST API v3,覆盖仓库、issue、PR、Actions、Packages 等所有 GitHub.com 资源的程序化访问。
REST 与 GraphQL 双 API,按场景选最合适
未认证速率仅 60/h,认证后 5000/h,仍是常被卡点
生成 personal access token(推荐 Fine-grained)或注册 GitHub App。用 Authorization: Bearer <token>(PAT)或 token <token> 都可。所有请求加 Accept: application/vnd.github+json 与 X-GitHub-Api-Version 头。复杂查询考虑用 GraphQL。
可用率 · 30 天窗口
关于这个 API
GitHub REST API 是与 GitHub.com 进行程序化交互的核心接口,几乎所有 UI 上能做的事都能通过 API 完成:创建仓库、操作 issue 和 PR、读写文件、触发 Actions、管理团队权限。它和 GitHub GraphQL API 并行存在——REST 适合简单直观的 CRUD,GraphQL 适合一次查询多种关联数据,避免 REST 的 N+1 问题。
认证有 PAT(personal access token,分 classic 与 fine-grained)、GitHub App、OAuth App、Actions workflow 内置 GITHUB_TOKEN 几种。Fine-grained PAT 是近年推出的更安全选项,能精确到单个仓库与最小操作集,强烈建议用于服务端集成。GitHub App 进一步引入安装级别隔离,适合发布给多个组织使用。
速率限制是常见痛点:匿名访问 60/h,认证后 5000/h,secondary rate limit 还会针对突发流量额外限流。webhook 几乎覆盖所有仓库事件,配合 GitHub App 可以构建复杂的自动化流水线。GraphQL 查询有 cost 概念,过于复杂的嵌套查询可能因超出预算被拒。
你可以做什么
- 1搭建 CI/CD 与 GitHub Actions 自动化
- 2镜像 issue 到外部跟踪系统
- 3生成项目动态报表与活跃度看板
- 4为内部工具集成代码搜索与文件读取
- 5编写 GitHub App 与 marketplace 集成
优劣对比
优点
- REST 与 GraphQL 双 API,按场景选最合适
- Fine-grained personal access tokens 让权限精细可控
- webhook 事件覆盖几乎所有仓库行为
- 官方 Octokit SDK 在所有主流语言都有
注意事项
- 未认证速率仅 60/h,认证后 5000/h,仍是常被卡点
- GraphQL 查询有 cost 上限,复杂查询可能被拒
- 部分企业功能需 Enterprise plan
示例请求
curl https://support.github.com/contact?tags=dotcom-rest-api/<endpoint> \
-H "Authorization: Bearer $ACCESS_TOKEN"快速开始
生成 personal access token(推荐 Fine-grained)或注册 GitHub App。用 Authorization: Bearer <token>(PAT)或 token <token> 都可。所有请求加 Accept: application/vnd.github+json 与 X-GitHub-Api-Version 头。复杂查询考虑用 GraphQL。
常见问题
API 调用免费吗?+
认证用户免费且配额 5000/h;GitHub Enterprise 客户限额更高。GraphQL 按 query cost 计算。
PAT 和 GitHub App 该选哪个?+
自家小工具 PAT 即可;要发布给别人安装或需要更细粒度的安装级隔离,选 GitHub App。
速率被限了怎么办?+
检查 X-RateLimit-Remaining 头与 X-RateLimit-Reset。被限时等到 reset 时间或换 GitHub App 提升配额。
REST 与 GraphQL 数据一致吗?+
资源模型大体一致但接口形态不同。某些预览特性可能先在某一边出现。
技术细节
- 认证方式
- oauth
- 计费
- freemium
- 协议
- REST, GraphQL
- SDK
- javascript, typescript, python, go, ruby, java, csharp
- 响应时间
- 78 ms
- 上次巡检
- 2026/5/12 07:37:29
接口端点
从 OpenAPI spec 自动解析。显示 12 / 629 个未弃用端点。
/metaGitHub API Root
/admin/hooksenterprise-adminList global webhooks
/admin/hooksenterprise-adminCreate a global webhook
/admin/hooks/{hook_id}enterprise-adminDelete a global webhook
/admin/hooks/{hook_id}enterprise-adminGet a global webhook
/admin/hooks/{hook_id}enterprise-adminUpdate a global webhook
/admin/hooks/{hook_id}/pingsenterprise-adminPing a global webhook
/admin/keysenterprise-adminList public keys
/admin/keys/{key_ids}enterprise-adminDelete a public key
/admin/organizationsenterprise-adminCreate an organization
/admin/organizations/{org}enterprise-adminUpdate an organization name
/admin/pre-receive-environmentsenterprise-adminList pre-receive environments
另有 617 个端点未显示,详见 OpenAPI spec。
更多来自 GitHub 的 API
可以替代的选择
不同公司、解决相似问题的备选。按分类、认证、计费档位与标签重合度匹配。