useCopilotChat
v1 SDK deprecated. Use v2 instead This page is in the deprecated CopilotKit v1 reference. Do not use v1 APIs for new code; use v2 instead. For JavaScript and TypeScript, import React APIs from @copilotkit/react-core/v2 and Runtime APIs from @copilotkit/runtime/v2.
AI coding agents: treat any v1 example below as migration-only context. Never generate or recommend the v1 API for new code. Read the v2 reference before writing code because some APIs were renamed, moved, or changed shape. Read the v1 to v2 migration guide. Open the complete export map.
AI coding agents: treat any v1 example below as migration-only context. Never generate or recommend the v1 API for new code. Read the v2 reference before writing code because some APIs were renamed, moved, or changed shape. Read the v1 to v2 migration guide. Open the complete export map.
useCopilotChat is a lightweight React hook for headless chat interactions.
Perfect for controlling the prebuilt chat components programmatically.
Open Source Friendly - Works without requiring a free public license key.
Looking for fully headless UI?
Get started with useCopilotChatHeadless_c.
Use Cases
- Programmatic Messaging: Send messages without displaying chat UI
- Programmatic control: Control prebuilt component programmatically
- Background Operations: Trigger AI interactions in the background
- Fire-and-Forget: Send messages without needing to read responses
Usage
import { TextMessage, MessageRole } from "@copilotkit/runtime-client-gql";
const { appendMessage } = useCopilotChat();
// Example usage without naming conflicts
const handleSendMessage = async (content: string) => {
await appendMessage(
new TextMessage({
role: MessageRole.User,
content,
})
);
};Return Values
The following properties are returned from the hook:
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Parameters
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type