# Install (/docs/install)



The soil layer before the trellis goes up. Install paths organized
by what you already use: pick a package manager, pick a framework,
pick a provider. The wizard wraps all three; the manual snippets
are if you want to see what gets generated.

> **Not on npm yet.** The `@pleach/*` packages aren't on npm yet. Some names are reserved with `0.0.1` placeholders. Each package's first real release ships under FSL-1.1-Apache-2.0. The commands on this page describe the install once it lands. [Packages](/docs/packages) tracks each package's status.

## The wizard (recommended) [#the-wizard-recommended]

`npx @pleach/core init` detects your framework, asks four questions
(template, provider, plugin stub, schema scaffold), and writes a
starter project. Per-framework template matrix lives at
[CLI → `pleach init`](/docs/cli#pleach-init--the-wizard).

<Tabs items="['npm', 'pnpm', 'yarn', 'bun']" groupId="pkg">
  <Tab value="npm">
    ```bash
    npx @pleach/core init
    ```
  </Tab>

  <Tab value="pnpm">
    ```bash
    pnpm --package=@pleach/core dlx pleach init
    ```
  </Tab>

  <Tab value="yarn">
    ```bash
    yarn dlx -p @pleach/core pleach init
    ```
  </Tab>

  <Tab value="bun">
    ```bash
    bunx --package @pleach/core pleach init
    ```
  </Tab>
</Tabs>

Run `npm run dev` with a provider key set — there is no keyless
mode (with no key the scaffolded route refuses every turn with an
actionable "Set `<PROVIDER>_API_KEY`" message). The bundled
`/audit` view shows real rows from your first message. \~60 seconds
wall-clock.

## Manual: install `@pleach/core` [#manual-install-pleachcore]

<Tabs items="['npm', 'pnpm', 'yarn', 'bun']" groupId="pkg">
  <Tab value="npm">
    ```bash
    npm install @pleach/core
    ```
  </Tab>

  <Tab value="pnpm">
    ```bash
    pnpm add @pleach/core
    ```
  </Tab>

  <Tab value="yarn">
    ```bash
    yarn add @pleach/core
    ```
  </Tab>

  <Tab value="bun">
    ```bash
    bun add @pleach/core
    ```
  </Tab>
</Tabs>

## Manual: set a provider key [#manual-set-a-provider-key]

<ProviderTabs shape="env" />

The runtime auto-detects whichever key is set. Detection scans Anthropic, OpenAI and OpenRouter first,
then DeepSeek and Google, then Mistral and Moonshot. A DeepSeek or
Google key on its own streams from that vendor's own endpoint. A
Mistral or Moonshot key on its own is detected but has no built-in
stream, so the route answers 503 `no_provider_key` until you pass a
`providerStream`. To pin a provider explicitly (skipping
detection), pass `provider: "anthropic"` to `createPleachRoute()`.

## Manual: wire a route handler [#manual-wire-a-route-handler]

The same `createPleachRoute()` factory works in any fetch-based
Node.js server — App Router, Pages Router, Astro, SvelteKit, Remix, Hono,
Bun. Pick the framework you're on; the body is identical.

<Tabs items="['Next.js App', 'Next.js Pages', 'Astro', 'SvelteKit', 'Remix', 'Hono', 'Bun']" groupId="framework">
  <Tab value="Next.js App">
    ```typescript
    // app/api/chat/route.ts
    import { createPleachRoute } from "@pleach/core/quickstart";

    export const POST = createPleachRoute();
    ```
  </Tab>

  <Tab value="Next.js Pages">
    ```typescript
    // pages/api/chat.ts
    import { createPleachRoute } from "@pleach/core/quickstart";

    const handler = createPleachRoute();

    export const config = { api: { bodyParser: false } };

    export default async function POST(req, res) {
      const response = await handler(new Request(`http://x${req.url}`, {
        method: "POST",
        body: req as unknown as BodyInit,
      }));
      res.status(response.status);
      response.headers.forEach((v, k) => res.setHeader(k, v));
      if (response.body) {
        const reader = response.body.getReader();
        while (true) {
          const { value, done } = await reader.read();
          if (done) break;
          res.write(value);
        }
      }
      res.end();
    }
    ```
  </Tab>

  <Tab value="Astro">
    ```typescript
    // src/pages/api/chat.ts
    import type { APIRoute } from "astro";
    import { createPleachRoute } from "@pleach/core/quickstart";

    const handler = createPleachRoute();

    export const POST: APIRoute = ({ request }) => handler(request);
    ```
  </Tab>

  <Tab value="SvelteKit">
    ```typescript
    // src/routes/api/chat/+server.ts
    import { createPleachRoute } from "@pleach/core/quickstart";

    const handler = createPleachRoute();

    export const POST = ({ request }) => handler(request);
    ```
  </Tab>

  <Tab value="Remix">
    ```typescript
    // app/routes/api.chat.ts
    import { createPleachRoute } from "@pleach/core/quickstart";

    const handler = createPleachRoute();

    export const action = ({ request }) => handler(request);
    ```
  </Tab>

  <Tab value="Hono">
    ```typescript
    // src/index.ts — run Hono on Node.js
    import { serve } from "@hono/node-server";
    import { Hono } from "hono";
    import { createPleachRoute } from "@pleach/core/quickstart";

    const app = new Hono();
    const handler = createPleachRoute();

    app.post("/api/chat", (c) => handler(c.req.raw));

    serve({ fetch: app.fetch, port: 3000 });
    ```
  </Tab>

  <Tab value="Bun">
    ```typescript
    // server.ts
    import { createPleachRoute } from "@pleach/core/quickstart";

    const handler = createPleachRoute();

    Bun.serve({
      port: 3000,
      fetch(req) {
        const url = new URL(req.url);
        if (url.pathname === "/api/chat" && req.method === "POST") {
          return handler(req);
        }
        return new Response("Not found", { status: 404 });
      },
    });
    ```
  </Tab>
</Tabs>

## What this gives you [#what-this-gives-you]

A streaming chat handler at `POST /api/chat` that accepts
`{ sessionId?, message }` JSON and streams `StreamEvent`s back as
SSE. No persistence, no plugins, no domain customization — the
runtime returns a substrate placeholder until you adopt a
[storage adapter](/docs/storage) and (optionally) a
[plugin](/docs/plugin-contract).

There is no keyless mode: with no provider key the route refuses
every turn with the actionable "Set `<PROVIDER>_API_KEY`" message —
a canned answer is never served. The wizard scaffolds the same
key-required route, with an `/audit` view to read the rows.

For the React side — `useChat()`, `<ChatBox />`, both on
`@pleach/core/quickstart/react` — see
[Getting started](/docs/getting-started). For a production-shape
handler with custom storage, plugins, and provider pinning, see
[Getting started → Custom storage, plugins, or provider pinning](/docs/getting-started#custom-storage-plugins-or-provider-pinning).

## Optional peer dependencies [#optional-peer-dependencies]

`@pleach/core` installs with no optional peers. Four surfaces load
theirs by dynamic import and fail with a named error naming the
package, rather than a module-resolution stack — so a consumer who
never reaches for the surface never installs the dependency.

| Install when you use                                                                                                     | Packages                                                             |
| ------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------- |
| [CMS attestation envelopes](/docs/attestation#the-cms-envelope) (`@pleach/core/attestation/cms`)                         | `@peculiar/asn1-schema`, `@peculiar/asn1-cms`, `@peculiar/asn1-x509` |
| [Role-based approval flows](/docs/rbac-contract) (`@pleach/core/rbac`)                                                   | `@pleach/rbac-contract`                                              |
| An MCP server or client from core                                                                                        | `@modelcontextprotocol/sdk`                                          |
| [RFC 3161 receipt verification](/docs/attestation#verifying-the-token-pleachcompliance) (`@pleach/compliance/timestamp`) | `@sigstore/core`                                                     |

The failure is designed to be readable. Missing ASN.1 peers surface as
`CmsAttestationError("asn1-peer-missing")`; a missing `@sigstore/core`
makes `verifyRfc3161Receipt` return `{ verified: false, reason:
"verifier-unavailable" }` rather than throwing — an unverifiable
receipt and an unavailable verifier are different facts, and the
result says which one you have.

## Where to go next [#where-to-go-next]

<Cards>
  <Card title="Getting started" href="/docs/getting-started" description="The end-to-end 60-second walkthrough — install, env, route handler, page." />

  <Card title="Which SKU do I need?" href="/docs/which-sku" description="Most projects need three or four packages. The shortest install list for what you're building." />

  <Card title="Runtime construction" href="/docs/runtime-construction" description="When you need to drop below the route handler — SessionRuntime constructor + createPleachRuntime factory." />

  <Card title="Storage" href="/docs/storage" description="Memory, IndexedDB, Supabase, Postgres — when to use which adapter." />
</Cards>
