File: inline-citation.md | Updated: 11/15/2025
Slash Forward
Docs Cookbook Providers Playground AI ElementsAI ElementsLeft sparkleRight sparkle AI GatewayGateway
Search...⌘KFeedback GitHub Vercel LogoSign in with Vercel
Chatbot
A hoverable citation component that displays source information and quotes inline with text, perfect for AI-generated content with references.
The InlineCitation component provides a way to display citations inline with text content, similar to academic papers or research documents. It consists of a citation pill that shows detailed source information on hover, making it perfect for AI-generated content that needs to reference sources.
Preview
Code
According to recent studies, artificial intelligence has shown remarkable progress in natural language processing. The technology continues to evolve rapidly, with new breakthroughs being announced regularlyexample.com +5.
AI Elements
shadcn CLI
Manual
npx ai-elements@latest add inline-citation
Build citations for AI-generated content using experimental_generateObject
.
Add the following component to your frontend:
app/page.tsx
'use client';
import { experimental_useObject as useObject } from '@ai-sdk/react';
import {
InlineCitation,
InlineCitationText,
InlineCitationCard,
InlineCitationCardTrigger,
InlineCitationCardBody,
InlineCitationCarousel,
InlineCitationCarouselContent,
InlineCitationCarouselItem,
InlineCitationCarouselHeader,
InlineCitationCarouselIndex,
InlineCitationCarouselPrev,
InlineCitationCarouselNext,
InlineCitationSource,
InlineCitationQuote,
} from '@/components/ai-elements/inline-citation';
import { Button } from '@/components/ui/button';
import { citationSchema } from '@/app/api/citation/route';
const CitationDemo = () => {
const { object, submit, isLoading } = useObject({
api: '/api/citation',
schema: citationSchema,
});
const handleSubmit = (topic: string) => {
submit({ prompt: topic });
};
return (
<div className="max-w-4xl mx-auto p-6 space-y-6">
<div className="flex gap-2 mb-6">
<Button
onClick={() => handleSubmit('artificial intelligence')}
disabled={isLoading}
variant="outline"
>
Generate AI Content
</Button>
<Button
onClick={() => handleSubmit('climate change')}
disabled={isLoading}
variant="outline"
>
Generate Climate Content
</Button>
</div>
{isLoading && !object && (
<div className="text-muted-foreground">
Generating content with citations...
</div>
)}
{object?.content && (
<div className="prose prose-sm max-w-none">
<p className="leading-relaxed">
{object.content.split(/(\[\d+\])/).map((part, index) => {
const citationMatch = part.match(/\[(\d+)\]/);
if (citationMatch) {
const citationNumber = citationMatch[1];
const citation = object.citations?.find(
(c: any) => c.number === citationNumber,
);
if (citation) {
return (
<InlineCitation key={index}>
<InlineCitationCard>
<InlineCitationCardTrigger sources={[citation.url]} />
<InlineCitationCardBody>
<InlineCitationCarousel>
<InlineCitationCarouselHeader>
<InlineCitationCarouselPrev />
<InlineCitationCarouselNext />
<InlineCitationCarouselIndex />
</InlineCitationCarouselHeader>
<InlineCitationCarouselContent>
<InlineCitationCarouselItem>
<InlineCitationSource
title={citation.title}
url={citation.url}
description={citation.description}
/>
{citation.quote && (
<InlineCitationQuote>
{citation.quote}
</InlineCitationQuote>
)}
</InlineCitationCarouselItem>
</InlineCitationCarouselContent>
</InlineCitationCarousel>
</InlineCitationCardBody>
</InlineCitationCard>
</InlineCitation>
);
}
}
return part;
})}
</p>
</div>
)}
</div>
);
};
export default CitationDemo;
Add the following route to your backend:
app/api/citation/route.ts
import { streamObject } from 'ai';
import { z } from 'zod';
export const citationSchema = z.object({
content: z.string(),
citations: z.array(
z.object({
number: z.string(),
title: z.string(),
url: z.string(),
description: z.string().optional(),
quote: z.string().optional(),
}),
),
});
// Allow streaming responses up to 30 seconds
export const maxDuration = 30;
export async function POST(req: Request) {
const { prompt } = await req.json();
const result = streamObject({
model: 'openai/gpt-4o',
schema: citationSchema,
prompt: `Generate a well-researched paragraph about ${prompt} with proper citations.
Include:
- A comprehensive paragraph with inline citations marked as [1], [2], etc.
- 2-3 citations with realistic source information
- Each citation should have a title, URL, and optional description/quote
- Make the content informative and the sources credible
Format citations as numbered references within the text.`,
});
return result.toTextStreamResponse();
}
<InlineCitation />Prop
Type
...props?React.ComponentProps<"span">
<InlineCitationText />Prop
Type
...props?React.ComponentProps<"span">
<InlineCitationCard />Prop
Type
...props?React.ComponentProps<"span">
<InlineCitationCardTrigger />Prop
Type
sources?string[]
...props?React.ComponentProps<"button">
<InlineCitationCardBody />Prop
Type
...props?React.ComponentProps<"div">
<InlineCitationCarousel />Prop
Type
...props?React.ComponentProps<typeof Carousel>
<InlineCitationCarouselContent />Prop
Type
...props?React.ComponentProps<"div">
<InlineCitationCarouselItem />Prop
Type
...props?React.ComponentProps<"div">
<InlineCitationCarouselHeader />Prop
Type
...props?React.ComponentProps<"div">
<InlineCitationCarouselIndex />Prop
Type
...props?React.ComponentProps<"div">
<InlineCitationCarouselPrev />Prop
Type
...props?React.ComponentProps<typeof CarouselPrevious>
<InlineCitationCarouselNext />Prop
Type
...props?React.ComponentProps<typeof CarouselNext>
<InlineCitationSource />Prop
Type
title?string
url?string
description?string
...props?React.ComponentProps<"div">
<InlineCitationQuote />Prop
Type
...props?React.ComponentProps<"blockquote">
Conversation
Wraps messages and automatically scrolls to the bottom. Also includes a scroll button that appears when not at the bottom.
Message
A comprehensive suite of components for displaying chat messages, including message rendering, branching, actions, and markdown responses.
On this page
Installation
Usage with AI SDK
Features
Props
<InlineCitation />
<InlineCitationText />
<InlineCitationCard />
<InlineCitationCardTrigger />
<InlineCitationCardBody />
<InlineCitationCarousel />
<InlineCitationCarouselContent />
<InlineCitationCarouselItem />
<InlineCitationCarouselHeader />
<InlineCitationCarouselIndex />
<InlineCitationCarouselPrev />
<InlineCitationCarouselNext />
<InlineCitationSource />
<InlineCitationQuote />
GitHubEdit this page on GitHub Scroll to topCopy pageOpen in chat