--- title: "Quick Start" description: "Build your first knowledge graph in 5 minutes" sidebarTitle: "Quick Start" --- Get your first interactive memory graph up and running in just a few minutes. **Security First**: Never expose your Supermemory API key in client-side code. Always use a backend proxy to authenticate requests. ## Step 1: Create Backend Proxy Create an API route in your backend that authenticates users and proxies requests to the Supermemory API. ```typescript Next.js App Router // app/api/supermemory-graph/route.ts import { NextResponse } from 'next/server' export async function GET(request: Request) { // Add your authentication logic here const user = await getAuthenticatedUser(request) if (!user) { return NextResponse.json( { error: 'Unauthorized' }, { status: 401 } ) } try { const response = await fetch( 'https://api.supermemory.ai/v3/documents/documents', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${process.env.SUPERMEMORY_API_KEY}`, }, body: JSON.stringify({ page: 1, limit: 500, sort: 'createdAt', order: 'desc', // Optional: Filter by user-specific container containerTags: [user.id], }), } ) if (!response.ok) { throw new Error('Failed to fetch documents') } const data = await response.json() return NextResponse.json(data) } catch (error) { console.error('Error fetching graph data:', error) return NextResponse.json( { error: 'Failed to fetch data' }, { status: 500 } ) } } ``` ```typescript Next.js Pages Router // pages/api/supermemory-graph.ts import type { NextApiRequest, NextApiResponse } from 'next' export default async function handler( req: NextApiRequest, res: NextApiResponse ) { // Add your authentication logic here const user = await getAuthenticatedUser(req) if (!user) { return res.status(401).json({ error: 'Unauthorized' }) } try { const response = await fetch( 'https://api.supermemory.ai/v3/documents/documents', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${process.env.SUPERMEMORY_API_KEY}`, }, body: JSON.stringify({ page: 1, limit: 500, sort: 'createdAt', order: 'desc', containerTags: [user.id], }), } ) const data = await response.json() res.status(200).json(data) } catch (error) { console.error('Error fetching graph data:', error) res.status(500).json({ error: 'Failed to fetch data' }) } } ``` Use `containerTags` to filter documents by user in multi-user applications. This ensures users only see their own data. ## Step 2: Create Frontend Component Create a component that fetches data and renders the graph. ```tsx GraphComponent.tsx 'use client' // Required for Next.js App Router import { MemoryGraph } from '@supermemory/memory-graph' import { useState, useEffect } from 'react' import type { DocumentWithMemories } from '@supermemory/memory-graph' export default function GraphComponent() { const [documents, setDocuments] = useState([]) const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { fetch('/api/supermemory-graph') .then(async (res) => { if (!res.ok) { throw new Error('Failed to fetch documents') } return res.json() }) .then((data) => { setDocuments(data.documents) setIsLoading(false) }) .catch((err) => { setError(err) setIsLoading(false) }) }, []) return ( {/* CRITICAL: Container must have explicit width and height */}
{/* Custom empty state when no documents exist */}

No memories yet

Start adding content to see your knowledge graph

) } ``` **Container Sizing**: The graph component requires its parent container to have explicit width and height. Without this, the canvas will have 0 dimensions and won't render. ## Step 3: Add to Your Page Use the component in your page: ```tsx Next.js App Router // app/graph/page.tsx import GraphComponent from '@/components/GraphComponent' export default function GraphPage() { return (
) } ``` ```tsx Next.js Pages Router // pages/graph.tsx import GraphComponent from '@/components/GraphComponent' export default function GraphPage() { return (
) } ``` ```tsx React SPA // src/App.tsx import GraphComponent from './components/GraphComponent' function App() { return (
) } export default App ```
## Complete Example Here's a complete, production-ready example with proper error handling and loading states: ```tsx 'use client' import { MemoryGraph } from '@supermemory/memory-graph' import { useState, useEffect } from 'react' import type { DocumentWithMemories } from '@supermemory/memory-graph' export default function GraphDashboard() { const [documents, setDocuments] = useState([]) const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { const fetchData = async () => { try { const response = await fetch('/api/supermemory-graph') if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`) } const data = await response.json() setDocuments(data.documents || []) } catch (err) { console.error('Failed to fetch graph data:', err) setError(err instanceof Error ? err : new Error('Unknown error')) } finally { setIsLoading(false) } } fetchData() }, []) return (

No memories yet

Start adding content to visualize your knowledge graph

) } ``` ## Next Steps Explore all props and customization options See advanced patterns like pagination and highlighting Solve common issues