docs/content/docs/reference/v2/index.mdx
import { LinkIcon } from "lucide-react"; import { Accordions, Accordion } from "fumadocs-ui/components/accordion";
The v2 React API (@copilotkit/react-core/v2) is the next-generation interface for building copilot-powered applications. It provides a streamlined set of hooks and components built on top of the AG-UI agent protocol.
<OpsPlatformCTA variant="inline" title="Building production agents?" body="Persistent threads, observability, and the full Enterprise Intelligence Platform on the free Developer tier." surface="docs_reference_v2" />
The v2 API uses the <CopilotKit> provider. Wrap your application with it to configure the runtime connection:
// CopilotKit is imported from the root package, not from the v2 subpackage
import { CopilotKit } from "@copilotkit/react-core";
function App() {
return (
<CopilotKit runtimeUrl="/api/copilotkit">
<YourApp />
</CopilotKit>
);
}
If you need direct control over the v2 provider (e.g. for custom integrations), you can import CopilotKitProvider from @copilotkit/react-core/v2:
import { CopilotKitProvider } from "@copilotkit/react-core/v2";
<CopilotKitProvider runtimeUrl="/api/copilotkit">
<App />
</CopilotKitProvider>
Provide sandboxFunctions to expose host application functions to the sandboxed iframe. See the sandbox functions guide for details. Only needed when using sandbox functions — Open Generative UI rendering works without this prop.
<CopilotKitProvider
runtimeUrl="/api/copilotkit"
openGenerativeUI={{
sandboxFunctions: [{
name: "setTheme",
description: "Switch between light and dark mode",
parameters: z.object({ mode: z.enum(["light", "dark"]) }),
handler: async ({ mode }) => { setTheme(mode); return `Theme set to ${mode}`; },
}],
}}
>
Unlike the v1 onError, this does not require a publicApiKey — error handling works with any configuration.
<CopilotKitProvider
runtimeUrl="/api/copilotkit"
onError={(event) => {
console.error(`[${event.code}]`, event.error.message, event.context);
}}
>
<App />
</CopilotKitProvider>
When using v2 UI components, import the stylesheet once at your app boundary:
import "@copilotkit/react-core/v2/styles.css";