Short, practical recipes for using the GitHub Copilot SDK with Node.js and TypeScript. Each recipe is concise, copy-pasteable, and points to complete runnable examples.
const session = await client.createSession({ model: "gpt-5" });// Start a requestsession.send({ prompt: "Write a very long story..." });// Abort it after some conditionsetTimeout(async () => { await session.abort(); console.log("Request aborted");}, 5000);
import { CopilotClient } from "@github/copilot-sdk";const client = new CopilotClient();await client.start();// Create multiple independent sessionsconst session1 = await client.createSession({ model: "gpt-5" });const session2 = await client.createSession({ model: "gpt-5" });const session3 = await client.createSession({ model: "claude-sonnet-4.5" });// Each session maintains its own conversation historyawait session1.sendAndWait({ prompt: "You are helping with a Python project" });await session2.sendAndWait({ prompt: "You are helping with a TypeScript project" });await session3.sendAndWait({ prompt: "You are helping with a Go project" });// Follow-up messages stay in their respective contextsawait session1.sendAndWait({ prompt: "How do I create a virtual environment?" });await session2.sendAndWait({ prompt: "How do I set up tsconfig?" });await session3.sendAndWait({ prompt: "How do I initialize a module?" });// Clean up all sessionsawait session1.destroy();await session2.destroy();await session3.destroy();await client.stop();
import { CopilotClient } from "@github/copilot-sdk";const client = new CopilotClient();await client.start();const session = await client.createSession({ model: "gpt-5" });const response = await session.sendAndWait({ prompt: ` I have these files in a directory: - report.pdf - meeting-notes.txt - photo.jpg - invoice.xlsx - presentation.pptx Please organize them into folders by type. Return JSON with the folder structure. `,});console.log(response?.data.content);// Parse the AI response and execute file operations// ...