A REST API for verifying citations using AI.
# Development
uvicorn citation_verifier.api:app --reload
# Production
uvicorn citation_verifier.api:app --host 0.0.0.0 --port 8000Once running, visit:
- Interactive docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
curl http://localhost:8000/healthVerify all citations in a document (Markdown, PDF, or URL):
curl -X POST http://localhost:8000/verify/document \
-H "Content-Type: application/json" \
-d '{
"source": "path/to/document.md",
"model": "claude-3-5-haiku-20241022"
}'Response:
{
"summary": {
"total_citations": 5,
"supported": 3,
"partial": 1,
"not_supported": 1
},
"results": [
{
"claim": "80% of companies use AI",
"source_url": "https://example.com/study",
"verdict": "partial",
"confidence": 0.85,
"explanation": "Source states 78%, not 80%",
"source_quote": "78% of surveyed companies..."
}
],
"processing_time_seconds": 12.34
}Verify one claim against a source:
curl -X POST http://localhost:8000/verify/claim \
-H "Content-Type: application/json" \
-d '{
"claim": "Python is the most popular programming language",
"source_url": "https://www.python.org/about/",
"model": "claude-3-5-haiku-20241022"
}'Response:
{
"claim": "Python is the most popular programming language",
"source_url": "https://www.python.org/about/",
"verdict": "supported",
"confidence": 0.92,
"explanation": "The source confirms Python's popularity...",
"source_quote": "Python is one of the most popular..."
}| Verdict | Description |
|---|---|
supported |
Source confirms the claim |
not_supported |
Source contradicts or doesn't mention the claim |
partial |
Source partially supports (different numbers, missing nuance) |
inconclusive |
Cannot determine with certainty |
source_unavailable |
Source is behind paywall, 404, timeout, etc. |
Set your API key:
export ANTHROPIC_API_KEY=your-key-hereOr create a .env file:
ANTHROPIC_API_KEY=your-key-hereThe API allows all origins by default. For production, update the CORS settings in api.py:
app.add_middleware(
CORSMiddleware,
allow_origins=["https://yourdomain.com"], # Specify allowed origins
...
)The API returns standard HTTP status codes:
200: Success404: File/resource not found500: Internal server error (verification failed)
Error response format:
{
"detail": "Error message here"
}