사용 시기: 특정 CLI 버전을 고정하거나 Go SDK(CLI를 번들로 묶지 않음)로 작업해야 합니다.
작동 방식
기본적으로 Node.js, Python 및 .NET SDK에는 자체 CLI 종속성이 포함됩니다(기본 설정(번들 CLI) 참조). 예를 들어 시스템에 설치된 CLI를 사용하기 위해 이를 재정의해야 하는 경우, Connection 옵션을 사용할 수 있습니다.

주요 특징:
- CLI 바이너리 경로를 명시적으로 지정합니다.
- 사용자는 SDK와의 CLI 버전 호환성을 담당합니다.
- 인증은 시스템 키 집합(또는 env vars)에서 로그인한 사용자의 자격 증명을 사용합니다.
- stdio를 통한 통신 발생
구성 / 설정
로컬 CLI 바이너리 사용
TypeScript
import { CopilotClient } from "@github/copilot-sdk";
const client = new CopilotClient({
cliPath: "/usr/local/bin/copilot",
});
const session = await client.createSession({ model: "gpt-4.1" });
const response = await session.sendAndWait({ prompt: "Hello!" });
console.log(response?.data.content);
await client.stop();
Python
from copilot import CopilotClient
from copilot.generated.session_events import AssistantMessageData
from copilot.session import PermissionHandler
client = CopilotClient({
"cli_path": "/usr/local/bin/copilot",
})
await client.start()
session = await client.create_session(on_permission_request=PermissionHandler.approve_all, model="gpt-4.1")
response = await session.send_and_wait("Hello!")
if response:
match response.data:
case AssistantMessageData() as data:
print(data.content)
await client.stop()
Go
참고
Go SDK는 CLI를 번들로 묶지 않으므로 항상 제공해야 Connection합니다.
package main
import (
"context"
"fmt"
"log"
copilot "github.com/github/copilot-sdk/go"
)
func main() {
ctx := context.Background()
client := copilot.NewClient(&copilot.ClientOptions{
Connection: copilot.StdioConnection{Path: "/usr/local/bin/copilot"},
})
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!"})
if response != nil {
if d, ok := response.Data.(*copilot.AssistantMessageData); ok {
fmt.Println(d.Content)
}
}
}
client := copilot.NewClient(&copilot.ClientOptions{
Connection: copilot.StdioConnection{Path: "/usr/local/bin/copilot"},
})
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!"})
if response != nil {
if d, ok := response.Data.(*copilot.AssistantMessageData); ok {
fmt.Println(d.Content)
}
}
.NET
var client = new CopilotClient(new CopilotClientOptions
{
Connection = RuntimeConnection.ForStdio(path: "/usr/local/bin/copilot"),
});
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);
추가 옵션
const client = new CopilotClient({
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="gho_xxxx" # Recommended
export GH_TOKEN="gho_xxxx" # GitHub CLI compatible
export GITHUB_TOKEN="gho_xxxx" # GitHub Actions compatible
SDK는 코드 변경이 필요하지 않고 자동으로 선택합니다.
세션 관리
세션은 기본적으로 임시로 설정됩니다. 다시 시작 가능한 세션을 만들려면 사용자 고유의 세션 ID를 제공합니다.
// Create a named session
const session = await client.createSession({
sessionId: "my-project-analysis",
model: "gpt-4.1",
});
// Later, resume it
const resumed = await client.resumeSession("my-project-analysis");
세션 상태는 에 ~/.copilot/session-state/{sessionId}/로컬로 저장됩니다.
Limitations
| Limitation | 세부 정보 |
|---|---|
| 버전 호환성 | CLI 버전이 SDK와 호환되는지 확인해야 합니다. |
| 단일 사용자 | 자격 증명은 CLI에 로그인한 사용자와 연결됩니다. |
| 로컬 전용 | CLI는 앱과 동일한 컴퓨터에서 실행됩니다. |
| 다중 테넌트 없음 | 하나의 CLI 인스턴스에서 여러 사용자를 제공할 수 없습니다. |
다음 단계
- 기본 설정(번들 CLI): SDK의 기본 제공 CLI 사용(대부분의 사용 사례에 권장)
- 첫 번째 Copilot 기반 앱 빌드: 완전한 대화형 앱 빌드
- 인증: 모든 인증 메서드 세부 정보