原文标题: github copilot-sdk
GitHub Copilot CLI SDK
为每个应用打造的智能代理。通过 GitHub Copilot SDK(支持 Python、TypeScript、Go、.NET、Java 和 Rust),将 Copilot 的代理工作流嵌入你的应用程序。GitHub Copilot SDK 暴露了与 Copilot CLI 相同的底层引擎:一个经过生产测试的代理运行时,你可以通过编程方式调用它。无需自行构建编排——你定义代理行为,Copilot 负责规划、工具调用、文件编辑等任务。
可用 SDK
| SDK | 位置 | 食谱 | 安装 | API 文档 | | --- | --- | --- | --- | --- | | Node.js / TypeScript | nodejs/ | 食谱 | npm install @github/copilot-sdk | API 文档 | | Python | python/ | 食谱 | pip install github-copilot-sdk | | | Go | go/ | 食谱 | go get github.com/github/copilot-sdk/go | API 文档 | | .NET | dotnet/ | 食谱 | dotnet add package GitHub.Copilot.SDK | | | Rust | rust/ | — | cargo add github-copilot-sdk | API 文档 | | Java | java/ | 食谱 | Maven 坐标 com.github:copilot-sdk-java(参见 Maven 和 Gradle 的安装说明) | API 文档 |
请参阅各个 SDK 的 README 文件,了解安装、使用示例和 API 参考。
快速入门
有关完整教程,请参阅[快速入门指南](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli)。
快速步骤:
- (可选)安装 Copilot CLI
- 使用上述命令安装你偏好的 SDK。
- 请参阅 SDK README 了解使用示例和 API 文档。
- 对于 Node.js、Python 和 .NET SDK,Copilot CLI 会自动捆绑,无需单独安装。
- 对于 Go、Java 和 Rust SDK,请手动安装 CLI,或确保
copilot在你的 PATH 中可用。Go 和 Rust 也提供了应用级别的 CLI 捆绑功能。
架构
所有 SDK 通过 JSON-RPC 与 Copilot CLI 服务器通信:
你的应用程序
↓
SDK 客户端
↓
JSON-RPC
Copilot CLI(服务器模式)
SDK 会自动管理 CLI 进程的生命周期。你也可以连接到外部 CLI 服务器——有关在服务器模式下运行 CLI 的详细信息,请参阅[快速入门指南](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli)。
常见问题
使用 SDK 是否需要 GitHub Copilot 订阅? 是的,使用 GitHub Copilot SDK 需要 GitHub Copilot 订阅,除非你使用 BYOK(自带密钥)。使用 BYOK 时,你可以通过配置来自受支持 LLM 提供商的 API 密钥,无需 GitHub 身份验证即可使用 SDK。对于标准使用(非 BYOK),请参阅 [GitHub Copilot 定价页面](https://github.com/features/copilot/plans),其中包含有限使用的免费套餐。
SDK 使用如何计费? GitHub Copilot SDK 的计费模式与 Copilot CLI 相同,每次提示都会计入你的使用配额。有关 Copilot 使用计费的更多信息,请参阅 [GitHub Copilot 中的使用](https://docs.github.com/en/billing/managing-billing-for-github-copilot/about-billing-for-github-copilot)。
是否支持 BYOK(自带密钥)? 是的,GitHub Copilot SDK 支持 BYOK(自带密钥)。你可以配置 SDK,使用来自受支持 LLM 提供商(例如 OpenAI、Azure AI Foundry、Anthropic)的 API 密钥,通过这些提供商访问模型。请参阅 [BYOK 文档](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli#using-byok)了解设置说明和示例。注意:BYOK 仅支持基于密钥的身份验证。不支持 Microsoft Entra ID(Azure AD)、托管标识和第三方身份提供商。
支持哪些身份验证方法? SDK 支持多种身份验证方法:
- GitHub 已登录用户 - 使用
copilot CLI login存储的 OAuth 凭据 - OAuth GitHub 应用 - 从你的 GitHub OAuth 应用传递用户令牌
- 环境变量 -
COPILOT_GITHUB_TOKEN、GH_TOKEN、GITHUB_TOKEN - BYOK - 使用你自己的 API 密钥(无需 GitHub 身份验证)
有关每种方法的详细信息,请参阅[身份验证文档](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli#authentication)。
是否需要单独安装 Copilot CLI? 不需要——对于 Node.js、Python 和 .NET SDK,Copilot CLI 会自动作为依赖项捆绑。你无需单独安装。对于 Go、Java 和 Rust SDK,CLI 默认不捆绑。请手动安装 CLI,或确保 copilot 在你的 PATH 中可用。Go 和 Rust 也提供了应用级别的 CLI 捆绑功能。高级:你可以覆盖 CLI 二进制文件或连接到外部服务器。请参阅各个 SDK README 了解特定语言的选项。
默认启用了哪些工具? 默认情况下,SDK 暴露 Copilot CLI 的第一方工具,类似于使用 --allow-all 运行 CLI。工具执行仍受每个 SDK 的权限处理程序控制,因此应用程序可以批准、拒绝或自定义工具调用。你可以通过配置 SDK 客户端选项来启用和禁用特定工具,从而自定义工具的可用性。有关工具配置的详细信息,请参阅各个 SDK 文档,有关可用工具列表,请参阅 [Copilot CLI 文档](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli)。
能否使用自定义代理、技能或工具? 是的,GitHub Copilot SDK 允许你定义自定义代理、技能和工具。你可以通过实现自己的逻辑并根据需要集成其他工具来扩展代理的功能。有关更多详细信息,请参阅你偏好的语言的 SDK 文档。
是否有用于加速开发的 Copilot 自定义指令或 SDK 指南? 是的,请查看自定义指令和特定于 SDK 的指南:
- [Node.js / TypeScript](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli#custom-instructions)
- [Python](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli#custom-instructions)
- [.NET](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli#custom-instructions)
- [Go](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli#custom-instructions)
- [Rust](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli#custom-instructions)(SDK 指南;自定义指令尚未发布)
- [Java](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli#custom-instructions)
支持哪些模型? SDK 支持 Copilot CLI 可用的所有模型。SDK 还暴露了一个方法,可以返回可用模型,以便在运行时访问。
SDK 是否可用于生产环境? GitHub Copilot SDK 已正式发布,并遵循语义化版本控制。请参阅 [CHANGELOG.md](https://github.com/github/copilot-sdk/blob/main/CHANGELOG.md) 了解发布说明。
如何报告问题或请求功能? 请使用 [GitHub Issues 页面](https://github.com/github/copilot-sdk/issues)报告错误或请求新功能。我们欢迎你的反馈,以帮助改进 SDK。
快速链接
- [文档](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli) – 完整文档索引
- [快速入门](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli) – 上手教程
- [设置指南](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli) – 架构、部署和扩展
- [身份验证](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli) – GitHub OAuth、BYOK 等
- [功能](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli) – 钩子、自定义代理、MCP、技能等
- [故障排除](https://docs.github.com/en/copilot/using-github-copilot/using-github-copilot-cli) – 常见问题及解决方案
- [食谱](https://github.com/github/copilot-sdk/tree/main/cookbook) – 所有语言的常见任务实用示例
- [更多资源](https://github.com/github/copilot-sdk) – 其他示例、教程和社区