AI Provenance Tracker - Backend
FastAPI backend for detecting AI-generated content.
Quick Start
# Create virtual environment
python -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -e ".[dev]"
# Run the server
uvicorn app.main:app --reload
API Endpoints
POST /api/v1/detect/text- Detect AI-generated textPOST /api/v1/detect/image- Detect AI-generated imagesPOST /api/v1/detect/audio- Detect AI-generated audio (WAV)POST /api/v1/detect/video- Detect AI-generated video (MVP)POST /api/v1/batch/text- Batch text detectionPOST /api/v1/intel/x/collect- Collect X data into trust-and-safety input schemaPOST /api/v1/intel/x/collect/estimate- Estimate X request cost without external callsPOST /api/v1/intel/x/report- Generate trust-and-safety report from normalized inputPOST /api/v1/intel/x/drilldown- Build cluster/claim drill-down + alerts datasetGET /api/v1/intel/x/scheduler/status- Check recurring job statusPOST /api/v1/intel/x/scheduler/run- Trigger one immediate scheduled runGET /api/v1/analyze/dashboard- Dashboard-ready analytics metricsGET /api/v1/analyze/evaluation- Calibration precision/recall trend for dashboardGET /api/v1/analyze/audit-events- Audit log events (HTTP + detection)GET /health- Health check
X Intelligence Collection
Set X_BEARER_TOKEN in .env, then either call API:
curl -X POST "http://localhost:8000/api/v1/intel/x/collect" \
-H "Content-Type: application/json" \
-d '{"target_handle":"@example","window_days":30,"max_posts":300,"query":"anthropic OR claudecode"}'
or use CLI utility:
python scripts/collect_x_input.py --handle @example --window-days 30 --max-posts 300 --query "anthropic OR claudecode" --output ./x_intel_input.json --show-request-estimate
Low-cost run (tight request budget):
X_MAX_PAGES=1 X_MAX_REQUESTS_PER_RUN=4 python scripts/collect_x_input.py --handle @example --window-days 7 --max-posts 60 --output ./x_intel_input.json --show-request-estimate
Cost precheck endpoint (no external X calls):
curl -X POST "http://localhost:8000/api/v1/intel/x/collect/estimate" \
-H "Content-Type: application/json" \
-d '{"window_days":7,"max_posts":60,"max_pages":1}'
Batch text detection:
curl -X POST "http://localhost:8000/api/v1/batch/text" \
-H "Content-Type: application/json" \
-d '{"items":[{"item_id":"a","text":"Sample text one..."},{"item_id":"b","text":"Sample text two..."}]}'
Dashboard metrics:
curl "http://localhost:8000/api/v1/analyze/dashboard?days=30"
Audit events:
curl "http://localhost:8000/api/v1/analyze/audit-events?limit=50"
Dashboard drill-down from normalized input:
curl -X POST "http://localhost:8000/api/v1/intel/x/drilldown" \
-H "Content-Type: application/json" \
--data-binary @./x_intel_input.json
Trust Report, Benchmark, Evidence Pack
Generate trust report:
python scripts/generate_x_trust_report.py --input ./x_intel_input.json --output ./x_trust_report.json
Benchmark (optional labels file):
python scripts/benchmark_x_intel.py --report ./x_trust_report.json --labels ./evidence/labels_template.json --output ./x_trust_benchmark.json
Build talent-visa evidence pack:
python scripts/build_talent_visa_evidence_pack.py --reports-glob "./x_trust_report*.json" --benchmarks-glob "./x_trust_benchmark*.json" --output-dir ./evidence
Run full pipeline:
python scripts/run_talent_visa_pipeline.py --handle @example --window-days 90 --max-posts 600 --query "anthropic OR claudecode OR claudeai OR usagelimits"
Run pipeline from pre-collected input JSON (offline mode):
python scripts/run_talent_visa_pipeline.py --input-json ./x_intel_input.json --output-dir ./evidence/runs/manual_input --run-id run_snapshot
Compare two run directories:
python scripts/compare_talent_visa_runs.py --base-run-dir ./evidence/runs/run_a --candidate-run-dir ./evidence/runs/run_b --output-json ./evidence/runs/comparisons/run_a_vs_run_b.json --output-md ./evidence/runs/comparisons/run_a_vs_run_b.md
Evaluate confidence-threshold calibration on labeled data:
python scripts/evaluate_detection_calibration.py --input ./labels_text.jsonl --content-type text --output ./calibration_text.json --register
python scripts/evaluate_detection_calibration.py --input ./labels_audio.jsonl --content-type audio --output ./calibration_audio.json --register
python scripts/evaluate_detection_calibration.py --input ./labels_video.jsonl --content-type video --output ./calibration_video.json --register
Audio/video JSONL templates: ./evidence/samples/audio_labeled_template.jsonl, ./evidence/samples/video_labeled_template.jsonl
Weekly pipeline cycle with automatic run comparison:
python scripts/run_weekly_talent_visa_cycle.py --handle @example --window-days 7 --max-posts 60 --output-dir ./evidence/runs/weekly --comparisons-dir ./evidence/runs/comparisons --summary-output ./evidence/runs/weekly/latest_summary.json
Production smoke test for all detect endpoints:
python scripts/smoke_detect_prod.py --base-url https://your-api-domain --output ./evidence/smoke/prod_detect_smoke.json
Run background worker process (scheduler + webhook retry queue):
python -m app.worker.main
Trigger a scheduler run manually:
curl -X POST "http://localhost:8000/api/v1/intel/x/scheduler/run?handle=@example"
Check scheduler status:
curl "http://localhost:8000/api/v1/intel/x/scheduler/status"
Persistence and Migrations
Runtime analysis history is persisted in analysis_records (SQLite by default).
Audit events are persisted in audit_events.
alembic upgrade head
Security and Spend Controls
Configure optional API key enforcement and endpoint spend controls in .env:
REQUIRE_API_KEYAPI_KEYSDAILY_SPEND_CAP_POINTSRATE_LIMIT_MEDIA_REQUESTSRATE_LIMIT_BATCH_REQUESTSRATE_LIMIT_INTEL_REQUESTSX_COST_GUARD_ENABLEDX_MAX_REQUESTS_PER_RUNCONSENSUS_ENABLEDCOPYLEAKS_API_KEYREALITY_DEFENDER_API_KEYSCHEDULER_ENABLEDSCHEDULER_HANDLESSCHEDULER_MONTHLY_REQUEST_CAPSCHEDULER_KILL_SWITCH_ON_CAPSCHEDULER_USAGE_FILERUN_SCHEDULER_IN_APIWORKER_ENABLE_SCHEDULERWORKER_DRAIN_WEBHOOK_QUEUEWORKER_TICK_SECONDSWEBHOOK_URLSWEBHOOK_RETRY_ATTEMPTSWEBHOOK_RETRY_BACKOFF_SECONDSWEBHOOK_QUEUE_FILEWEBHOOK_DEAD_LETTER_FILEAUDIT_EVENTS_ENABLEDAUDIT_LOG_HTTP_REQUESTSAUDIT_ACTOR_HEADER
Documentation
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Metadata
Release files for ai-provenance-tracker 1.1.0
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_provenance_tracker-1.1.0.tar.gz | 267.7 kB | With provenance | Details for ai_provenance_tracker-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai_provenance_tracker-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for ai_provenance_tracker-1.1.0-py3-none-any.whl |
Total release size: 373.7 kB
Release files / ai_provenance_tracker-1.1.0.tar.gz
| Download URL | ai_provenance_tracker-1.1.0.tar.gz |
|---|---|
| Size | 267.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
53391c47e629685908a2f0fa6762d7c67fb8c2e475403b8511b06bc7e37810f6
|
|
BLAKE2b-256 checksum How to use checksums |
91a5044a207aa1181a036af079291ccdef298da398b4de1a72d2ae2b77fb9320
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 30, 2026.
Transparency logRelease files / ai_provenance_tracker-1.1.0-py3-none-any.whl
| Download URL | ai_provenance_tracker-1.1.0-py3-none-any.whl |
|---|---|
| Size | 106.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b902a3d88861080f0921a39b05437e29bc83059888b32a97d49f3de202626d12
|
|
BLAKE2b-256 checksum How to use checksums |
cd3ed5f8265a01aeb1e32583aed75ba275b3321d31ff86b1cd49bf8724fb8915
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 30, 2026.
Transparency logSecurity for ai-provenance-tracker 1.1.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for ai_provenance_tracker-1.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 30, 2026.
Transparency logA 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.