> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.recursiv.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.recursiv.io/_mcp/server.

# AI App Template

## What it is

A full app scaffold for a product with users. It comes with authentication, a Postgres database, an AI agent your users can chat with, and a one-call deploy. Pick Next.js for a data-dense web app or Expo for mobile.

## What it includes

| Piece        | What it does                                                     |
| ------------ | ---------------------------------------------------------------- |
| Scaffold     | A Recursiv starter repo (`nextjs` or `expo`) created server side |
| Auth         | Passwordless plus OAuth sign-in, sessions, scoped per-user keys  |
| Database     | A Postgres database for your app data                            |
| Agent        | A model-agnostic agent (any supported model) with streaming chat |
| Deploy       | A production deploy from the linked GitHub repo                  |
| Integrations | Optional access to hundreds of data integrations as tools        |

## How to start it

Scaffold a repo server side, create a project against it, then provision the rest. No local git or GitHub account required.

```bash
npm install @recursiv/sdk
export RECURSIV_API_KEY=sk_live_...
```

```typescript
import { Recursiv } from '@recursiv/sdk';

const r = new Recursiv();

// 1. Scaffold a starter repo. Templates: 'nextjs' | 'expo'
const { data: repo } = await r.github.createFromTemplate({
  template: 'nextjs',
  name: 'my-ai-app',
});

// 2. Create the project linked to that repo
const { data: project } = await r.projects.create({
  name: 'my-ai-app',
  repo_url: repo.repo_url,
});

// 3. Provision a database
await r.databases.ensure({ project_id: project.id, name: 'main' });

// 4. Create the agent
const { data: agent } = await r.agents.create({
  project_id: project.id,
  name: 'App Assistant',
  model: 'anthropic/claude-sonnet-4.6',
  system_prompt: 'You help users get things done in this app. Be concise.',
});
```

## Add auth

Sign users up and in, then mint a short-lived scoped key per session instead of shipping a long-lived key.

```typescript
const session = await r.auth.signUp({ email, password });

const apiKey = await r.auth.createApiKey(
  { name: 'web-session', scopes: ['agents:read', 'agents:write', 'databases:read'] },
  session.token,
);
```

## Stream the agent to your UI

In Next.js and browsers, `chatStream()` yields `{ delta }` chunks. In Expo, use `chatStreamText()`.

```typescript
for await (const chunk of r.agents.chatStream(agent.id, { message })) {
  process.stdout.write(chunk.delta ?? '');
}
```

## Deploy

Deploys build from the linked GitHub repo.

```typescript
const { data: deployment } = await r.projects.deploy(project.id, {
  branch: 'main',
  type: 'production',
});

console.log(deployment.deployment_url);
```

## Key SDK calls

* `r.github.createFromTemplate({ template, name })` - scaffold the repo
* `r.projects.create({ name, repo_url })` - the project
* `r.databases.ensure({ project_id, name })` - app database
* `r.auth.signUp(...)`, `r.auth.signIn(...)`, `r.auth.createApiKey(...)` - auth and scoped keys
* `r.agents.create({ project_id, model, instructions })` - the agent
* `r.agents.chatStream(agentId, { message })` / `r.agents.chatStreamText(...)` - stream to your UI
* `r.projects.deploy(projectId, { branch, type })` - ship it

## Next steps

* [Build an AI-Native App](/guides/build/build-an-ai-native-app) for the full walkthrough
* [Connect Next.js](/integrations/connect/connect-nextjs) or [Connect React Native](/integrations/connect/connect-react-native)
* [API Reference](/api-reference) for every endpoint