Skip to content

Getting Started

This guide walks you through setting up and running the Clearview API locally, then making your first request.


Prerequisites

  • Python 3.9+
  • pip
  • API keys for the following services:
Service Used for
OpenAI Summarization (OPENAI_API_KEY)
ElevenLabs Text-to-speech (ELEVENLABS_API_KEY)

Installation

1. Clone the repository

git clone https://github.com/hackathonapi/api.git
cd api

2. Create and activate a virtual environment

python -m venv .venv
source .venv/Scripts/activate   # Windows (bash)
# source .venv/bin/activate     # macOS / Linux

3. Install dependencies

pip install -r requirements.txt

4. Configure environment variables

Create a .env file in the project root:

OPENAI_API_KEY=sk-...
ELEVENLABS_API_KEY=...

Running the API

uvicorn src.main:app --reload

The API starts at http://127.0.0.1:8000.

Verify it's running:

curl http://127.0.0.1:8000/
import httpx

r = httpx.get("http://127.0.0.1:8000/")
print(r.json())
const res = await fetch("http://127.0.0.1:8000/");
console.log(await res.json());

Expected response:

{"message": "API is running!"}

Interactive docs

FastAPI exposes auto-generated interactive docs while the server is running:

  • Swagger UIhttp://127.0.0.1:8000/docs
  • ReDochttp://127.0.0.1:8000/redoc

Your first request

The following example analyzes a news article URL and retrieves the PDF report.

Step 1 — Analyze a document

curl -X POST http://127.0.0.1:8000/clearview \
  -H "Content-Type: application/json" \
  -d '{"input": "https://www.bbc.com/news/articles/example"}'
import httpx

r = httpx.post(
    "http://127.0.0.1:8000/clearview",
    json={"input": "https://www.bbc.com/news/articles/example"},
    timeout=120,  # analysis takes time — several ML models run in parallel
)
data = r.json()
print("Word count:", data["word_count"])
print("Scam notes:", data.get("scam_notes"))
print("Bias notes:", data.get("bias_notes"))
const res = await fetch("http://127.0.0.1:8000/clearview", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ input: "https://www.bbc.com/news/articles/example" }),
});
const data = await res.json();
console.log("Word count:", data.word_count);
console.log("Scam notes:", data.scam_notes);
console.log("Bias notes:", data.bias_notes);

The response includes a pdf field containing the full report as a base64-encoded string.

Step 2 — Save the PDF

import base64

pdf_bytes = base64.b64decode(data["pdf"])
with open("report.pdf", "wb") as f:
    f.write(pdf_bytes)
print("Saved report.pdf")
// In a browser
const bytes = atob(data.pdf);
const arr = new Uint8Array(bytes.length).map((_, i) => bytes.charCodeAt(i));
const blob = new Blob([arr], { type: "application/pdf" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "report.pdf";
a.click();

Next steps