Learn how to build a Perplexity-style search app with generative UI using Thesys C1
Build your own AI-powered search engine that generates beautiful, interactive UI instead of just returning links. This guide teaches you the architecture and techniques behind apps like Perplexity and Google AI Search.
THESYS_API_KEY=your_thesys_api_key# Choose one search providerEXA_API_KEY=your_exa_api_key# ORGOOGLE_GEMINI_API_KEY=your_gemini_api_key# Optional: For image searchGOOGLE_API_KEY=your_google_api_keyGOOGLE_CSE_ID=your_custom_search_engine_id
We recommend Exa for better neural search results. Get your API key from exa.ai.
The system prompt determines how C1 generates UI. Here’s a proven pattern for search apps:
Copy
Ask AI
const SYSTEM_PROMPT = `You are a visual search AI assistant. Your mission is to provide visually-rich answers.Today is ${new Date().toLocaleDateString()}.**Core Directives:**1. **Always Search First:** Use your web search tool for every query to get current information.2. **Be Visual:** For any visual topic (places, products, people), MUST use images. - Use Image component for single images - Use ImageGallery for multiple related images - Add images to every ListItem when showing visual things3. **Visualize Data:** Use tables and charts for statistics, comparisons, and numbers.4. **Structure Content:** Use headings, lists, and sections to organize information clearly.5. **Add Follow-ups:** Always include 2-4 follow-up questions to continue the conversation.**Image Rules:**- Leave src/imagesSrc/imageSrc fields EMPTY (images are added automatically)- Provide detailed alt text describing what should be shown- Examples: "Eiffel Tower illuminated at night", "Graph showing Tesla stock price"Remember: A great search response is a visual response.`;
The key is being specific about when to use visual components and how to structure them. Vague prompts lead to inconsistent results.
The C1 SDK handles images automatically through a searchImage callback:
Frontend (React)
Copy
Ask AI
import { C1Component } from "@thesysai/genui-sdk";// Your image search function (calls your backend)const imageSearch = async (query: string) => { const response = await fetch("/api/search/image", { method: "POST", body: JSON.stringify({ query }), }); return response.json(); // { url: "...", thumbnailUrl: "..." }};// Pass searchImage to C1Component<C1Component c1Response={response} searchImage={imageSearch} // SDK calls this when it needs images/>
The flow:
Backend C1 generates image components with descriptive alt text (e.g., alt="Eiffel Tower at sunset")
C1 SDK detects images with empty src attributes
SDK automatically calls your searchImage(altText) function
Your function fetches the actual image URL from your /api/search/image endpoint
SDK updates the component with the real image URL
You don’t need to manually handle image fetching - just provide the searchImage callback to C1Component.
The searchImage callback gives you flexibility: use Google Images, Unsplash, Pexels, or your own image CDN. The SDK just needs a function that takes a query string and returns { url, thumbnailUrl }.
User: "What are the best restaurants in Tokyo?"AI: [Shows image gallery + list of restaurants]User: "Which one has the best sushi?"AI: [References previous results, shows specific sushi restaurants]
Without threads, the second question would fail because the AI has no context from the first search.
Production tip: Use Redis or a database for thread storage instead of in-memory. In-memory storage is lost when your server restarts. The search-with-c1 repo includes Redis integration examples.
Tool calling lets the LLM decide when to search and what to search for. The LLM might reformulate the query, do multiple searches, or skip searching if it has enough context from conversation history.
Exa vs Gemini: Which should I use?
Exa: Best for deep content analysis. Returns full page text for the LLM to process.
Gemini: Faster and cheaper. Built-in search grounding with automatic result synthesis.
Many apps let users choose (see the live demo).
How does C1 know what UI to generate?
C1 analyzes the content + your system prompt. If content contains images, lists, or data, and your prompt encourages visual components, C1 will generate appropriate UI. The better your prompt, the better the UI.
Can I add my own data sources?
Yes! Create additional tools for databases, APIs, or documents. C1 can combine web search with your private data.