Skip to navigation

Build an AI-Native App

Database + AI agent + file storage in under 50 lines

Set up a Postgres database, AI assistant, and file storage in under 50 lines of code.

Prerequisites

Install

npm install @recursiv/sdk

Set up environment

export RECURSIV_API_KEY=sk_live_xxx
export RECURSIV_ORG_ID=your-org-id

The code

import { Recursiv } from '@recursiv/sdk'
const r = new Recursiv()
const ORG_ID = process.env.RECURSIV_ORG_ID!
async function main() {
// 1. Create a project (container for your infra)
const { data: project } = await r.projects.create({
name: 'my-app',
organization_id: ORG_ID,
})
console.log('Project:', project.id)
// 2. Provision a Postgres database
const { data: db } = await r.databases.ensure({
name: 'my-app-db',
project_id: project.id,
})
const { data: creds } = await r.databases.getCredentials({
project_id: project.id,
name: 'my-app-db',
})
console.log('Database ready:', creds.connection_string)
// 3. Run a migration in a sandbox
await r.projects.createSandbox(project.id)
await r.projects.executeCode(project.id, {
code: `
const { Client } = require('pg');
const c = new Client({ connectionString: '${creds.connection_string}' });
await c.connect();
await c.query(\`
CREATE TABLE IF NOT EXISTS items (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
category TEXT,
created_at TIMESTAMPTZ DEFAULT NOW()
)
\`);
console.log('Migration complete');
await c.end();
`,
language: 'typescript',
})
// 4. Create an AI assistant
const { data: agent } = await r.agents.create({
name: 'App Assistant',
username: 'assistant_' + Date.now(),
model: 'anthropic/claude-sonnet-4.6',
system_prompt: 'You help users manage their items. Be concise and helpful.',
organization_id: ORG_ID,
})
console.log('Agent:', agent.id)
// 5. Set up file storage
const { data: bucket } = await r.storage.ensureBucket({
name: 'app-uploads',
project_id: project.id,
})
console.log('Storage bucket:', bucket.name)
// 6. Stream a chat with the agent
process.stdout.write('Agent: ')
for await (const chunk of r.agents.chatStream(agent.id, {
message: 'What kinds of items should I track?',
})) {
process.stdout.write(chunk.delta ?? '')
}
console.log()
}
main()

What just happened

In ~50 lines you provisioned:

  • A Postgres database with a schema
  • An AI agent powered by Claude
  • A file storage bucket
  • All managed by Recursiv — no AWS, no Docker, no separate backend

Next steps

  • Add auth with r.auth.signUp() / r.auth.signIn()
  • Give the agent database access with r.agents.grantProjectAccess()
  • Deploy with r.projects.deploy()
  • Upload files with r.storage.getUploadUrl()