Ingest API β Usage & Integration
Overview
- Small Python FastAPI service that ingests URLs and PDFs, creates embeddings (Mistral), and upserts vectors to Pinecone.
- Endpoints return a
job_id; jobs are processed in background and can optionally POST results to awebhook_url.
APIs
POST /ingest/url
- Auth: header
x-api-key - Body (JSON):
{ "url": "https://...", "namespace": "workspace", "webhook_url": "https://..." } - Response: 202 Accepted,
{ "status": "accepted", "job_id": "..." }
- Auth: header
POST /ingest/pdf
- Auth: header
x-api-key - Multipart form fields:
file(PDF),namespace(optional),webhook_url(optional) - Response: 202 Accepted,
{ "status": "accepted", "job_id": "..." }
- Auth: header
GET /jobs/{job_id}
- Auth: header
x-api-key - Returns job object with keys:
id, type, status, created_at, started_at, finished_at, result, error.
- Auth: header
Webhooks
- Provide
webhook_urlin request body/form. When job finishes the service will POST JSON{ job_id, status, result, error }to that URL (best-effort; failures are ignored).
Environment variables (Python ingest service)
PINECONE_API_KEYβ Pinecone API keyPINECONE_HOSTβ Pinecone host (e.g. https://xyz.pinecone.io)PINECONE_INDEXβ Pinecone index nameMISTRAL_API_KEYβ Mistral embeddings API keyADMIN_API_KEYorADMIN_API_KEYSβ comma-separated admin API key(s) required byx-api-keyTESSERACT_PATHβ (optional) path to tesseract executable for OCR fallback; default:C:\Program Files\Tesseract-OCR\tesseract.exePOPPLER_PATHβ (optional) path to poppler binaries forpdf2image; default:C:\poppler\Library\binOCR_LANGβ languages for tesseract (example:ben+eng)
Run locally (Python)
- Create venv and install deps (ensure tesseract + poppler installed for OCR):
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
pip install pdf2image pytesseract
- Set required env vars (example PowerShell):
$env:PINECONE_API_KEY="your_key"
$env:PINECONE_HOST="https://your-index-host.pinecone.io"
$env:PINECONE_INDEX="pregnancy-knowledge"
$env:MISTRAL_API_KEY="your_mistral_key"
$env:ADMIN_API_KEY="supersecret"
# Optional OCR
$env:TESSERACT_PATH="C:\Program Files\Tesseract-OCR\tesseract.exe"
$env:POPPLER_PATH="C:\poppler\Library\bin"
$env:OCR_LANG="ben+eng"
uvicorn ingest_api:app --host 0.0.0.0 --port 8000
Next.js / Frontend integration
- Two approaches:
- Server-proxy (recommended: keep admin key server-side): create Next.js API route that calls Python service using
INGEST_API_URLandINGEST_API_KEY.- Env (server):
INGEST_API_URL,INGEST_API_KEY. - Example file provided:
admin-nextjs-example/pages/api/proxy/ingest-url.js.
- Env (server):
- Direct client upload (simpler for quick setups) β client sends
x-api-keyand form data directly to Python service.- If using client-facing key, set
NEXT_PUBLIC_INGEST_API_KEYandNEXT_PUBLIC_INGEST_API_URL(NOT recommended for production).
- If using client-facing key, set
- Server-proxy (recommended: keep admin key server-side): create Next.js API route that calls Python service using
Example curl
- Ingest URL (server or client with valid API key):
curl -X POST http://localhost:8000/ingest/url \
-H "Content-Type: application/json" \
-H "x-api-key: supersecret" \
-d '{"url":"https://example.com/article","namespace":"workspace"}'
- Upload PDF:
curl -X POST http://localhost:8000/ingest/pdf \
-H "x-api-key: supersecret" \
-F "file=@/path/to/file.pdf" \
-F "namespace=workspace"
Admin UI examples in this repo
admin_dashboard.htmlβ static demo (opens in browser, uses same-origin requests to Python service).admin-nextjs-example/β Next.js example:pages/admin.js(client UI);pages/api/proxy/ingest-url.js(server proxy example);pages/api/proxy/ingest-pdf.js(placeholder explaining multipart server proxying).
Notes & production recommendations
- Current job store is in-memory (
JOBS) β process restart will lose state. For production use Supabase/Redis/Postgres to persist jobs. - For reliable background processing and retries, replace
BackgroundTaskswith a worker system (Celery, RQ, or a serverless job queue). - Do not expose
ADMIN_API_KEYin browser. Use a server-side proxy with authentication.
Questions or next steps
- I can implement server-side PDF proxy parsing in the Next.js example (using
formidable) or wire Supabase auth to the admin UI. Which should I do next?