# Astro



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

# Overview

Use Astro with React islands to render AskAI where you need it, without turning the whole site into React.
The API route lives in `src/pages/api/peam.ts`, keeping server logic clean and scoped.
You get fast pages with a focused, AI-ready experience.

<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 in the Base Layout

    ```astro
    ---
    import { AskAI } from 'peam/client';
    import '../styles/global.css';

    interface Props {
      title: string;
      description?: string;
    }

    const { title, description } = Astro.props as Props;
    ---

    <html lang="en">
      <head>
        <!-- ... -->
      </head>
      <body class="antialiased">
        <!-- ... -->
        <slot />
        <!-- [!code highlight] -->
        <AskAI client:only="react" />
      </body>
    </html>
    ```
  </Step>

  <Step>
    ## Add the API Route

    Create `src/pages/api/peam.ts` and add:

    ```ts
    // [!code highlight]
    export { POST } from 'peam/server';
    export const prerender = false;
    ```
  </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/astro-react" external>
    examples/astro-react
  </Link>

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

## Customize the model

Define your own handler and pass a model to `createChat`. 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';

export const POST = createChat({
  model: openai('gpt-4o-mini'),
}).handler;
```


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