# Sources
URL: /components/sources
---
title: Sources
description: A component that allows a user to view the sources or citations used to generate a response.
path: elements/components/sources
---
The `Sources` component allows a user to view the sources or citations used to generate a response.
## Installation
## Usage
```tsx
import { Source, Sources, SourcesContent, SourcesTrigger } from "@/components/ai-elements/sources";
```
```tsx
```
## Usage with AI SDK
Build a simple web search agent with Perplexity Sonar.
Add the following component to your frontend:
```tsx title="app/page.tsx"
"use client";
import { useChat } from "@ai-sdk/react";
import { Source, Sources, SourcesContent, SourcesTrigger } from "@/components/ai-elements/sources";
import { Input, PromptInputTextarea, PromptInputSubmit } from "@/components/ai-elements/prompt-input";
import { Conversation, ConversationContent, ConversationScrollButton } from "@/components/ai-elements/conversation";
import { Message, MessageContent } from "@/components/ai-elements/message";
import { Response } from "@/components/ai-elements/response";
import { useState } from "react";
import { DefaultChatTransport } from "ai";
const SourceDemo = () => {
const [input, setInput] = useState("");
const { messages, sendMessage, status } = useChat({
transport: new DefaultChatTransport({
api: "/api/sources",
}),
});
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (input.trim()) {
sendMessage({ text: input });
setInput("");
}
};
return (
);
};
export default SourceDemo;
```
Add the following route to your backend:
```tsx title="api/chat/route.ts"
import { convertToModelMessages, streamText, UIMessage } from "ai";
import { perplexity } from "@ai-sdk/perplexity";
// Allow streaming responses up to 30 seconds
export const maxDuration = 30;
export async function POST(req: Request) {
const { messages }: { messages: UIMessage[] } = await req.json();
const result = streamText({
model: "perplexity/sonar",
system: "You are a helpful assistant. Keep your responses short (< 100 words) unless you are asked for more details. ALWAYS USE SEARCH.",
messages: convertToModelMessages(messages),
});
return result.toUIMessageStreamResponse({
sendSources: true,
});
}
```
## Features
- Collapsible component that allows a user to view the sources or citations used to generate a response
- Customizable trigger and content components
- Support for custom sources or citations
- Responsive design with mobile-friendly controls
- Clean, modern styling with customizable themes
## Examples
### Custom rendering
## Props
### ``
',
},
}}
/>
### ``
',
},
}}
/>
### ``
',
},
}}
/>
### ``
',
},
}}
/>