Upstreet Docs
    Examples

    Step-by-step tutorial to create a wiki project, configure settings, save and retrieve pages, view revision history, and access via URL or CLI.

    Build an AI Wiki

    This tutorial guides you through creating a wiki project, configuring AI and visibility settings, saving and retrieving pages, viewing revision history, and accessing content via the web URL or CLI.


    Prerequisites

    Install pu-client and get your API key from Account > Developer. Set PU_API_KEY in your environment.


    Step-by-Step Tutorial

    1. Create a wiki project

    const project = await client.wiki.projects.create({
      name: 'my-world',
      visibility: 'public',
      editability: 'private',
    });

    Use the SDK for project creation. The CLI focuses on listing and viewing pages—see step 7.

    2. Configure project settings

    Set the text model, image model, and project prompt for AI-assisted generation:

    await client.wiki.projects.update({
      id: project.id,
      text_model: 'gpt-4o',
      image_model: 'flux-1-1-pro',
      project_prompt: 'A fantasy world with elves, dragons, and ancient ruins.',
      web_search_enabled: true,
    });

    3. Save a page

    Pages are organized by type (e.g. characters, locations) and name:

    await client.wiki.savePage({
      type: 'characters',
      name: 'Hero',
      project_id: project.id,
      markdown: `# Hero
    
    A brave adventurer who wields the Sword of Dawn.
    
    ## Backstory
    Raised in the northern villages, Hero discovered their calling when...`,
      embedding: null,
      change_summary: 'Initial character page',
    });

    4. Get a page

    Fetch the current (latest) version of a page:

    const page = await client.wiki.getCurrent({
      type: 'characters',
      name: 'Hero',
      projectId: project.id,
    });
    
    console.log(page.markdown);

    5. View revision history

    const history = await client.wiki.getHistory({
      type: 'characters',
      name: 'Hero',
      projectId: project.id,
    });
    
    history.forEach(rev => {
      console.log(`Revision ${rev.id}: ${rev.created_at}`);
    });

    6. Access via URL

    Once your project is public, pages are available at:

    /wiki/my-world/characters/Hero

    Or via the API:

    /api/wiki/my-world/characters/Hero

    7. CLI access

    puc wiki list
    puc wiki list my-world
    puc wiki go my-world/characters/Hero

    Full SDK Example

    import { PUClient } from 'pu-client';
    
    async function buildWiki() {
      const client = new PUClient({ apiKey: process.env.PU_API_KEY! });
    
      const project = await client.wiki.projects.create({
        name: 'my-world',
        visibility: 'public',
      });
    
      await client.wiki.projects.update({
        id: project.id,
        project_prompt: 'A dark fantasy setting.',
        web_search_enabled: true,
      });
    
      await client.wiki.savePage({
        type: 'characters',
        name: 'Hero',
        project_id: project.id,
        markdown: '# Hero\n\nA legendary warrior.',
        embedding: null,
      });
    
      const page = await client.wiki.getCurrent({
        type: 'characters',
        name: 'Hero',
        projectId: project.id,
      });
    
      const history = await client.wiki.getHistory({
        type: 'characters',
        name: 'Hero',
        projectId: project.id,
      });
    
      console.log(`Page saved. Revisions: ${history.length}`);
      console.log(`View at: /wiki/${project.name}/characters/Hero`);
    }

    Get Resolved Content

    For fully expanded content (templates, references resolved), use getResolved:

    const content = await client.wiki.getResolved({
      projectName: 'my-world',
      type: 'characters',
      name: 'Hero',
      format: 'markdown',  // or 'html', 'json'
    });

    Next Steps