Skip to main content

기본 설정(번들 CLI)

Node.js, Python 및 .NET SDK에는 Copilot CLI가 종속성으로 포함됩니다. 앱은 추가 설치 또는 구성 없이 필요한 모든 항목을 제공합니다.

최적 대상: 대부분의 애플리케이션은 데스크톱 앱, 독립 실행형 도구, CLI 유틸리티, 프로토타입 등입니다.

작동 방식

SDK를 설치하면 Copilot CLI 이진 파일이 자동으로 포함됩니다. SDK는 자식 프로세스로 시작하고 stdio를 통해 통신합니다. 구성할 추가 항목은 없습니다.

다이어그램: 설명된 프로세스를 보여 주는 순서도입니다.

주요 특징:

  • CLI 이진 파일이 SDK에 포함되어 있습니다. 별도의 설치가 필요하지 않습니다.
  • SDK는 호환성을 보장하기 위해 CLI 버전을 관리합니다.
  • 사용자가 앱을 통해 인증(또는 env vars/BYOK 사용)
  • 세션은 머신에서 사용자별로 관리됩니다.

빠른 시작

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();
Python
from copilot import CopilotClient
from copilot.session import 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("Hello!")
print(response.data.content)

await client.stop()
Go

참고

Go SDK는 CLI를 번들로 묶지 않습니다. CLI를 별도로 설치하거나 Connection가 기존 바이너리를 가리키도록 설정해야 합니다. 자세한 내용을 보려면 로컬 CLI 설정(을)를 참조하세요.

package main

import (
    "context"
    "fmt"
    "log"
    copilot "github.com/github/copilot-sdk/go"
)

func main() {
    ctx := context.Background()

    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!"})
    if d, ok := response.Data.(*copilot.AssistantMessageData); ok {
        fmt.Println(d.Content)
    }
}
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!"})
if d, ok := response.Data.(*copilot.AssistantMessageData); ok {
    fmt.Println(d.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);
Java

참고

Java SDK는 Copilot CLI를 번들하거나 포함하지 않습니다. CLI를 별도로 설치하고 Connection 또는 COPILOT_CLI_PATH 환경 변수를 통해 해당 경로를 설정해야 합니다.

import com.github.copilot.sdk.CopilotClient;
import com.github.copilot.sdk.events.*;
import com.github.copilot.sdk.json.*;

var client = new CopilotClient(new CopilotClientOptions()
    // Point to the CLI binary installed on the system
    .setCliPath("/path/to/vendor/copilot")
);
client.start().get();

var session = client.createSession(new SessionConfig()
    .setModel("gpt-4.1")
    .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
).get();

var response = session.sendAndWait(new MessageOptions()
    .setPrompt("Hello!")).get();
System.out.println(response.getData().content());

client.stop().get();

인증 전략

사용자가 인증하는 방법을 결정해야 합니다. 일반적인 패턴은 다음과 같습니다.

다이어그램: 설명된 프로세스를 보여 주는 순서도입니다.

옵션 A: 사용자의 로그인 자격 증명(가장 간단한)

사용자가 CLI에 한 번 로그인하면 앱에서 해당 자격 증명을 사용합니다. 추가 코드가 필요하지 않습니다. 기본 동작입니다.

const client = new CopilotClient();
// Default: uses signed-in user credentials

옵션 B: 환경 변수를 통한 토큰

토큰을 설정하거나 프로그래밍 방식으로 설정하는 지침과 함께 앱을 제공합니다.

const client = new CopilotClient({
    env: {
        COPILOT_GITHUB_TOKEN: getUserToken(),  // Your app provides the token
    },
});

옵션 C: BYOK(GitHub 인증 필요 없음)

고유한 모델 공급자 키를 관리하는 경우 사용자는 GitHub 계정이 전혀 필요하지 않습니다.

const client = new CopilotClient();

const session = await client.createSession({
    model: "gpt-4.1",
    provider: {
        type: "openai",
        baseUrl: "https://api.openai.com/v1",
        apiKey: process.env.OPENAI_API_KEY,
    },
});

자세한 내용은 BYOK (bring your own key) 을 참조하세요.

세션 관리

앱은 일반적으로 사용자가 대화를 다시 시작할 수 있도록 명명된 세션을 원합니다.

const client = new CopilotClient();

// Create a session tied to the user's project
const sessionId = `project-${projectName}`;
const session = await client.createSession({
    sessionId,
    model: "gpt-4.1",
});

// User closes app...
// Later, resume where they left off
const resumed = await client.resumeSession(sessionId);

세션 상태는 .에 ~/.copilot/session-state/{sessionId}/유지됩니다.

이동 시기

필요다음 가이드
GitHub 계정으로 로그인하는 사용자
GitHub OAuth 설정
사용자 컴퓨터 대신 서버에서 실행
백 엔드 서비스 설정
사용자 고유의 모델 키 사용
BYOK (bring your own key)

다음 단계