PerSQL

The database for AI agents.

Branch-per-agent. Cost-per-call. Handoff in one line. Spawn an isolated SQLite database for every agent run, every sub-agent task, every PR — free until queried, billed only on the queries and storage they actually use.

Works with Claude, ChatGPT, Cursor, LangGraph, Mastra, and any MCP client.

agent.ts Discoverability + cost
// One DB per agent run. Free until queried.
import { PerSQL } from "@persql/sdk";

const persql = new PerSQL({ token: process.env.PERSQL_TOKEN! });
const db = persql.database("acme/orders");

// Step 1 — agent learns the schema (one round-trip).
const schema = await db.describe();

// Step 2 — runs SQL, gets cost back on every response.
const { data, meta } = await db.query<{ id: number; email: string }>(
  "SELECT id, email FROM customers WHERE id = ?", [42]
);
console.log(meta?.costUsd); // self-throttle on the way out
handoff.ts Multi-agent
// Sub-agent delegation — single-use, scoped, expires.
const { token } = await db.branches.pin("pr-42", {
  role: "write",
  ttlSec: 900,                  // 15 min
});

// Hand to a sub-agent — it never sees the parent token.
const sub = await PerSQL.fromHandoff(token);
const subDb = sub.database(sub.handedOff.namespaceSlug, sub.handedOff.databaseSlug);
await subDb.query("INSERT INTO leads (email) VALUES (?)", ["a@b.co"]);

Built for the agent loop

Every primitive — branches, scoped tokens, cost telemetry, schema search, snapshots — exists to make autonomous SQL safe and cheap. No agent framework to lock into. Just a database that's shaped right.

One DB per agent run

Spawn a fresh database — or a branch off prod — for every Claude/GPT/Cursor task. Free until queried; auto-clean with expiresAt.

Scoped handoff tokens

Mint a phand_… token pinned to (database, branch, role). Single-use, max 24h. Sub-agents never touch your master key.

Cost on every response

/v1/query and /v1/batch return meta.costUsd. Your agent decides when to stop — no polling a usage endpoint mid-loop.

Auto-snapshot before destructive ops

DROP, TRUNCATE, REPLACE, unbounded DELETE — automatically labeled into the 30-day PITR history. Restore is one call.

MCP-first

Plug PerSQL into Claude Desktop, Cursor, or any MCP client. ~40 tools: query, describe_database, search_schema, schema_doctor, pin_branch, claim_handoff.

Schema discoverability

describe() returns the whole graph + docs in one call. search() finds tables by intent ("customer billing addresses"). doctor() lints for LLM-hostile patterns.

Query log inside the DB

Every call writes to _persql_meta_query_log. Agents JOIN, GROUP BY, or subscribe to their own audit trail with plain SQL.

Branches as a primitive

PUT /branches/:ref is idempotent — call it on every PR push. Vectors, blobs, custom domains, sharing — none gated by plan.

Drop-in for Drizzle / Kysely

db.driver() returns the sqlite-proxy callback Drizzle expects. persql-codegen emits a typed Drizzle schema from a live DB.

Local mode for tests

new PerSQL({ local: ":memory:" }) — query/batch/tables/explain run via better-sqlite3. Agent recipes work in CI without a token.

Vectors + blobs, isolated per DB

Hybrid SQL + Vectorize for semantic search; R2-backed blob store for anything bigger than a SQLite cell. Same isolation boundary.

Edge-native

Each database is a Cloudflare Durable Object — embedded SQLite, migrates to the caller, sub-5ms reads from the right region.

From SQL to AI agents in one stack

Reach for the surface that fits the task: a web console for humans, an SDK for your app, a CLI for your terminal, an MCP server for your agent, public HTTP endpoints for everyone else.

Console SDK CLI MCP REST Endpoints

Pricing — only what you use

Two meters. No seat fees, no per-database fees, no plan-tier feature gates. Spawn as many databases and branches as you want — they cost nothing until they actually run queries or store data.

Per query

Every read or write across /v1 and the SDK is metered identically, regardless of which database or branch it hits.

Per stored GB

Storage rolls up across all your databases and branches. An empty branch costs nothing.

Everything else: $0

Branches, forks, snapshots, vectors, blobs, custom domains, MCP, public endpoints — all included. Plan tiers only change rate-limit headroom and support level.