次の場合に最適です。 ほとんどのアプリケーション (デスクトップ アプリ、スタンドアロン ツール、CLI ユーティリティ、プロトタイプなど)。
どのように機能するのか
SDK をインストールすると、Copilot CLI バイナリが自動的に含まれます。 SDK は、それを子プロセスとして開始し、stdio 経由で通信します。 構成する必要がある追加の情報はありません。

主な特性:
- CLI バイナリは SDK に含まれています。個別のインストールは必要ありません
- SDK は、互換性を確保するために CLI バージョンを管理します
- ユーザーはアプリを使用して認証します (または env vars/BYOK を使用します)
- セッションは自分のマシンでユーザーごとに管理されます
簡単スタート
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
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 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)
}
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 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 に 1 回サインインし、アプリはこれらの資格情報を使用します。 追加のコードは必要ありません。これが既定の動作です。
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) |
次のステップ
- BYOK (bring your own key): 独自のモデル プロバイダー キーを使用する
- セッションの再開と永続化: 高度なセッション管理
- 初めてのCopilot搭載アプリを構築する: 完全なアプリをビルドする