๐Ÿ“ฆ EqualifyEverything / equalify-docs

๐Ÿ“„ api.md ยท 242 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242---
title: API Reference
date: 2026-04-16
author: Equalify Tech Team
description: REST endpoints, authentication, request/response shapes for the Equalify Reflow API.
---

# API Reference

All endpoints are prefixed with `/api/v1/`.

**Interactive docs are the source of truth.** The OpenAPI schema is auto-generated from the code and stays in lockstep with the server. For the authoritative, always-current reference, see the running Swagger at:

- **Public instance:** [https://reflow.equalify.uic.edu/docs](https://reflow.equalify.uic.edu/docs)
- **Your own instance:** `http://<your-host>:8080/docs` (public โ€” no auth required)

This page summarises the endpoints an API integrator is most likely to use. For recipe-style walkthroughs, see [how to integrate via the API](../how-to/integrate-via-api).

## Authentication

All `/api/v1/*` endpoints require an API key in the `X-API-Key` header:

```bash
curl -H "X-API-Key: YOUR_API_KEY" https://your-instance/api/v1/documents/submit
```

The following are **publicly accessible** (no API key required):

- `/` โ€” viewer SPA
- `/docs`, `/redoc`, `/openapi.json` โ€” API documentation
- `/health`, `/health/ready` โ€” health checks
- `/metrics` โ€” Prometheus scrape target

Browser `EventSource` connections cannot send custom headers. For SSE, exchange an API key for a short-lived [stream token](#streaming-events).

## Document processing

### Submit a document

```
POST /api/v1/documents/submit
```

Upload a PDF. Scanned for PII, then queued for the conversion pipeline.

**Multipart request body:**

| Field | Type | Default | Description |
|---|---|---|---|
| `file` | file | required | PDF file (max 100 MB, max 50 pages) |
| `skip_pii_scan` | boolean | `false` | Bypass PII scanning (requires `skip_reason`) |
| `skip_reason` | string | โ€” | Justification; recorded in the audit trail |
| `review_mode` | string | `"auto"` | `"auto"` completes immediately; `"human"` holds for ledger review |
| `generate_debug_bundle` | boolean | `false` | Save all agent prompts and responses |

**Response** (`201 Created`):

```json
{
  "job_id": "abc123-def456",
  "status": "pii_scanning",
  "message": "Document submitted successfully",
  "estimated_completion_minutes": 5
}
```

### Get job status

```
GET /api/v1/documents/{job_id}
```

Response shape changes with status. The most interesting fields on completion are `markdown_url`, `figures[]`, `llm_cost`, and `warnings[]`. Pre-signed S3 URLs are short-lived โ€” download promptly.

**Possible statuses:**

| Status | Meaning |
|---|---|
| `pii_scanning` | Being scanned for PII |
| `awaiting_approval` | PII detected โ€” waiting for human review |
| `processing` | Converting |
| `completed` | Done |
| `failed` | Error during processing |
| `denied` | PII review denied |

**Completed response (elided):**

```json
{
  "job_id": "abc123-def456",
  "status": "completed",
  "markdown_url": "https://s3.../result.md",
  "figures": [{"figure_id": "figure_1_1", "url": "https://s3.../figure_1_1.png", "page": 1, "alt_text": "", "caption": "..."}],
  "llm_cost": {"input_tokens": 45000, "output_tokens": 12000, "total_tokens": 57000, "estimated_cost_dollars": 0.34},
  "warnings": []
}
```

### Get change ledger

```
GET /api/v1/documents/{job_id}/ledger
```

Every edit the pipeline made, grouped by page โ€” action, target, before/after text, and reasoning. Only available after processing completes.

## Streaming events

For live progress, use Server-Sent Events. This is how the built-in viewer and the WordPress plugin show real-time progress.

### Get a stream token

```
POST /api/v1/documents/{job_id}/stream/token
```

Returns a short-lived (5 min), single-use token for the SSE endpoint.

```json
{
  "token": "st_abc123...",
  "expires_in_seconds": 300,
  "stream_url": "/api/v1/documents/abc123-def456/stream?token=st_abc123..."
}
```

### Connect to the stream

```
GET /api/v1/documents/{job_id}/stream?token={stream_token}
```

**Event types:**

| Event | Data | Description |
|---|---|---|
| `pipeline:phase` | `{user_phase, display_name, step_name, step_number, total_steps}` | A pipeline stage started |
| `processing:complete` | `{}` | Finished successfully |
| `processing:error` | `{error}` | Failed |
| `done` | `{}` | Stream is closing |

> **Use `user_phase` for progress UI.** Every `pipeline:phase` event carries a `user_phase` field โ€” one of `extraction`, `analysis`, `headings`, `translation`, `assembly`, or `review`. That's the stable public contract, matching the five phases the viewer and WordPress plugin display. `display_name` (human-readable, e.g. "Heading Reconciliation") and `step_name` (internal identifier) are also provided for richer progress detail, but their values are not a stable contract โ€” drive any UI state off `user_phase`.

## PII approval

When PII is detected, the job enters `awaiting_approval`. The status response includes an `approval_token` and `approval_url`.

### Get review details

```
GET /api/v1/approval/{token}/review
```

Returns job details and PII findings for the review interface.

### Submit a decision

```
POST /api/v1/approval/{token}/decision
```

**Request:**

```json
{
  "decision": "approved",
  "justification": "Course material, instructor contact info is public",
  "reviewed_by": "admin@your-institution.edu"
}
```

Approved โ†’ the job moves to `processing`. Denied โ†’ the job moves to `denied` and the document is deleted from temporary storage.

## Pipeline viewer endpoints

These endpoints power the built-in pipeline viewer served at the root path `/` โ€” a visualizer for the AI pipeline. The viewer shows real-time progress, versioned markdown diffs, and the change ledger as a document moves through each stage. Not intended for bulk document processing.

### Process with streaming

```
POST /api/v1/pipeline/process/stream
```

Synchronous: upload a PDF and receive the full pipeline execution as an SSE stream, with versioned markdown snapshots at each stage.

**Multipart request body:**

| Field | Type | Default | Description |
|---|---|---|---|
| `file` | file | required | PDF to process |
| `images_scale` | float | `2.0` | Page image DPI scale (1.0โ€“3.0) |
| `do_table_structure` | boolean | `true` | Enable table structure extraction |
| `ocr_languages` | string | โ€” | OCR language codes (e.g., `"en,es"`) |

**SSE event types** emitted during the stream:

| Event | Description |
|---|---|
| `session` | Session ID for reconnection |
| `init` | Docling extraction complete โ€” metadata + initial markdown |
| `page_image` | Individual page image (base64 PNG) |
| `figure_image` | Individual extracted figure (base64 PNG) |
| `processing` | A pipeline step is starting |
| `step` | A pipeline step completed โ€” includes version diff |
| `error` | A step failed (non-fatal, pipeline continues) |
| `done` | Processing complete |

### Reconnect to a session

```
GET /api/v1/pipeline/sessions/{session_id}/stream?last_event_id={id}
```

Replays all events after the given ID. The pipeline continues running whether or not a client is connected.

## Health

```
GET /health        # Full check (Redis, S3, Docling, queues)
GET /health/ready  # Readiness probe
```

## Rate limiting

Per-IP limits apply to submission (`POST /api/v1/documents/submit`) and status polling. Violations return `429 Too Many Requests` with a `Retry-After` header. Adjust via env vars โ€” see the contributor-side rate-limiting docs in the [equalify-reflow](https://github.com/EqualifyEverything/equalify-reflow) repo.

## Error format

```json
{"detail": "Job not found"}
```

| Status | Meaning |
|---|---|
| `400` | Bad request |
| `401` | Missing or invalid API key |
| `404` | Job or resource not found |
| `413` | File too large (max 100 MB) |
| `422` | Validation error |
| `429` | Rate limited |
| `500` | Internal server error |