Copilot SDK

Embed GitHub Copilot’s AI capabilities into your own applications. The SDK manages a Copilot CLI process and communicates via JSON-RPC - you control sessions, tools, and streaming programmatically.

Overview

The SDK doesn’t call the Copilot API directly. It spawns a Copilot CLI subprocess and talks to it via JSON-RPC over stdio. The CLI handles authentication, model selection, and API communication.

┌─────────────────┐     JSON-RPC      ┌──────────────┐     API      ┌─────────────┐
│   Your App      │ <───────────────> │  Copilot CLI │ <──────────> │  Copilot    │
│  (uses SDK)     │      (stdio)      │   (runtime)  │              │  Service    │
└─────────────────┘                   └──────────────┘              └─────────────┘

Three layers:

  • Client (CopilotClient) - spawns the CLI, manages the connection, creates sessions
  • Session (CopilotSession) - an independent conversation with its own history, system prompt, and tools
  • Tools - functions you define that Copilot can call to take actions
Copilot CLI/VS CodeCopilot SDK
Interactive chatProgrammatic control
Human types promptsYour app sends messages
Human reads responsesYour app processes events
Built-in tools onlyDefine your own tools
Single conversationMultiple concurrent sessions

Contents

  • Concepts - How the SDK works
  • Quickstart - Get a Copilot-powered app running in minutes
  • Deep Dives - Advanced patterns
    • Tools - Advanced tool patterns, error handling, MCP integration
    • Streaming - Event handling, UI patterns, performance
    • Sessions - Multi-session patterns, persistence, context management
    • Models - Model selection, BYOK, capabilities
    • Testing - Testing strategies for Copilot-powered apps
  • Notes - Personal gotchas and experiment results

Resources