You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Create new AI chat interface components for the ai-elements library following established composable patterns, shadcn/ui integration, and Vercel AI SDK conventions. Use when creating new components in packages/elements/src or when the user asks to add a new component to ai-elements.
181
+
---
182
+
183
+
# AI Elements
184
+
185
+
${transformOverviewMdx(indexContent)}
186
+
187
+
## Usage
188
+
189
+
${transformOverviewMdx(usageContent)}
190
+
191
+
## Troubleshooting
192
+
193
+
${transformOverviewMdx(troubleshootingContent)}
194
+
195
+
## Available Components
196
+
197
+
See the \`references/\` folder for detailed documentation on each component.
description: Create new AI chat interface components for the ai-elements library following established composable patterns, shadcn/ui integration, and Vercel AI SDK conventions. Use when creating new components in packages/elements/src or when the user asks to add a new component to ai-elements.
4
+
---
5
+
6
+
# AI Elements
7
+
8
+
[AI Elements](https://www.npmjs.com/package/ai-elements) is a component library and custom registry built on top of [shadcn/ui](https://ui.shadcn.com/) to help you build AI-native applications faster. It provides pre-built components like conversations, messages and more.
9
+
10
+
Installing AI Elements is straightforward and can be done in a couple of ways. You can use the dedicated CLI command for the fastest setup, or integrate via the standard shadcn/ui CLI if you've already adopted shadcn's workflow.
11
+
12
+
13
+
14
+
## Quick Start
15
+
16
+
Here are some basic examples of what you can achieve using components from AI Elements.
17
+
18
+
19
+
20
+
## Prerequisites
21
+
22
+
Before installing AI Elements, make sure your environment meets the following requirements:
23
+
24
+
-[Node.js](https://nodejs.org/en/download/), version 18 or later
25
+
- A [Next.js](https://nextjs.org/) project with the [AI SDK](https://ai-sdk.dev/) installed.
26
+
-[shadcn/ui](https://ui.shadcn.com/) installed in your project. If you don't have it installed, running any install command will automatically install it for you.
27
+
- We also highly recommend using the [AI Gateway](https://vercel.com/docs/ai-gateway) and adding `AI_GATEWAY_API_KEY` to your `env.local` so you don't have to use an API key from every provider. AI Gateway also gives $5 in usage per month so you can experiment with models. You can obtain an API key [here](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai%2Fapi-keys&title=Get%20your%20AI%20Gateway%20key).
28
+
29
+
30
+
31
+
## Installing Components
32
+
33
+
You can install AI Elements components using either the AI Elements CLI or the shadcn/ui CLI. Both achieve the same result: adding the selected component’s code and any needed dependencies to your project.
34
+
35
+
The CLI will download the component’s code and integrate it into your project’s directory (usually under your components folder). By default, AI Elements components are added to the `@/components/ai-elements/` directory (or whatever folder you’ve configured in your shadcn components settings).
36
+
37
+
After running the command, you should see a confirmation in your terminal that the files were added. You can then proceed to use the component in your code.
38
+
39
+
## Usage
40
+
41
+
Once an AI Elements component is installed, you can import it and use it in your application like any other React component. The components are added as part of your codebase (not hidden in a library), so the usage feels very natural.
42
+
43
+
## Example
44
+
45
+
After installing AI Elements components, you can use them in your application like any other React component. For example:
In the example above, we import the `Message` component from our AI Elements directory and include it in our JSX. Then, we compose the component with the `MessageContent` and `MessageResponse` subcomponents. You can style or configure the component just as you would if you wrote it yourself – since the code lives in your project, you can even open the component file to see how it works or make custom modifications.
82
+
83
+
## Extensibility
84
+
85
+
All AI Elements components take as many primitive attributes as possible. For example, the `Message` component extends `HTMLAttributes<HTMLDivElement>`, so you can pass any props that a `div` supports. This makes it easy to extend the component with your own styles or functionality.
86
+
87
+
## Customization
88
+
89
+
90
+
91
+
After installation, no additional setup is needed. The component’s styles (Tailwind CSS classes) and scripts are already integrated. You can start interacting with the component in your app immediately.
92
+
93
+
For example, if you'd like to remove the rounding on `Message`, you can go to `components/ai-elements/message.tsx` and remove `rounded-lg` as follows:
Make sure your project is configured correctly for shadcn/ui in Tailwind 4 - this means having a `globals.css` file that imports Tailwind and includes the shadcn/ui base styles.
119
+
120
+
## I ran the AI Elements CLI but nothing was added to my project
121
+
122
+
Double-check that:
123
+
124
+
- Your current working directory is the root of your project (where `package.json` lives).
125
+
- Your components.json file (if using shadcn-style config) is set up correctly.
126
+
- You’re using the latest version of the AI Elements CLI:
127
+
128
+
```bash title="Terminal"
129
+
npx ai-elements@latest
130
+
```
131
+
132
+
If all else fails, feel free to open an [issue on GitHub](https://github.com/vercel/ai-elements/issues).
133
+
134
+
## Theme switching doesn’t work — my app stays in light mode
135
+
136
+
Ensure your app is using the same data-theme system that shadcn/ui and AI Elements expect. The default implementation toggles a data-theme attribute on the `<html>` element. Make sure your tailwind.config.js is using class or data- selectors accordingly:
137
+
138
+
## The component imports fail with “module not found”
139
+
140
+
Check the file exists. If it does, make sure your `tsconfig.json` has a proper paths alias for `@/` i.e.
141
+
142
+
```json title="tsconfig.json"
143
+
{
144
+
"compilerOptions": {
145
+
"baseUrl": ".",
146
+
"paths": {
147
+
"@/*": ["./*"]
148
+
}
149
+
}
150
+
}
151
+
```
152
+
153
+
## My AI coding assistant can't access AI Elements components
154
+
155
+
1. Verify your config file syntax is valid JSON.
156
+
2. Check that the file path is correct for your AI tool.
157
+
3. Restart your coding assistant after making changes.
158
+
4. Ensure you have a stable internet connection.
159
+
160
+
## Still stuck?
161
+
162
+
If none of these answers help, open an [issue on GitHub](https://github.com/vercel/ai-elements/issues) and someone will be happy to assist.
163
+
164
+
## Available Components
165
+
166
+
See the `references/` folder for detailed documentation on each component.
0 commit comments