| 1 | # Ingest interfaces |
| 2 | |
| 3 | Utopia pulls or receives documents through **sources**. Two source kinds speak JSON and are meant for integration: **Custom** (Utopia polls your service) and **API** (your service pushes to Utopia). Both share the same identity semantics: every item has a stable ID, and pushing or returning the same ID again **updates the same document in place** — the previous content is kept as a version, search re-indexes, and the knowledge graph re-extracts. |
| 4 | |
| 5 | ## Choosing between them |
| 6 | |
| 7 | | | Custom (pull) | API (push) | |
| 8 | |---|---|---| |
| 9 | | Who initiates | Utopia, on a schedule | Your service, any time | |
| 10 | | Auth | Optional header you configure | Per-source Bearer token | |
| 11 | | Fits | Feeds, exports, periodic snapshots | Event-driven systems, scripts, CI | |
| 12 | | Deletion signal | `deleted` array in the response | `deleted: true` in a push | |
| 13 | |
| 14 | --- |
| 15 | |
| 16 | ## Custom source — the pull interface |
| 17 | |
| 18 | Create a **Custom** source and point it at any URL you control. On every sync (manual, interval, or cron) Utopia sends: |
| 19 | |
| 20 | ``` |
| 21 | GET {endpoint}?since=2026-08-26T19:43:24Z |
| 22 | Authorization: <your configured header, if any> |
| 23 | ``` |
| 24 | |
| 25 | - `since` is the last successful sync time (RFC 3339). It is **omitted on the first sync** — return everything then; afterwards you may return only what changed since that moment. Returning unchanged items again is harmless: they are skipped by content hash. |
| 26 | - If you configured an *Authorization header* on the source, it is sent verbatim in the `Authorization` header. It is stored server-side and never shown again in any API response. |
| 27 | |
| 28 | Respond with JSON: |
| 29 | |
| 30 | ```json |
| 31 | { |
| 32 | "items": [ |
| 33 | { |
| 34 | "id": "note-42", |
| 35 | "title": "Deployment runbook", |
| 36 | "content": "# Runbook\nRestart the ingest worker before each release.", |
| 37 | "doc_time": "2026-08-20T09:00:00Z", |
| 38 | "mime": "text/markdown" |
| 39 | } |
| 40 | ], |
| 41 | "deleted": ["note-17"] |
| 42 | } |
| 43 | ``` |
| 44 | |
| 45 | Field reference: |
| 46 | |
| 47 | | Field | Required | Meaning | |
| 48 | |---|---|---| |
| 49 | | `id` | yes | Stable identity within this source. Same `id` + new `content` → the document is updated in place. | |
| 50 | | `title` | no | Display name; the file extension is inferred from `mime` when missing. Defaults to `id`. | |
| 51 | | `content` | yes | Full text of the item (not a diff). | |
| 52 | | `doc_time` | no | RFC 3339. Becomes the document's time axis position — feed the real publish/effective time whenever you have it. | |
| 53 | | `mime` | no | `text/markdown` (default), `text/plain`, or `text/html`. | |
| 54 | | `deleted` | no | Array of `id`s your source has retired. Matching documents are **marked "Not in source"**, never auto-deleted — a person decides in the Library. Returning an item again clears the mark. | |
| 55 | |
| 56 | Notes: |
| 57 | |
| 58 | - Items missing from a response are **not** treated as deleted (the response may be incremental). Only the `deleted` array signals retirement. |
| 59 | - Endpoints on `localhost` are fetched directly, bypassing any system HTTP proxy. |
| 60 | |
| 61 | --- |
| 62 | |
| 63 | ## API source — the push interface |
| 64 | |
| 65 | Create an **API** source; it gets its own push token (view or rotate it from the source's Token dialog). Then: |
| 66 | |
| 67 | ``` |
| 68 | POST {your-utopia-base}/api/v1/sources/{source_id}/ingest |
| 69 | Authorization: Bearer utp_… |
| 70 | Content-Type: application/json |
| 71 | ``` |
| 72 | |
| 73 | ```json |
| 74 | { |
| 75 | "filename": "runbook.md", |
| 76 | "content": "# Runbook\nRestart the ingest worker before each release.", |
| 77 | "doc_time": "2026-08-20T09:00:00Z", |
| 78 | "external_id": "note-42" |
| 79 | } |
| 80 | ``` |
| 81 | |
| 82 | | Field | Required | Meaning | |
| 83 | |---|---|---| |
| 84 | | `filename` | yes | Display name; also the fallback identity when `external_id` is absent. | |
| 85 | | `content` | yes* | Full text. *Optional when `deleted` is `true`.* | |
| 86 | | `doc_time` | no | RFC 3339; the document's position on the time axis. | |
| 87 | | `external_id` | no | Stable identity. Same identity + new content → update in place. Without it, `filename` is the identity. | |
| 88 | | `deleted` | no | `true` marks the identified document "Not in source" (tombstone). A later normal push of the same identity revives it. | |
| 89 | |
| 90 | The response tells you what happened: |
| 91 | |
| 92 | ```json |
| 93 | { "action": "created" } |
| 94 | ``` |
| 95 | |
| 96 | `created` · `updated` · `moved` (same content, new name) · `unchanged` · `marked_missing`. |
| 97 | |
| 98 | Example with curl: |
| 99 | |
| 100 | ```bash |
| 101 | curl -X POST "https://utopia.example.com/api/v1/sources/01a0…/ingest" \ |
| 102 | -H "Authorization: Bearer utp_…" \ |
| 103 | -H "Content-Type: application/json" \ |
| 104 | -d '{"filename":"runbook.md","content":"# Runbook v2 …","external_id":"note-42"}' |
| 105 | ``` |
| 106 | |
| 107 | --- |
| 108 | |
| 109 | ## Shared semantics |
| 110 | |
| 111 | - **Identity, not filenames.** Documents are tracked by `custom:{id}` / `api:{external_id}` keys. Renames are recognized as moves; content changes update the same document. |
| 112 | - **Updates keep history.** Every content change records a version; earlier extracted knowledge keeps its provenance. |
| 113 | - **Deletion is a marker.** Tombstones set a "Not in source" flag; the Library shows a cleanup action, and a human confirms actual deletion. |
| 114 | - **`doc_time` drives the time axis.** Documents without it fall back to their ingestion time — real timestamps make the temporal graph meaningfully better. |