참고
코필로트 SDK가 현재 기술 미리 보기에 있습니다. 기능 및 가용성은 변경될 수 있습니다.
GitHub Copilot SDK 로컬로 로그인한 CLI에 연결하는 것이 가장 빠른 시작 방법입니다.
**최적 대상:** 개인 프로젝트, 프로토타입 생성, 로컬 개발 및 SDK 학습
작동 방식
설치 코파일럿 CLI 하고 로그인하면 자격 증명이 시스템 키 집합에 저장됩니다. SDK는 자동으로 CLI를 자식 프로세스로 시작하고 저장된 자격 증명을 사용합니다. 주요 특징:
- CLI는 SDK에 의해 자동으로 생성되며 설치가 필요하지 않습니다.
- 인증은 시스템 키 집합에서 로그인한 사용자의 자격 증명을 사용합니다.
- stdio(stdin/stdout)를 통해 통신이 수행되며 네트워크 포트가 열리지 않습니다.
- 세션은 컴퓨터에 로컬입니다.
빠른 시작
기본 구성에는 옵션이 전혀 필요하지 않습니다.
Node.js/ TypeScript
import { CopilotClient } from "@github/copilot-sdk";
const client = new CopilotClient();
const session = await client.createSession({ model: "gpt-4.1" });
const response = await session.sendAndWait({ prompt: "Hello!" });
console.log(response?.data.content);
await client.stop();
파이썬
from copilot import CopilotClient, PermissionHandler
client = CopilotClient()
await client.start()
session = await client.create_session(on_permission_request=PermissionHandler.approve_all, model="gpt-4.1")
response = await session.send_and_wait({"prompt": "Hello!"})
print(response.data.content)
await client.stop()
이동
client := copilot.NewClient(nil)
if err := client.Start(ctx); err != nil {
log.Fatal(err)
}
defer client.Stop()
session, _ := client.CreateSession(ctx, &copilot.SessionConfig{Model: "gpt-4.1"})
response, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "Hello!"})
fmt.Println(*response.Data.Content)
.NET
await using var client = new CopilotClient();
await using var session = await client.CreateSessionAsync(
new SessionConfig { Model = "gpt-4.1" });
var response = await session.SendAndWaitAsync(
new MessageOptions { Prompt = "Hello!" });
Console.WriteLine(response?.Data.Content);
SDK는 CLI 시작, 인증 및 세션 관리 등 모든 것을 처리합니다.
내부적으로 어떻게 작동하나요?
구성 요소 간의 상호 작용 순서에 대한 자세한 내용은 github/copilot-sdk의 시퀀스 다이어그램을 참조하세요.
구성 옵션
기본값은 대부분의 경우 작동하지만 로컬 설정을 사용자 지정할 수 있습니다.
const client = new CopilotClient({
// Override CLI location (default: bundled with @github/copilot)
cliPath: "/usr/local/bin/copilot",
// Set log level for debugging
logLevel: "debug",
// Pass extra CLI arguments
cliArgs: ["--log-dir=/tmp/copilot-logs"],
// Set working directory
cwd: "/path/to/project",
});
환경 변수 사용
키 집합 대신 환경 변수를 통해 인증할 수 있습니다. 이는 CI 또는 대화형 로그인을 원하지 않는 경우에 유용합니다.
# Set one of these (in priority order):
export COPILOT_GITHUB_TOKEN="YOUR-GITHUB-TOKEN" # Recommended
export GH_TOKEN="YOUR-GITHUB-TOKEN" # GitHub CLI compatible
export GITHUB_TOKEN="YOUR-GITHUB-TOKEN" # GitHub Actions compatible
`YOUR-GITHUB-TOKEN`를 유효한 GitHub 또는 OAuth 토큰으로 personal access token 대체합니다. SDK는 이러한 기능을 자동으로 선택합니다. 코드 변경이 필요하지 않습니다.
세션 관리
로컬 CLI를 사용하면 세션은 기본적으로 임시 세션입니다. 다시 열 수 있는 세션을 만들려면 세션 ID를 제공합니다.
// Create a named session
const session = await client.createSession({
sessionId: "my-project-analysis",
model: "gpt-4.1",
});
// Resume it in a later run
const resumed = await client.resumeSession("my-project-analysis");
세션 상태는 사용자가 제공한 세션 ID가 있는 위치에 ~/.copilot/session-state/SESSION-ID/``SESSION-ID 로컬로 저장됩니다.
제한점
| Limitation | 세부 정보 |
|---|
**단일 사용자** | 자격 증명은 CLI에 로그인한 사용자와 연결됩니다. |
|
로컬 전용 | CLI는 앱과 동일한 컴퓨터에서 실행됩니다. |
|
다중 테넌트 없음 | 하나의 CLI 인스턴스에서 여러 사용자를 제공할 수 없습니다. |
|
CLI 로그인 필요 | 사용자가 먼저 실행하고 copilot 인증해야 합니다. |
다음 단계
- 앱을 다른 사용자에게 배송하려면 Copilot SDK와 함께 번들된 CLI 사용을 참조하세요.
- 여러 사용자가 자신의 GitHub 계정으로 로그인할 수 있도록 지원하려면 Copilot SDK와 함께 GitHub OAuth 사용을 참조하세요.
- 서버에서 SDK를 실행하려면 백 엔드 서비스에 대한 Copilot SDK 설정을 참조하세요.
- 첫 번째 메시지 및 설치는 Copilot SDK 사용 시작하기을 참조하세요.