---
meta:
  title: "Copilots"
  parentTitle: "AI Copilots"
  description: "Customizable AI copilots"
---

AI Copilots provides a default copilot for testing, but you should define a
custom copilot in the [Liveblocks dashboard](/dashboard) for further development
and production. This allows you to configure your AI model, system prompt,
back-end knowledge, and more.

## Creating a copilot

To create a copilot, open the [Liveblocks dashboard](/dashboard), select a
project and click on the “AI Copilots” page. Click on the “Create copilot”
button, and fill in the required fields.

<Figure>
  <Image
    src="/assets/ai-copilots/create-copilot.png"
    alt="Screenshot of the Liveblocks dashboard with the AI Copilots page and the Create copilot button"
    width={720}
    height={409}
    quality={100}
  />
</Figure>

### Get your API key

Copilots use API keys provided by your AI provider, which can be created and
copied on their respective websites. Out of the box, we support
[OpenAI](https://platform.openai.com/api-keys),
[Anthropic](https://console.anthropic.com/settings/keys), and
[Google](https://aistudio.google.com/app/api-keys), but, you can use other
OpenAI-compatible APIs, such as [Groq](https://groq.com/api-keys) and
[OpenRouter](https://openrouter.ai/settings/keys).

## Add the copilot to your application

To use the new copilot in your application, copy your copilot ID from the
dashboard.

<Figure>
  <video autoPlay loop muted playsInline>
    <source src="/assets/ai-copilots/create-copilot-2.mp4" type="video/mp4" />
  </video>
</Figure>

Paste the copilot ID into
[`AiChat`](/docs/api-reference/liveblocks-react-ui#AiChat) and
[`useSendAiMessage`](/docs/api-reference/liveblocks-react#useSendAiMessage) to
start using it.

```tsx
import { AiChat } from "@liveblocks/react-ui";

function Chat() {
  return (
    <AiChat
      chatId="my-chat-id"
      // +++
      copilotId="co_tUYtNctLAtUIAAIZBc1Zk"
      // +++
    />
  );
}
```

```tsx
import { useSendAiMessage } from "@liveblocks/react";

function SendMessage() {
  const sendAiMessage = useSendAiMessage("my-chat-id", {
    // +++
    copilotId: "co_tUYtNctLAtUIAAIZBc1Zk",
    // +++
  });

  return (
    <button onClick={() => sendAiMessage("What's new?")}>What's new?</button>
  );
}
```

## Configuring your copilot

Within the “General” tab you can configure a number of settings for your
copilot. Settings slightly differ between providers.

### Name

The name of your AI Copilot, which will be displayed in the dashboard.

```text title="Name"
My AI Copilot
```

### Provider

This is the AI provider you want to use for your copilot. You can choose from
[OpenAI](https://platform.openai.com/api-keys),
[Anthropic](https://console.anthropic.com/settings/keys), and
[Google](https://aistudio.google.com/app/api-keys), and other OpenAI-compatible
APIs, such as [Groq](https://groq.com/api-keys). Using an OpenAI-compatible tool
like OpenRouter allows you to
[define fallback models](/docs/guides/how-to-use-fallback-ai-models-in-ai-copilots).

```text title="Provider"
OpenAI
```

### Model

The AI model you want to use for your copilot, such as `GPT-4.1` or
`Claude 4 Sonnet`. You can choose from the models supported by your provider.
With third-party tools you can
[define fallback models](/docs/guides/how-to-use-fallback-ai-models-in-ai-copilots).

```text title="Model"
GPT-4.1
```

### Custom provider name

If you’re using an OpenAI-compatible provider, you can define a custom provider
name, which you may find on your provider’s website. If a custom provider name
isn’t needed by your provider, you can use any string.

```text title="Custom provider name"
custom-provider
```

### Base URL

If you’re using an OpenAI-compatible provider, you must define a base URL, which
you can find on your provider’s website.

```text title="Base URL"
https://openrouter.ai/api/v1/
```

### Reasoning effort, extended thinking, thinking budget

Reasoning is supported by some models, allowing AI show its thought processes,
and come up with more accurate answers. Some models allow you to select a
reasoning effort, such as `low`, `medium`, or `high`, or a token budget for
extended thinking.

```text title="Reasoning effort"
low
```

### Web search

Toggle web searching, allowing your AI to query the internet for information.

```text title="Web search"
on
```

### Limit web search to specific domains

When web search is enabled, limit the domains that the AI can search. Will
search both `http://` and `https://` URLs. Subdomains are allowed.

```text title="Limit web search to specific domains"
encyclopedia.com
en.wikipedia.org
```

### API key

The API key for your provider. You can find keys on each provider’s website:
[OpenAI](https://platform.openai.com),
[Anthropic](https://console.anthropic.com), and
[Google](https://aistudio.google.com). Also supports OpenAI-compatible APIs,
such as [Groq](https://groq.com/) and [OpenRouter](https://openrouter.ai). All
API keys are encrypted at rest, and never stored in plain text.

```text title="API key"
sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

### System prompt

The system prompt defines the behavior of the copilot, for example:

```text title="System prompt"
You're a helpful assistant that can answer questions and help with tasks.
```

You can create more complex system prompts by using
[Markdown formatting](https://www.markdownguide.org/basic-syntax/).

```text title="System prompt"
# Role and objective

You're a helpful assistant that can answer questions and help with tasks.

## Instructions

- Always help the user as best you can.
- Always use markdown formatting in your responses.
- If you don't know the answer, tell the user to contact support.

## Examples

User: How do I log in?
Assistant: Navigate to the [login page](/login) and enter your email.

User: What's the weather in Tokyo?
Assistant: I don't know the answer to that question, please contact support.
```

### When should AI use knowledge?

This setting determines when AI will search back-end knowledge before
responding.

```text title="When should AI use knowledge?"
Whenever the user asks a question about code.
```

You can also write a more complex prompt, giving knowledge a name, which then
allows you to refer to it in your system prompt. This can help reinforce AI
behavior.

```text title="When should AI use knowledge?"
Whenever the user asks a question about code.

// +++
This is your **knowledge base**.
// +++
```

```text title="System prompt"
## Instructions

// +++
- When a user asks about React, searching your **knowledge base** is required.
// +++
...
```

## Adding back-end knowledge

Under the “Knowledge” tab you can add back-end knowledge to your copilot.
Knowledge can be submitted as web pages or files, and your AI chat can query
this knowledge when responding, allowing it to intelligently answer questions or
perform tasks.

<Figure>
  <Image
    src="/assets/ai-copilots/copilot-knowledge.png"
    alt="Screenshot of the Liveblocks dashboard, adding knowledge to a copilot"
    width={720}
    height={409}
    quality={100}
  />
</Figure>

You can submit a whole website/sitemap for crawling, a single page, or PDF/image
files. Crawled knowledge is not updated, and to update it, it must be
resubmitted programmatically or via the dashboard.

## Configuring advanced settings

Under the “Advanced” tab you can configure a number of advanced settings for
your copilot. By default, Liveblocks does not pass default values to your
provider, and leaves the options blank.

| Setting                                                                                                                                                                                                                                                     | Description                                           | Example value          |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- | ---------------------- |
| Max tokens <InfoTooltip>The maximum number of tokens that the copilot can use per response.</InfoTooltip>                                                                                                                                                   | Controls response length                              | `1024`                 |
| Temperature <InfoTooltip>Temperature setting. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.</InfoTooltip>                                | Controls randomness in responses                      | `0.2`                  |
| Top P <InfoTooltip>Nucleus sampling. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either `temperature` or `topP`, but not both.</InfoTooltip>                                         | Alternative to temperature for controlling randomness | `0.9`                  |
| Top K <InfoTooltip>Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. Recommended for advanced use cases only. You usually only need to use temperature.</InfoTooltip>                     | Advanced sampling control                             | `200`                  |
| Presence penalty <InfoTooltip>Presence penalty setting. It affects the likelihood of the model to repeat information that is already in the prompt. The value is passed through to the provider. The range depends on the provider and model.</InfoTooltip> | Controls repetition of existing content               | `0.3`                  |
| Frequency penalty <InfoTooltip>Frequency penalty setting. It affects the likelihood of the model to repeatedly use the same words or phrases. The value is passed through to the provider. The range depends on the provider and model.</InfoTooltip>       | Controls repetition of words and phrases              | `0.3`                  |
| Stop sequences <InfoTooltip>Sequences that will stop the generation of the text. If the model generates any of these sequences, it will stop generating further text.</InfoTooltip>                                                                         | Controls when text generation stops                   | `["\\n\\n", "Human:"]` |
| Seed <InfoTooltip>The seed (integer) to use for random sampling. If set and supported by the model, calls will generate deterministic results.</InfoTooltip>                                                                                                | Controls randomness for reproducible results          | `42`                   |
| Max retries <InfoTooltip>Maximum number of retries. Set to 0 to disable retries. Default: 2.</InfoTooltip>                                                                                                                                                  | Controls how many times to retry failed requests      | `2`                    |

## Modifying copilots programmatically

You aren’t limited to creating copilots from the dashboard—you can also create
and modify copilots programmatically, allowing users or teams in your app to
have their own individual copilots.

```ts
import { Liveblocks } from "@liveblocks/node";

const liveblocks = new Liveblocks({
  secret: "{{SECRET_KEY}}",
});

// +++
const copilot = await liveblocks.createAiCopilot({
  name: "My AI Assistant",
  systemPrompt: "You're a helpful assistant that can answer questions.",
  provider: "openai",
  providerModel: "gpt-4",
  providerApiKey: "sk-...",
});
// +++
```

This is made possible using the
[Liveblocks Node.js client](/docs/api-reference/liveblocks-node#AI-Copilots) and
[REST API](/docs/api-reference/rest-api-endpoints#AI), where a number of APIs
are available for managing copilots.

- [`getAiCopilots`](/docs/api-reference/liveblocks-node#get-ai-copilots)
- [`createAiCopilot`](/docs/api-reference/liveblocks-node#create-ai-copilot)
- [`getAiCopilot`](/docs/api-reference/liveblocks-node#get-ai-copilot)
- [`updateAiCopilot`](/docs/api-reference/liveblocks-node#update-ai-copilot)
- [`deleteAiCopilot`](/docs/api-reference/liveblocks-node#delete-ai-copilot)

You can also manage each copilot’s knowledge sources.

- [`createWebKnowledgeSource`](/docs/api-reference/liveblocks-node#create-web-knowledge-source)
- [`createFileKnowledgeSource`](/docs/api-reference/liveblocks-node#create-file-knowledge-source)
- [`getKnowledgeSources`](/docs/api-reference/liveblocks-node#get-knowledge-sources)
- [`getKnowledgeSource`](/docs/api-reference/liveblocks-node#get-knowledge-source)
- [`getFileKnowledgeSourceMarkdown`](/docs/api-reference/liveblocks-node#get-file-knowledge-source-markdown)
- [`getWebKnowledgeSourceLinks`](/docs/api-reference/liveblocks-node#get-web-knowledge-source-links)
- [`deleteWebKnowledgeSource`](/docs/api-reference/liveblocks-node#delete-web-knowledge-source)
- [`deleteFileKnowledgeSource`](/docs/api-reference/liveblocks-node#delete-file-knowledge-source)

---

For an overview of all available documentation, see [/llms.txt](/llms.txt).
