> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kupe.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Databases

> Call databases — post-call tables, columns, attach agents, rows, export, and destinations. Knowledge bases for RAG.

**Call databases** are tables of structured data extracted after every attached agent's call. They are not a generic SQL store and not the knowledge base.

* **Databases** — one row per finished call (web, inbound, outbound).
* **Knowledge bases** — files for mid-call RAG search.

Requires `feature_databases`. Console: **Monitor → Databases**, or attach a database on the agent editor.

## How a row is written

1. Create a database with a name and columns (`fields`).
2. Attach one or more agents.
3. When a call hangs up, Kupe runs post-call extraction and inserts **one row per session**.

Always-present columns:

| Column | Meaning |
| - | - |
| `who_called` | Caller phone or web participant |
| `direction` | `inbound` (incoming), `outbound`, or `web` |
| `started_at` | Call start |
| `duration_seconds` | Length |

Schema you define, plus built-in analysis fields `summary` (string) and `success` (boolean). Custom fields:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{ "name": "promise_date", "type": "string", "description": "Date they promised to pay" }
```

`type` is `string` | `number` | `boolean` | `enum` (enum needs `enum_values`). Unique on `(database_id, session_id)`.

## Create and attach

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from kupe import Kupe

client = Kupe()
db = client.databases.create(
    name="Collections outcomes",
    description="Promise dates from EMI calls",
    fields=[
        {"name": "promise_date", "type": "string", "description": "Date they promised to pay"},
        {"name": "amount", "type": "number", "description": "Amount confirmed"},
        {
            "name": "intent",
            "type": "enum",
            "description": "Will pay / dispute / DND",
            "enum_values": ["will_pay", "dispute", "dnd"],
        },
    ],
)
client.databases.attach_agent(db.id, agent_id="agt_...")
rows = client.databases.rows(db.id, q="pending")
```

```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { Kupe } from "kupe-sdk";

const kupe = new Kupe();
const db = await kupe.databases.create({
  name: "Collections outcomes",
  description: "Promise dates from EMI calls",
  fields: [
    { name: "promise_date", type: "string", description: "Date they promised to pay" },
    { name: "amount", type: "number", description: "Amount confirmed" },
  ],
});
await kupe.databases.agents.attach(db.id, { agent_id: "agt_..." });
const rows = await kupe.databases.rows.list(db.id, { q: "pending" });
```

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
ORG=$(curl -s https://x.kupe.in/v1/me -H "Authorization: Bearer sk-kupe-YOUR_KEY" | jq -r .org_id)
PRJ=$(curl -s https://x.kupe.in/v1/me -H "Authorization: Bearer sk-kupe-YOUR_KEY" | jq -r .project_id)

curl -X POST "https://x.kupe.in/v1/orgs/${ORG}/projects/${PRJ}/databases" \
  -H "Authorization: Bearer sk-kupe-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Collections outcomes",
    "fields": [
      {"name": "promise_date", "type": "string", "description": "Date they promised to pay"}
    ]
  }'
```

You can also pass `agent_ids` on create to attach in the same request.

## Routes

| Action | Path |
| - | - |
| List / create | `GET\|POST /v1/orgs/{org_id}/projects/{project_id}/databases` |
| Get / patch / archive | `/v1/databases/{database_id}` |
| Agents | `GET\|POST /v1/databases/{id}/agents`, `DELETE .../agents/{agent_id}` |
| Reverse | `GET /v1/agents/{agent_id}/databases` |
| Rows (keyset) | `GET /v1/databases/{id}/rows?cursor=&limit=&q=` |
| Patch / delete a row | `PATCH\|DELETE /v1/databases/{id}/rows/{row_id}` |
| Export | `GET /v1/databases/{id}/export?format=csv\|json\|ndjson\|zip` |

Patch `fields` to replace the extraction schema for every attached agent.

## Destinations

After a row is written you can fan it out. Patch `destinations`:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
[
  { "kind": "webhook", "url": "https://example.com/hooks/calls" },
  { "kind": "tool", "tool_id": "tool_..." },
  { "kind": "composio", "composio_slug": "hubspot", "connected_account_id": "ca_..." }
]
```

## Rows

Each row includes `direction` (`web` | `inbound` | `outbound`), `values` (JSON of schema fields), `status` (`pending` | `skipped` | `completed` | `failed`), and `sync_error`. Search `q` matches caller, direction, and values text. The console sorts, filters empty columns, hides columns, and exports. Right-click a row to edit values, change a column type, or delete it.

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
blob = client.databases.export(db.id, format="csv")
open("calls.csv", "wb").write(blob)
```

```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
const buf = await kupe.databases.rows.export(db.id, { format: "csv" });
```

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl "https://x.kupe.in/v1/databases/db_.../export?format=csv" \
  -H "Authorization: Bearer sk-kupe-YOUR_KEY" -o calls.csv
```

## Knowledge bases

Separate product for RAG files. Attach to an agent with `config.knowledge_base_ids` — do not dump FAQs into the system prompt.

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
kb = client.knowledge_bases.create(name="Policy")
client.knowledge_bases.files.upload(kb.id, file=open("policy.pdf", "rb"))
hits = client.knowledge_bases.search(kb.id, query="prepayment charges", top_k=5)
```

```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
const kb = await kupe.knowledgeBases.create({ name: "Policy" });
await kupe.knowledgeBases.files.upload(kb.id, file);
const hits = await kupe.knowledgeBases.search(kb.id, {
  query: "prepayment charges",
  top_k: 5,
});
```

```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://x.kupe.in/v1/orgs/${ORG}/projects/${PRJ}/knowledge-bases" \
  -H "Authorization: Bearer sk-kupe-YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"Policy"}'
```

## Audio assets

Ambient beds for web calls: `GET|POST /v1/orgs/{org_id}/projects/{project_id}/audio-assets`, archive with `POST /v1/audio-assets/{asset_id}/archive`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.