INTEGRATIONS_

Integration patterns for your current API routes: /api/v1/process, /api/v1/tasks, /api/v1/tasks/{task_id}.

TaskResponse Shape

TaskResponse
{
  "id": "uuid",
  "status": "PENDING | PROCESSING | COMPLETED | FAILED",
  "error_message": "string | null",
  "result_markdown": "string | null",
  "file_hash": "string | null",
  "original_filename": "string | null",
  "created_at": "datetime",
  "updated_at": "datetime"
}
Pattern 01

Native Python

sync_client.py
import requests
import time

API_KEY = "sk_live_..."
BASE_URL = "https://api.ragfodder.com"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

def process_document(file_path: str) -> str:
    with open(file_path, "rb") as f:
        submit = requests.post(
            f"{BASE_URL}/api/v1/process",
            headers=HEADERS,
            files=[("files", f)]
        )
    submit.raise_for_status()
    task_id = submit.json()[0]["task_id"]

    while True:
        task = requests.get(f"{BASE_URL}/api/v1/tasks/{task_id}", headers=HEADERS).json()
        if task["status"] == "COMPLETED":
            return task.get("result_markdown", "")
        if task["status"] == "FAILED":
            raise RuntimeError(task.get("error_message") or "Task failed")
        time.sleep(1)
Pattern 02

Native JavaScript

Use these examples in server-side runtimes only. Do not expose API keys in browser code.

single-file.mjs
import fs from "node:fs";

const API_KEY = "sk_live_...";
const BASE_URL = "https://api.ragfodder.com";

async function processFile(filePath) {
  const form = new FormData();
  form.append(
    "files",
    new Blob([fs.readFileSync(filePath)]),
    filePath.split("/").pop()
  );

  const submit = await fetch(`${BASE_URL}/api/v1/process`, {
    method: "POST",
    headers: { Authorization: `Bearer ${API_KEY}` },
    body: form,
  });

  if (!submit.ok) throw new Error("Failed to submit file");
  const [{ task_id }] = await submit.json();

  while (true) {
    const statusRes = await fetch(`${BASE_URL}/api/v1/tasks/${task_id}`, {
      headers: { Authorization: `Bearer ${API_KEY}` },
    });
    const task = await statusRes.json();

    if (task.status === "COMPLETED") return task.result_markdown ?? "";
    if (task.status === "FAILED") {
      throw new Error(task.error_message ?? "Task failed");
    }
    await new Promise((resolve) => setTimeout(resolve, 1000));
  }
}

const markdown = await processFile("./annual-report.pdf");
console.log(markdown.slice(0, 300));
Pattern 03

Common Tools

Examples for popular RAG tooling using the same Ragfodder processing flow.

langchain_loader.py
from langchain_core.document_loaders import BaseLoader
from langchain_core.documents import Document
import requests
import time

class RagfodderLoader(BaseLoader):
    def __init__(self, file_path: str, api_key: str):
        self.file_path = file_path
        self.base_url = "https://api.ragfodder.com"
        self.headers = {"Authorization": f"Bearer {api_key}"}

    def _process_and_wait(self) -> str:
        with open(self.file_path, "rb") as f:
            submit = requests.post(
                f"{self.base_url}/api/v1/process",
                headers=self.headers,
                files=[("files", f)],
            )
        submit.raise_for_status()
        task_id = submit.json()[0]["task_id"]

        while True:
            task = requests.get(f"{self.base_url}/api/v1/tasks/{task_id}", headers=self.headers).json()
            if task["status"] == "COMPLETED":
                return task.get("result_markdown", "")
            if task["status"] == "FAILED":
                raise RuntimeError(task.get("error_message") or "Task failed")
            time.sleep(1)

    def lazy_load(self):
        markdown = self._process_and_wait()
        yield Document(page_content=markdown, metadata={"source": self.file_path})

# Usage:
# docs = list(RagfodderLoader("./report.pdf", api_key="sk_live_...").lazy_load())