# Vite



import { Step, Steps } from 'fumadocs-ui/components/steps';
import Link from 'fumadocs-core/link';

# Overview

Add Peam to a Vite + React SSR app by mounting AskAI in your layout and wiring a simple API route.
Your server calls `createChat()` per request, while the client streams results from `/api/peam`.
It’s a lightweight setup that keeps your stack fast and flexible.

<Steps>
  <Step>
    ## Install Dependencies

    <CodeBlockTabs defaultValue="npm">
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="npm">
          npm
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="pnpm">
          pnpm
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="yarn">
          yarn
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="bun">
          bun
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="npm">
        ```bash
        npm install peam
        ```
      </CodeBlockTab>

      <CodeBlockTab value="pnpm">
        ```bash
        pnpm add peam
        ```
      </CodeBlockTab>

      <CodeBlockTab value="yarn">
        ```bash
        yarn add peam
        ```
      </CodeBlockTab>

      <CodeBlockTab value="bun">
        ```bash
        bun add peam
        ```
      </CodeBlockTab>
    </CodeBlockTabs>
  </Step>

  <Step>
    ## Add AskAI to the Root Layout

    ```tsx
    export { Layout };

    import { AskAI } from 'peam/client';
    import type { ReactNode } from 'react';
    import '../index.css';

    function Layout({ children }: { children: ReactNode }) {
      return (
        <html lang="en">
          <head>
            {/* ... */}
          </head>
          <body>
            {/* ... */}
            {children}
            // [!code highlight]
            <AskAI />
          </body>
        </html>
      );
    }
    ```
  </Step>

  <Step>
    ## Add an API Endpoint in the Express Server

    The server handler is built with `createChat()` from `peam/server` and invoked per request.

    Create or edit `api/server.ts` and add the /api/peam route:

    ```ts
    import { createChat } from 'peam/server';

    // ... Express setup

    const chat = createChat();

    // [!code highlight]
    app.post('/api/peam', async (req, res) => {
      // ... convert to Request
      const response = await chat.handler(request);
      // ... stream response
    });

    // ... server startup
    ```
  </Step>

  <Step>
    ## Export the OpenAI API Key

    Peam uses ChatGPT (OpenAI GPT-4o) by default, so `OPENAI_API_KEY` must be set in your environment.

    ```bash
    export OPENAI_API_KEY="your-api-key"
    ```
  </Step>
</Steps>

## Examples

Browse the full app in:

* <Link href="https://github.com/peam-ai/peam/tree/main/examples/vite-react" external>
    examples/vite-react
  </Link>

See the [API Reference](/docs/api-reference) for all available options.

## Customize the model

Pass a custom model to `createChat` when wiring your route. Peam uses the Vercel AI SDK, so import models from the provider package you choose. See the <Link href="https://ai-sdk.dev/docs/foundations/providers-and-models" external>providers and models guide</Link>.

```ts
import { createChat } from 'peam/server';
import { openai } from '@ai-sdk/openai';

const chat = createChat({
  model: openai('gpt-4o-mini'),
});
```


## Sitemap
[Overview of all docs pages](/sitemap.md)
