Getting started
Authentication
The two credentials
| Ingest key | Agent token | |
|---|---|---|
| Looks like | 1db_ + 32 hex characters | 1db_at_… |
| Sent as | X-API-Key header | Authorization: Bearer header |
| Works on | POST /v1/leads only | /v1/agent/* and the MCP server |
| Can | Create leads for its website | Manage websites, forms, leads and routing, within its scopes |
| Lives in | The website's project and its host's env vars | Your user config, never a project |
| Made by | 1DB, when the website is created | A person, in Settings or by approving npx @1db/cli setup |
Where the ingest key goes
The ingest key can only create leads, so it is designed to be safe in browser code: the embed script puts it in the page. A server route is still the better default, because it can:
- pass on the visitor's IP and browser (
X-1DB-Client-IP,X-1DB-Client-UA), so visitors don't share one rate limit; - retry a failed post with the same
submission_id; - keep the key out of view, so nobody copies it to post junk leads.
Keep the variables unprefixed on the server: DB_API_ENDPOINT, DB_API_KEY, DB_FORM_SLUG. If the browser posts directly, the public prefix is fine: NEXT_PUBLIC_DB_API_KEY, VITE_DB_API_KEY.
export async function POST(request: Request) {
const fields = await request.json(); // { formSlug?, email, name, ... } flat
const response = await fetch(`${process.env.DB_API_ENDPOINT}/v1/leads`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": process.env.DB_API_KEY!,
"X-1DB-Client-IP": request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ?? "",
"X-1DB-Client-UA": request.headers.get("user-agent") ?? "",
},
body: JSON.stringify({ ...fields, formSlug: process.env.DB_FORM_SLUG }),
});
// Pass 1DB's answer through: { success, leadId } or { error, code, hint }
return new Response(await response.text(), {
status: response.status,
headers: { "Content-Type": "application/json" },
});
}Replacing a key
A website can have more than one key. To replace one, create a new key for the website in Settings → API keys (or with issue_ingest_key when every key was revoked), put it in the host's env vars, redeploy, send one lead, then revoke the old key. A key revoked before the site uses the new one makes every lead fail with INVALID_API_KEY.
Agent tokens
Only a person can create an agent token: in Settings → API keys → Agent tokens, or by approving npx @1db/cli setup in the browser. A token acts as the admin who made it, limited to its scopes, and stops working the moment it is revoked.
For AI agents
If you don't have an agent token, ask your user for one. Don't try to sign up or sign in to 1DB yourself, and never write a 1db_at_ token into a project.
Setup, scopes and the MCP server are in AI agents, MCP and CLI. Endpoints and error codes are in the API reference.