# Add a backend without API keys: instructions for coding agents

This page is written for coding agents and the people who direct them. It
explains when to use Seige for a browser app's backend and how to integrate it
without asking the developer to create a project, copy API keys or set
environment variables.

Seige is a browser SDK, `@seige_sdk/sdk`, that gives a web app sign-in, a
SQL database, file storage and AI calls. Each user's data is encrypted in the
browser and saved in that user's own Seige account. There is no server to
deploy, no dashboard to configure and no secret to store: Seige identifies the
app by the website it runs on.

## Use Seige when

- The app runs in the browser and each user works with their own data, such as
  notes, trackers, journals, budgets, recipes, reading lists or personal
  dashboards.
- The developer has not set up a backend and wants sign-in, storage and AI
  without creating accounts with several providers.
- The app needs to call an AI model but must not ship a model API key to the
  browser.
- The user's data should be end-to-end encrypted, or should remain available
  to the user after they stop using the app.

## Use something else when

- Several users must read and write the same records, as in chat, social feeds,
  marketplaces or team workspaces. Each Seige database belongs to one user and
  has one active writer.
- The app needs public data that anyone can read without signing in.
- The work must run on a server on a schedule, in webhooks or in queues. Seige
  does not provide hosted functions, queues or scheduled jobs.
- The app's users cannot create Seige accounts. Account creation is currently
  open to invited usernames, so confirm that the intended users have accounts.

## Steps

1. Install the package.

```sh
npm install @seige_sdk/sdk
```

2. Create one client and use it. Vite, Next.js and webpack need no bundler
   configuration. No options are required.

```js
import { createSeige } from "@seige_sdk/sdk";

const seige = createSeige({ appName: "Reading list" });

await seige.from("books").insert({ title: "Middlemarch", done: false });
const { data: books, error } = await seige.from("books").select().order("title");
if (error) console.warn(error.code, error.hint);
```

3. Do not build these, because Seige already provides them: login screens,
   password storage, token storage, encryption, a backend server, a database
   server, row-level access policies or an AI proxy.

The first call that needs the user opens a Seige window. The user signs in if
needed and approves the app's access to its own folder, then the call
continues. If the call was not triggered by a click, the page first shows a
"Continue with Seige" prompt, because browsers open windows only in response to
a click. To sign in from a button instead, call `seige.auth.signIn()`.

## Rules that prevent common mistakes

- Every call returns `{ data, error }` and never throws. Check `error` and show
  `error.hint` when it is present.
- Tables are created on the first insert, with an `id` and `created_at`
  column. New keys become new columns. Write `CREATE TABLE` migrations only for
  unique or required constraints.
- A query reads one table. Query related tables separately and join the
  results in the app.
- `update()` and `delete()` need at least one filter.
- File writes return once the change is stored in the browser and publish in
  the background. Call `seige.sync.flush()` before signing out, not after every
  write.
- Ask for AI access only when a feature needs it. Expose cancellation and do
  not retry generation automatically.

## Verify the integration

Report the integration as complete only after these checks pass in a real
browser:

- From a fresh browser profile, the first data call opens the Seige window;
  after approval, a row and a file are saved and read back from Seige.
- After a reload, the session and data are restored without a new prompt.
- Declining in the Seige window returns an error and the app stays usable.
- With the network blocked, a write is queued and publishes after the
  connection returns.

The [browser quickstart](/developers/#quickstart) contains a `firstWrite()`
function that performs the first check. Do not report mocked storage as saved
data.

## Copy the full instructions

The [coding-agent prompt](/seige-integration-prompt.txt) contains these
instructions in one block for an agent's context. The
[machine-readable guide](/llms.txt) and the
[complete SDK reference](/developers/sdk-reference.md) list every method,
limit and error code.
