--- title: 'Quick Start' description: 'Get Memory Graph running in 2 minutes' --- ## Basic Setup Here's a minimal example to get the graph running: ```tsx 'use client'; // For Next.js App Router import { MemoryGraph } from '@supermemory/memory-graph'; import type { DocumentWithMemories } from '@supermemory/memory-graph'; import { useEffect, useState } from 'react'; export default function GraphPage() { const [documents, setDocuments] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { fetch('/api/graph') .then(res => res.json()) .then(data => { setDocuments(data.documents); setIsLoading(false); }) .catch(err => { setError(err); setIsLoading(false); }); }, []); return (
); } ``` ## Backend API Route Create an API route to fetch documents from Supermemory: ```typescript Next.js App Router // app/api/graph/route.ts import { NextResponse } from 'next/server'; export async function GET() { 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', }), }); const data = await response.json(); return NextResponse.json(data); } ``` ```typescript Next.js Pages Router // pages/api/graph.ts import type { NextApiRequest, NextApiResponse } from 'next'; export default async function handler( req: NextApiRequest, res: NextApiResponse ) { 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', }), }); const data = await response.json(); res.json(data); } ``` ```javascript Express // routes/graph.js app.get('/api/graph', async (req, res) => { 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', }), }); const data = await response.json(); res.json(data); }); ``` Never expose your Supermemory API key to the client. Always fetch data through your backend. ## Environment Variables Add your API key to `.env.local`: ```bash SUPERMEMORY_API_KEY=your_api_key_here ``` Get your API key from the [Supermemory dashboard](https://console.supermemory.ai). ## Common Customizations ### Embedded Mode For a widget-style view, use the consumer variant: ```tsx ``` ### CSS Import The component includes bundled styles. You don't need to import CSS separately. Styles are automatically injected when the component mounts. If you want explicit control, you can import the stylesheet: ```typescript import '@supermemory/memory-graph/styles.css'; ``` The automatic CSS injection works for most setups. Only use the explicit import if you need custom control over style loading order. ### Custom Empty State Show custom content when no documents exist: ```tsx

No memories yet

Add content to see your knowledge graph

``` ### Hide Space Selector ```tsx ``` ## Next Steps See more usage examples Full API documentation