All projects

01 / ENGINEERING CASE STUDY · AI systems

Autonomous Billing Proxy

A FastAPI gateway that separates response delivery from outcome verification and records successful executions in an atomic wallet ledger.

PythonFastAPINext.jsSupabaseGemini AI
April 2026 — Present
View source

01 / CONTEXT

The problem

An HTTP request can return an empty response, a bot challenge, or irrelevant content and still count as billable traffic. This prototype explores charging an AI agent only after the response is judged useful, while keeping verification off the agent’s response path.

02 / SYSTEM DESIGN

Architecture

Return the response; evaluate the charge separately

Agent · bearer token + target URL
FastAPI gateway · authenticate + proxy
Target API · response
Telemetry · verification
Verified outcome · wallet debit + ledger row
  • Gemini structured judgment + heuristic fallback
  • Failed verification: no charge
  • Next.js dashboard: tokens, balance, history
The gateway returns the upstream response to the agent. A separate asynchronous verification path decides whether to create a charge.

03 / TRADEOFFS

Engineering decisions

01

Keep verification off the response path

The gateway schedules verification asynchronously so the agent does not wait for model scoring and billing. The current client is fire-and-forget: an unreachable verifier can mean dropped telemetry. That makes a durable queue an important next step before relying on it for revenue.

Asynchronous verification client
02

Make a charge explainable

Gemini produces structured judgments, with local heuristics available when the model is unavailable. Status, body coherence, and failure signals inform the decision. Scores and proof metadata accompany ledger entries, so a charge can be inspected rather than reduced to an opaque pass/fail.

Structured verification judge
03

Commit the debit and ledger entry together

A PL/pgSQL function updates the wallet and inserts the transaction in one database transaction, rolling back if the balance is insufficient. The request-hash precheck helps identify repeated executions, but it does not by itself prove safety against concurrent duplicate requests. Stronger idempotency and concurrency tests belong in the next iteration.

Atomic billing function
04

Treat the gateway as an enforcement boundary

Bearer tokens are stored as SHA-256 hashes. Session checks, request fingerprints, per-developer rate limits, and bounded telemetry constrain what reaches the downstream services. Distributed rate limiting remains a production-hardening task.

Gateway implementation

04 / VALIDATION

Evidence & measurement

The source supports the asynchronous gateway, verifier, and atomic billing design. Evaluator tests cover decision logic; they do not establish end-to-end financial correctness or load capacity.

Asynchronous verification

The verification client creates background tasks and logs unreachable-service failures. It does not currently provide durable delivery.

View supporting reference

Atomic wallet + ledger writes

The database function combines wallet debit and ledger insertion in a transaction. Concurrent duplicate handling still needs stronger guarantees.

View supporting reference

Evaluator coverage

The repository includes pytest cases for the verification decision pipeline. The README identifies calibration against real labeled traffic as an open requirement.

View supporting reference

Performance claims: available context

These figures appear in my résumé. Published benchmark conditions are still missing; they should not be read as reproducible results.

Reported figures and the information needed to validate them
Reported figureEvidence statusWhat’s needed
<50 ms proxy overheadRésumé-reported; no published runNo direct-versus-proxied baseline, payload sizes, concurrency, deployment hardware, or latency percentiles are published.
100K+ micro-transactionsRésumé-reported; no published load reportNo run duration, transaction rate, environment, failure counts, or wallet/ledger reconciliation results are published.

05 / NEXT ITERATION

What I’d improve next

Durable verification and retry safety

Put telemetry on a durable queue, add a concurrency-safe idempotency strategy, and verify that retries cannot create duplicate charges.

Calibrate the judge

Evaluate labeled agent responses and report false-positive and false-negative rates. A false positive can create an incorrect charge, so aggregate accuracy alone is insufficient.

Measure the full system

Compare direct and proxied requests under a fixed workload. Report response overhead separately from verification time, and reconcile wallets with ledger entries after load and failure tests.

Implementation references are pinned to repository revision 9943ff1. Performance claims originate in the September 2026 résumé; no new load-test results are claimed here.

NEXT CASE STUDYDistributed Vector Database