ai-citer
AI-powered fact extraction and citation mapping for documents — PDF, Word, web pages, and plain text.
Built on FastAPI + Anthropic Claude. Extracts verbatim-quoted facts from documents, maps each quote back to its exact character offset, and optionally assigns PDF page numbers.
Install
pip install ai-citer
Requires Python 3.11+ and a PostgreSQL database.
Quick start
Run as a standalone server
Set environment variables (or create a .env file):
ANTHROPIC_API_KEY=sk-ant-...
DATABASE_URL=postgresql://user:pass@localhost/ai_citer
ai-citer serve # starts on :3001
ai-citer serve --port 8080 --reload
Or with uvicorn directly:
uvicorn ai_citer.main:app --port 3001
Embed the router in your own FastAPI app
from fastapi import FastAPI
from ai_citer import documents_router
app = FastAPI()
app.include_router(documents_router, prefix="/ai-citer")
Note: the router reads
app.state.pool(asyncpg pool) andapp.state.anthropic_clientfrom the FastAPI app state. Use the lifespan fromai_citer.mainas a reference, or set them up yourself.
Use the core functions directly
import anthropic
import asyncio
from ai_citer import (
create_pool, init_db,
extract_facts, map_citations, assign_page_numbers,
parse_pdf, parse_word, parse_web, parse_text,
)
async def main():
pool = await create_pool("postgresql://localhost/mydb")
await init_db(pool)
client = anthropic.AsyncAnthropic(api_key="sk-ant-...")
# Parse a PDF
with open("report.pdf", "rb") as f:
content = parse_pdf(f.read())
# Extract facts
extraction, usage = await extract_facts(client, content.rawText)
# Map quotes back to character offsets
facts = map_citations(content.rawText, extraction.facts)
print(facts[0].citations[0].charOffset) # exact position in raw text
print(f"Cost: ${usage.costUsd:.4f}")
asyncio.run(main())
REST API
When running as a server, the following endpoints are available under /api/documents:
| Method | Path | Description |
|---|---|---|
GET |
/ |
List all documents |
POST |
/ |
Upload a file (multipart/form-data) or URL (url form field) |
GET |
/:id |
Get a document (includes pdfData for PDFs) |
POST |
/:id/extract |
Run fact extraction (optional { "prompt": "..." } body) |
GET |
/:id/facts |
Get all accumulated facts for a document |
POST |
/:id/chat |
Chat with a document ({ "message": "...", "history": [] }) |
MCP server
ai-citer ships an MCP server that exposes extraction tools to AI assistants (Claude Desktop, etc.):
ai-citer mcp
Tools: upload_document_url, extract_facts, get_facts, list_documents.
Environment variables
| Variable | Required | Default | Description |
|---|---|---|---|
ANTHROPIC_API_KEY |
Yes | — | Anthropic API key |
DATABASE_URL |
Yes | — | PostgreSQL connection string |
Development
git clone https://github.com/czawora/ai-citer
cd ai-citer/server
pip install -e ".[dev]"
pytest
Metadata
Release files for ai-citer 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ai_citer-1.0.4.tar.gz | 25.0 kB | Without provenance | Details for ai_citer-1.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai_citer-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for ai_citer-1.0.4-py3-none-any.whl |
Total release size: 47.6 kB
Release files / ai_citer-1.0.4.tar.gz
| Download URL | ai_citer-1.0.4.tar.gz |
|---|---|
| Size | 25.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1fda07d5eee509da601cc493e965bcb0c2254a102a88d3c90aafad9e0fe364ff
|
|
BLAKE2b-256 checksum How to use checksums |
6e85c614c6f7a43ddcef7b62b170781d951165bd111e69eb7dbe83f7d032d0ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / ai_citer-1.0.4-py3-none-any.whl
| Download URL | ai_citer-1.0.4-py3-none-any.whl |
|---|---|
| Size | 22.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2ad2915738ae8e6e384fc77751200531b67845cf46fea033ec5bf4e5919f95b2
|
|
BLAKE2b-256 checksum How to use checksums |
3e681788398f6d1e987c1ceabb0f43452e157e6bf313c541ccfb0d8dfeb42978
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for ai-citer 1.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.