From copilotkit
Guides CopilotKit setup in React projects with Next.js (App/Pages), Vite+React, or Angular: detects framework, installs packages, wires runtime (Hono/Express), configures AI providers, adds chat UI.
npx claudepluginhub copilotkit/skills --plugin copilotkitThis skill uses the workspace's default tool permissions.
This plugin includes an MCP server (`copilotkit-docs`) that provides `search-docs` and `search-code` tools for querying live CopilotKit documentation and source code.
Builds AI-powered app features with CopilotKit v2: configure server runtime (Hono/Express), add React chat UIs, register frontend tools, share app context with agents, handle interrupts.
Embeds GitHub Copilot's agentic runtime in Python, TypeScript, Go, .NET apps for custom agents, tools, sessions, streaming, and MCP servers.
Builds and maintains GitHub Copilot CLI plugins including skills, agents, prompts, instructions, AGENTS.md, MCP servers, and hooks. Provides specs, templates, validation.
Share bugs, ideas, or general feedback.
This plugin includes an MCP server (copilotkit-docs) that provides search-docs and search-code tools for querying live CopilotKit documentation and source code.
.mcp.json -- no setup needed.Before starting setup, verify:
fetch globals used by the runtime)OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY)Before generating any code, detect the project's framework by checking files in the project root. See references/framework-detection.md for the full decision tree.
Quick summary:
| Signal File | Framework |
|---|---|
next.config.{js,ts,mjs} + app/ directory | Next.js App Router |
next.config.{js,ts,mjs} + pages/ directory | Next.js Pages Router |
angular.json | Angular |
vite.config.{js,ts} + React deps in package.json | Vite + React |
All packages use the @copilotkit namespace.
Frontend (React) packages:
npm install @copilotkit/react @copilotkit/core
Runtime packages (backend):
npm install @copilotkit/runtime @copilotkit/agent
If the runtime runs in the same Next.js app as the frontend, install all four packages together.
For standalone Express backends, also install Express adapter dependencies:
npm install express cors
npm install -D @types/express @types/cors
The runtime is the server-side component that manages agent execution. See references/runtime-architecture.md for details.
There are two endpoint styles:
createCopilotEndpoint. Requires a catch-all route ([[...slug]] in Next.js). Each operation (run, connect, stop, info, transcribe, threads) gets its own HTTP path.createCopilotEndpointSingleRoute or createCopilotEndpointSingleRouteExpress. All operations go through a single POST endpoint with method multiplexing.Create src/app/api/copilotkit/[[...slug]]/route.ts:
import {
CopilotRuntime,
createCopilotEndpoint,
InMemoryAgentRunner,
} from "@copilotkit/runtime";
import { BuiltInAgent } from "@copilotkit/agent";
import { handle } from "hono/vercel";
const agent = new BuiltInAgent({
model: "openai/gpt-4o",
prompt: "You are a helpful AI assistant.",
});
const runtime = new CopilotRuntime({
agents: {
default: agent,
},
runner: new InMemoryAgentRunner(),
});
const app = createCopilotEndpoint({
runtime,
basePath: "/api/copilotkit",
});
export const GET = handle(app);
export const POST = handle(app);
This requires hono as a dependency:
npm install hono
Create src/app/api/copilotkit/route.ts:
import {
CopilotRuntime,
createCopilotEndpointSingleRoute,
InMemoryAgentRunner,
} from "@copilotkit/runtime";
import { BuiltInAgent } from "@copilotkit/agent";
import { handle } from "hono/vercel";
const agent = new BuiltInAgent({
model: "openai/gpt-4o",
prompt: "You are a helpful AI assistant.",
});
const runtime = new CopilotRuntime({
agents: {
default: agent,
},
runner: new InMemoryAgentRunner(),
});
const app = createCopilotEndpointSingleRoute({
runtime,
basePath: "/api/copilotkit",
});
export const POST = handle(app);
When using single-route, the frontend must set useSingleEndpoint on the provider (see Step 3).
Create src/index.ts:
import express from "express";
import { CopilotRuntime } from "@copilotkit/runtime";
import { createCopilotEndpointSingleRouteExpress } from "@copilotkit/runtime/express";
import { BuiltInAgent, defineTool } from "@copilotkit/agent";
import { z } from "zod";
const agent = new BuiltInAgent({
model: "openai/gpt-4o",
});
const runtime = new CopilotRuntime({
agents: {
default: agent,
},
});
const app = express();
app.use(
"/api/copilotkit",
createCopilotEndpointSingleRouteExpress({
runtime,
basePath: "/",
}),
);
const port = Number(process.env.PORT ?? 4000);
app.listen(port, () => {
console.log(`CopilotKit runtime listening at http://localhost:${port}/api/copilotkit`);
});
For multi-route Express, use createCopilotEndpointExpress instead (imported from @copilotkit/runtime/express).
import { CopilotRuntime, createCopilotEndpoint } from "@copilotkit/runtime";
import { BuiltInAgent } from "@copilotkit/agent";
import { serve } from "@hono/node-server";
const runtime = new CopilotRuntime({
agents: {
default: new BuiltInAgent({ model: "openai/gpt-4o" }),
},
});
const app = createCopilotEndpoint({
runtime,
basePath: "/api/copilotkit",
});
serve({ fetch: app.fetch, port: 8787 });
Requires @hono/node-server:
npm install hono @hono/node-server
Wrap your application with CopilotKitProvider from @copilotkit/react.
Important: Import the stylesheet in your root layout:
import "@copilotkit/react/styles.css";
In src/app/page.tsx (or a client component):
"use client";
import { CopilotKitProvider, CopilotChat } from "@copilotkit/react";
export default function Home() {
return (
<CopilotKitProvider runtimeUrl="/api/copilotkit">
<div style={{ height: "100vh" }}>
<CopilotChat />
</div>
</CopilotKitProvider>
);
}
When the runtime runs on a separate server (e.g., Express on port 4000):
<CopilotKitProvider
runtimeUrl="http://localhost:4000/api/copilotkit"
useSingleEndpoint
>
{children}
</CopilotKitProvider>
Set useSingleEndpoint when the backend uses single-route endpoints (createCopilotEndpointSingleRoute or createCopilotEndpointSingleRouteExpress).
| Prop | Type | Description |
|---|---|---|
runtimeUrl | string | URL of the CopilotKit runtime endpoint |
useSingleEndpoint | boolean | Set to true when using single-route endpoints |
headers | Record<string, string> | Custom headers sent with every request |
credentials | RequestCredentials | Fetch credentials mode (e.g., "include" for cookies) |
publicApiKey | string | Copilot Cloud public API key (if using hosted runtime) |
showDevConsole | boolean | "auto" | Show the dev inspector ("auto" = development only) |
renderToolCalls | ReactToolCallRenderer[] | Custom renderers for tool call UI |
frontendTools | ReactFrontendTool[] | Frontend-defined tools (declarative alternative to useFrontendTool) |
onError | (event) => void | Global error handler |
CopilotKit provides three pre-built chat layouts:
| Component | Usage |
|---|---|
CopilotChat | Inline chat, fills its container |
CopilotSidebar | Collapsible sidebar panel |
CopilotPopup | Floating popup widget |
Example with sidebar:
<CopilotKitProvider runtimeUrl="/api/copilotkit" showDevConsole="auto">
<YourApp />
<CopilotSidebar
defaultOpen
width="420px"
labels={{
modalHeaderTitle: "AI Assistant",
chatInputPlaceholder: "Ask me anything...",
}}
/>
</CopilotKitProvider>
Create a .env.local (Next.js) or .env file:
OPENAI_API_KEY=sk-...
The BuiltInAgent automatically resolves API keys from environment variables based on the model prefix:
openai/* models read OPENAI_API_KEYanthropic/* models read ANTHROPIC_API_KEYgoogle/* models read GOOGLE_API_KEYYou can also pass apiKey directly to BuiltInAgent if needed.
CopilotKit uses telemetry to understand adoption, improve the product, and provide better support. Connecting to the CopilotKit cloud platform gives you access to analytics and optional premium features.
npx copilotkit --help as it may vary by version):
npx copilotkit auth
ck_...).CopilotKitProvider:
<CopilotKitProvider
runtimeUrl="/api/copilotkit"
licenseKey="ck_..."
>
Alternatively, store it as an environment variable (COPILOTKIT_LICENSE_KEY in .env.local or .env) and reference it:
<CopilotKitProvider
runtimeUrl="/api/copilotkit"
licenseKey={process.env.NEXT_PUBLIC_COPILOTKIT_LICENSE_KEY}
>
See references/telemetry-setup.md for full details on what the license key enables and how to opt out.
/info endpoint (GET) to confirm it reports available agents| Package | Purpose |
|---|---|
@copilotkit/react | React components, hooks, provider |
@copilotkit/core | Core types, agent abstraction, state management |
@copilotkit/runtime | Server-side runtime, endpoint factories, agent runners |
@copilotkit/agent | BuiltInAgent, defineTool, model resolution |
@copilotkit/shared | Shared utilities, logger, types |
| Function | Import | Protocol | Framework |
|---|---|---|---|
createCopilotEndpoint | @copilotkit/runtime | Multi-route (Hono) | Next.js App Router, Hono standalone |
createCopilotEndpointSingleRoute | @copilotkit/runtime | Single-route (Hono) | Next.js App Router |
createCopilotEndpointExpress | @copilotkit/runtime/express | Multi-route (Express) | Express standalone |
createCopilotEndpointSingleRouteExpress | @copilotkit/runtime/express | Single-route (Express) | Express standalone |
| Class | Use case |
|---|---|
CopilotRuntime | Compatibility shim; auto-selects SSE or Intelligence mode |
CopilotSseRuntime | Explicit SSE mode (default, in-memory threads) |
CopilotIntelligenceRuntime | Intelligence mode (durable threads, realtime events) |
| Runner | Description |
|---|---|
InMemoryAgentRunner | Default. Stores thread state in process memory. Suitable for development and single-instance deployments. |
IntelligenceAgentRunner | Used automatically with CopilotIntelligenceRuntime. Connects to CopilotKit Intelligence Platform via WebSocket. |
Format: "provider/model-name" string or a Vercel AI SDK LanguageModel instance.
OpenAI: openai/gpt-5, openai/gpt-5-mini, openai/gpt-4.1, openai/gpt-4.1-mini, openai/gpt-4.1-nano, openai/gpt-4o, openai/gpt-4o-mini, openai/o3, openai/o3-mini, openai/o4-mini
Anthropic: anthropic/claude-sonnet-4.5, anthropic/claude-sonnet-4, anthropic/claude-3.7-sonnet, anthropic/claude-opus-4.1, anthropic/claude-opus-4, anthropic/claude-3.5-haiku
Google: google/gemini-2.5-pro, google/gemini-2.5-flash, google/gemini-2.5-flash-lite
Any string is accepted (for custom/unlisted models); the provider is parsed from the prefix before /.