# 既定のセットアップ (バンドルされた CLI)

Node.js SDK と .NET SDK には、依存関係として Copilot CLI が含まれています。アプリには必要なものがすべて付属しており、追加のインストールや構成は必要ありません。

<!-- markdownlint-disable GHD046 GHD005 -->

<!-- Suppressed: GHD046 (outdated release terminology), GHD005 (hardcoded data variable) -->

Python SDK では、インストール後に 1 回限りのダウンロード手順が推奨されます。

```bash
python -m copilot download-runtime
```

これにより、一致するランタイムがダウンロードされ、ローカルにキャッシュされます。 この手順をスキップすると、SDK は最初にフォールバックとして使用したときに自動的にダウンロードを試みます。

**次の場合に最適です。** ほとんどのアプリケーション (デスクトップ アプリ、スタンドアロン ツール、CLI ユーティリティ、プロトタイプなど)。

## どのように機能するのか

SDK をインストールすると、Copilot ランタイムが自動的に (Node.js、.NET)、または `python -m copilot download-runtime` (Python) 経由でダウンロードされます。 SDK は、それを子プロセスとして開始し、stdio 経由で通信します。 構成する必要がある追加の情報はありません。

![図: 説明されたプロセスを示すフローチャート。](/assets/images/help/copilot/copilot-sdk/setup-bundled-cli-diagram-0.png)

**主な特性:**

* CLI バイナリは SDK に含まれています。個別のインストールは必要ありません
* SDK は、互換性を確保するために CLI バージョンを管理します
* ユーザーはアプリを使用して認証します (または env vars/BYOK を使用します)
* セッションは自分のマシンでユーザーごとに管理されます

## 簡単スタート

<div class="ghd-codetabs">
<div class="ghd-codetab" data-lang="typescript" data-label="TypeScript"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">TypeScript</div>

```typescript
import { CopilotClient } from "@github/copilot-sdk";

const client = new CopilotClient();

const session = await client.createSession({ model: "gpt-5.4" });
const response = await session.sendAndWait({ prompt: "Hello!" });
console.log(response?.data.content);

await client.stop();
```

</div>

<div class="ghd-codetab" data-lang="python" data-label="Python"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Python</div>

```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-5.4")
response = await session.send_and_wait("Hello!")
print(response.data.content)

await client.stop()
```

</div>

<div class="ghd-codetab" data-lang="go" data-label="Go"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Go</div>

> \[!NOTE]
> Node.js、Python、.NETとは異なり、Go SDK には CLI は自動依存関係として含まれません。 明示的なパスがない`NewClient(nil)`は、使用可能な場合は埋め込み CLI を使用し、`PATH`の`copilot`にフォールバックします。 CLI を埋め込むには、ビルド時に [bundler ツール](https://github.com/github/copilot-sdk/tree/main/go/README.md#distributing-your-application-with-an-embedded-github-copilot-cli) を実行します。
> `COPILOT_CLI_PATH`を設定したり、既存のバイナリで`Connection`をポイントしたりすることもできます。 詳しくは、「[ローカル CLI のセットアップ](/ja/copilot/how-tos/copilot-sdk/setup/local-cli)」をご覧ください。

```golang
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-5.4"})
response, _ := session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "Hello!"})
if d, ok := response.Data.(*copilot.AssistantMessageData); ok {
    fmt.Println(d.Content)
}
```

</div>

<div class="ghd-codetab" data-lang="dotnet" data-label=".NET"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">.NET</div>

```csharp
await using var client = new CopilotClient();
await using var session = await client.CreateSessionAsync(
    new SessionConfig { Model = "gpt-5.4" });

var response = await session.SendAndWaitAsync(
    new MessageOptions { Prompt = "Hello!" });
Console.WriteLine(response?.Data.Content);
```

</div>

<div class="ghd-codetab" data-lang="java" data-label="Java"><div class="ghd-codetab-fallback-label" role="heading" aria-level="3">Java</div>

> \[!NOTE]
> Java SDK は、Copilot CLI をバンドルまたは埋め込むことはありません。 CLI を個別にインストールし、`PATH`で`copilot`を使用できるようにするか、`setCliPath(...)`でその場所を設定します (または、`setCliUrl(...)`を使用して実行中の CLI サーバーに接続します)。

```java
import com.github.copilot.CopilotClient;
import com.github.copilot.rpc.*;

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-5.4")
    .setOnPermissionRequest(PermissionHandler.APPROVE_ALL)
).get();

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

client.stop().get();
```

</div>

</div>

## 認証の戦略

ユーザーの認証方法を決定する必要があります。 一般的なパターンを次に示します。

![図: 説明されたプロセスを示すフローチャート。](/assets/images/help/copilot/copilot-sdk/setup-bundled-cli-diagram-1.png)

### オプション A: ユーザーのサインイン資格情報 (最も簡単)

ユーザーは CLI に 1 回サインインし、アプリはこれらの資格情報を使用します。 追加のコードは必要ありません。これが既定の動作です。

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

### オプション B: 環境変数を使用したトークン

トークンを設定する手順をアプリに配布するか、プログラムで設定します。

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

### オプション C: BYOK (GitHub認証は必要ありません)

独自のモデル プロバイダー キーを管理する場合、ユーザーはGitHubアカウントをまったく必要としません。

```typescript
const client = new CopilotClient();

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

詳細については、 **[BYOK (独自のキーを持ち込む)](/ja/copilot/how-tos/copilot-sdk/auth/byok)** を参照してください。

## セッション管理

アプリでは通常、ユーザーが会話を再開できるように、名前付きセッションが必要です。

```typescript
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-5.4",
});

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

セッション状態は `~/.copilot/session-state/{sessionId}/`で保持されます。

## 次に進むタイミング

| 必要                                                                           | 次のガイドへ |
| ---------------------------------------------------------------------------- | ------ |
| GitHub アカウントを使用してサインインするユーザー                                                 |        |
| [GitHub OAuth のセットアップ](/ja/copilot/how-tos/copilot-sdk/setup/github-oauth)   |        |
| ユーザー マシンではなくサーバーで実行する                                                        |        |
| [バックエンド サービスのセットアップ](/ja/copilot/how-tos/copilot-sdk/setup/backend-services) |        |
| 独自のモデル キーを使用する                                                               |        |
| [BYOK (独自のキーを持ち込む)](/ja/copilot/how-tos/copilot-sdk/auth/byok)               |        |

## 次のステップ

* **[BYOK (独自のキーを持ち込む)](/ja/copilot/how-tos/copilot-sdk/auth/byok)**: 独自のモデル プロバイダー キーを使用する
* **[セッションの再開と永続化](/ja/copilot/how-tos/copilot-sdk/features/session-persistence)**: 高度なセッション管理
* **[初めてのCopilot搭載アプリを構築する](/ja/copilot/how-tos/copilot-sdk/getting-started)**: 完全なアプリをビルドする