Quickstart
Get started with CopilotKit's Built-in Agent in minutes.
Prerequisites#
Before you begin, you'll need the following:
- An OpenAI API key (or Anthropic/Google — see Model Selection)
- Node.js 20+
- Your favorite package manager
Getting started#
Create a free account#
Sign up for a free developer account on our Enterprise Intelligence Platform to get a license key. You'll use it later to enable persistent threads and the inspector.
Create your frontend#
CopilotKit works with any React-based frontend. We'll use Next.js for this example.
npx create-next-app@latest my-copilot-app
cd my-copilot-appAlready have an app?
Skip this step and install CopilotKit into your existing React or Next.js project. The CopilotKit CLI (npx copilotkit@latest create, aliased as init) scaffolds a brand-new project in its own directory — it does not add CopilotKit to an app you already have.
Install CopilotKit packages#
npm install @copilotkit/react-core @copilotkit/runtimeThe components used below (CopilotKit, CopilotSidebar) and the
stylesheet all come from @copilotkit/react-core/v2, so
@copilotkit/react-ui is not needed for this setup.
Configure your environment#
Create a .env file and add your OpenAI API key:
OPENAI_API_KEY=your_openai_api_keyWhat about other models?
This example uses OpenAI's GPT-4o. See Model Selection for Anthropic, Google, or custom model setup.
Setup Copilot Runtime#
Create an API route with the BuiltInAgent and CopilotRuntime:
Already have an agent? Do not use BuiltInAgent
BuiltInAgent is CopilotKit's own agent — it calls the model
directly. Registering it as default means chat talks to it, not to
any agent you already wrote. It replaces your agent rather than
connecting to it.
If you already have a LangGraph, CrewAI, Mastra, ADK, Pydantic AI or other agent, take the frontend steps from this page but get the runtime wiring from your framework's quickstart, which registers your agent instead — for example LangGraph (Python). Pick yours from the docs landing.
import {
CopilotRuntime,
createCopilotRuntimeHandler,
InMemoryAgentRunner,
} from "@copilotkit/runtime/v2";
import { BuiltInAgent } from "@copilotkit/runtime/v2";
const builtInAgent = new BuiltInAgent({
model: "openai:gpt-5.4-mini",
});
const runtime = new CopilotRuntime({
agents: { default: builtInAgent }, //,
runner: new InMemoryAgentRunner(),
});
const handler = createCopilotRuntimeHandler({
runtime,
basePath: "/api/copilotkit",
});
export const GET = handler;
export const POST = handler;Configure CopilotKit Provider#
Wrap your application with the CopilotKit provider:
Which provider goes with which handler?
<CopilotKit> here is the backward-compatible wrapper, and every released
version pins it to the single-route transport — which is why it needs the
explicit useSingleEndpoint={false} below to reach the multi-route
createCopilotRuntimeHandler route above. <CopilotKitProvider> is the v2
provider from the same package and detects the transport from /info on
its own. They are not aliases — see
Provider and handler pairs.
import { CopilotKit } from "@copilotkit/react-core/v2";
import "@copilotkit/react-core/v2/styles.css";
import './globals.css';
// ...
export default function RootLayout({ children }: {children: React.ReactNode}) {
return (
<html lang="en">
<body>
<CopilotKit runtimeUrl="/api/copilotkit" useSingleEndpoint={false}>
{children}
</CopilotKit>
</body>
</html>
);
}Add the chat interface#
Add the CopilotSidebar component to your page:
import { CopilotSidebar } from "@copilotkit/react-core/v2";
export default function Page() {
return (
<main>
<h1>Your App</h1>
<CopilotSidebar />
</main>
);
}Start the development server#
npm run devpnpm devyarn devbun dev🎉 Start chatting!#
Your AI agent is now ready to use! Try asking it some questions:
Can you tell me a joke?Can you help me understand AI?What do you think about React?Troubleshooting
- If you're having connection issues, try using
0.0.0.0or127.0.0.1instead oflocalhost - Check that your API key is correctly set in the
.envfile - Make sure the runtime endpoint path matches the
runtimeUrlin your CopilotKit provider
Open Inspector and confirm setup#
On localhost, click the Inspector button in the corner of the app.
- Open Agents, then Agent. Your agent is listed.
- Send a chat message. Open Agents, then AG-UI Events. Events are moving.
- Open Threads. The list is unlocked (Intelligence is on), or locked with Enable Intelligence (Intelligence is off).
More detail: Inspector.
What's next?#
Now that you have your basic agent setup, explore these advanced features: