Skip to main content

Middleware proxy for AI agent request attribution and compliance audit trails

Project description

agent-cost-attribution-layer

A FastAPI-based middleware proxy that automatically attributes every AI request to agents, users, and tasks—generating compliance-ready audit trails for multi-agent deployments.

What is this?

This is a transparent proxy layer that sits between your AI agents and LLM APIs (OpenAI, Anthropic, local models, etc.). It automatically tags every request with agent identity, user attribution, task context, and cost, then logs everything to a queryable audit database. It solves the core problem revealed by the VS Code Copilot attribution drama: "Who authorized this AI action and what data did it use?" Unlike cost-monitoring tools, this focuses on consent tracking, regulatory compliance, and multi-agent accountability.

Features

  • Transparent proxy — Drop-in replacement for OpenAI/Anthropic client calls; no agent code changes required
  • Automatic attribution — Tags every request with agent ID, user ID, task context, and timestamp
  • Audit trails — SQLite-backed compliance log with prompt hashes, token usage, and costs
  • REST API — Query attribution history: "Show all AI actions by user X in the last 30 days"
  • Export compliance — CSV (legal), JSON (monitoring), and GDPR-compliant deletion endpoints
  • CLI toolingagent-attr proxy start --port 8080 --log-db audit.db
  • Rate limiting — Per-user, per-agent quotas with configurable tiers
  • Multi-tier pricing — Freemium (local), Pro (cloud-hosted), Enterprise (SOC2 audit trails)

Quick Start

Installation

# Clone and install
git clone https://github.com/yourusername/agent-cost-attribution-layer.git
cd agent-cost-attribution-layer
pip install -e .

Basic Setup

# Copy environment template
cp .env.example .env

# Start the proxy server
agent-attr proxy start --port 8080 --log-db ./audit.db

Docker Deployment

docker-compose up -d

The proxy is now listening on http://localhost:8080.

Usage

Redirect agent requests through the proxy

Before:

from openai import OpenAI
client = OpenAI(api_key="sk-...")
response = client.chat.completions.create(model="gpt-4", messages=[...])

After (one-line change):

from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="http://localhost:8080/v1")
# Add attribution headers
client.default_headers = {
    "X-Agent-ID": "code-review-bot",
    "X-User-ID": "user-123",
    "X-Task-Context": "PR review #456"
}
response = client.chat.completions.create(model="gpt-4", messages=[...])

Query audit logs via REST API

# Get all actions by a user in the last 30 days
curl http://localhost:8080/audit/user/user-123?days=30

# Get all actions by an agent
curl http://localhost:8080/audit/agent/code-review-bot

# Export as CSV (for compliance)
curl http://localhost:8080/audit/export/csv?start_date=2026-05-01&end_date=2026-05-31 > audit.csv

CLI commands

# Start proxy
agent-attr proxy start --port 8080 --log-db audit.db

# Query logs
agent-attr audit query --agent code-review-bot --days 7

# Export for compliance
agent-attr audit export --format csv --output audit.csv

# GDPR deletion
agent-attr audit delete --user user-123

Tech Stack

  • FastAPI — High-performance async proxy server
  • SQLite — Local-first audit log (no external DB required)
  • Pydantic — Request/response validation
  • pytest — Test suite
  • Docker — Container deployment
  • Python 3.10+

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_cost_attribution_layer-0.1.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_cost_attribution_layer-0.1.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file agent_cost_attribution_layer-0.1.0.tar.gz.

File metadata

File hashes

Hashes for agent_cost_attribution_layer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aa90bb6969ed8421a271ed7fca9e6fe3ad564bdee216b027532b31131fea8b60
MD5 b32dd702e3ad206825e1e293504d4a81
BLAKE2b-256 791a42a97db871d18f273942f6df40ec3cd91d5ce7d49a61370ac66f16cccda9

See more details on using hashes here.

File details

Details for the file agent_cost_attribution_layer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agent_cost_attribution_layer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18bc238f835554355575c1f89022f5b820ef21953f190e71e5098a344afc6753
MD5 8b0dc0363e60e7a3de2a0a1f55cd8ac1
BLAKE2b-256 c6a27c8389f9c48197b4c76c5046fcbc18c7ab0baa6eee03b32257b3945dec02

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page