laguagu/claude-code-nextjs-skills / skills/ai-elements
ai-elements
VerifiedMaintains AI chat UI built from elements.ai-sdk.dev AI Elements components already copied into the project. Use when changing or debugging those components (conversations, messages, prompt inputs, attachments, reasoning, tool output, sources). New chat UI uses the shadcn/ui AI Elements patterns (`shadcn` skill).
references/image.md
View on GitHub# Image
Displays AI-generated images from the AI SDK.
The `Image` component displays AI-generated images from the AI SDK. It accepts a [`Experimental_GeneratedImage`](https://ai-sdk.dev/docs/reference/ai-sdk-core/generate-image) object from the AI SDK's `generateImage` function and automatically renders it as an image.
See `scripts/image.tsx` for this example.
## Installation
```bash
npx ai-elements@latest add image
```
## Usage with AI SDK
Build a simple app allowing a user to generate an image given a prompt.
Install the `@ai-sdk/openai` package:
```package-install
npm i @ai-sdk/openai
```
Add the following component to your frontend:
```tsx title="app/page.tsx"
"use client";
import { Image } from "@/components/ai-elements/image";
import {
PromptInput,
type PromptInputMessage,
PromptInputTextarea,
PromptInputSubmit,
} from "@/components/ai-elements/prompt-input";
import { useState } from "react";
import { Spinner } from "@/components/ui/spinner";
const ImageDemo = () => {
const [prompt, setPrompt] = useState("A futuristic cityscape at sunset");
const [imageData, setImageData] = useState<any>(null);
const [isLoading, setIsLoading] = useState(false);
const handleSubmit = async (message: PromptInputMessage) => {
if (!message.text.trim()) return;
setPrompt("");
setIsLoading(true);
try {
const response = await fetch("/api/image", {
method: "POST",
body: JSON.stringify({ prompt: message.text.trim() }),
});
const data = await response.json();
setImageData(data);
} catch (error) {
console.error("Error generating image:", error);
} finally {
setIsLoading(false);
}
};
return (
<div className="max-w-4xl mx-auto p-6 relative size-full rounded-lg border h-[600px]">
<div className="flex flex-col h-full">
<div className="flex-1 overflow-y-auto p-4">
{imageData && (
<div className="flex justify-center">
<Image
{...imageData}
alt="Generated image"
className="h-[300px] aspect-square border rounded-lg"
/>
</div>
)}
{isLoading && <Spinner />}
</div>
<PromptInput
onSubmit={handleSubmit}
className="mt-4 w-full max-w-2xl mx-auto relative"
>
<PromptInputTextarea
value={prompt}
placeholder="Describe the image you want to generate..."
onChange={(e) => setPrompt(e.currentTarget.value)}
className="pr-12"
/>
<PromptInputSubmit
status={isLoading ? "submitted" : "ready"}
disabled={!prompt.trim()}
className="absolute bottom-1 right-1"
/>
</PromptInput>
</div>
</div>
);
};
export default ImageDemo;
```
Add the following route to your backend (AI SDK 6/7; model checked 2026-10-11):
```ts title="app/api/image/route.ts"
import { openai } from "@ai-sdk/openai";
import { generateImage } from "ai";
export async function POST(req: Request) {
const { prompt }: { prompt: string } = await req.json();
const { image } = await generateImage({
model: openai.image("gpt-image-2"),
prompt: prompt,
size: "1024x1024",
});
return Response.json({
base64: image.base64,
uint8Array: image.uint8Array,
mediaType: image.mediaType,
});
}
```
## Features
- Accepts `Experimental_GeneratedImage` objects directly from the AI SDK
- Automatically creates proper data URLs from base64-encoded image data
- Supports all standard HTML image attributes
- Responsive by default with `max-w-full h-auto` styling
- Customizable with additional CSS classes
- Includes proper TypeScript types for AI SDK compatibility
## Props
### `<Image />`
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `alt` | `string` | - | Alternative text for the image. |
| `className` | `string` | - | Additional CSS classes to apply to the image. |
| `...props` | `Experimental_GeneratedImage` | - | The image data to display, as returned by the AI SDK. |
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |