AgentCOGS is an open-source Python SDK and a self-hosted dashboard for customer-level AI unit economics. It attributes each LLM call to the customer who caused it, compares that cost with the monthly fee, and checks a per-customer budget before the next SDK call.
Know which AI customers make you money, and which ones are eating your margins. The blended total can look fine while one fee no longer covers the AI cost. Which customer stops making money this month.
pip install agentcogs
This package is the SDK. It is on PyPI. The customer list is the dashboard in the repository, and you run that yourself. A hosted API is not serving. The working sample is agentcogs.vercel.app.
What does the number mean?
AI margin is (monthly fee − attributed AI cost) / monthly fee. It is the contribution of the fee after attributed AI cost. It is not total customer profitability, and it is not accounting gross margin. People, infrastructure, support, payment processing, refunds, discounts, credits, and proration are outside it. Pace is a straight line from the cost so far. It does not forecast a change in behavior. You type the fee, or you pull that customer's Stripe subscription. The SDK does not invent it.
Install, configure, instrument, verify
AGENTCOGS_ENDPOINT defaults to http://localhost:8000. Create a workspace with the self-hosted dashboard, then:
import os
from openai import OpenAI
import agentcogs
agentcogs.init() # AGENTCOGS_API_KEY, AGENTCOGS_WORKSPACE_ID, AGENTCOGS_ENDPOINT
print(agentcogs.ping())
agentcogs.set_customer("acme") # your tenant id, once per request
with agentcogs.run(workflow_id="support") as ctx:
if os.environ.get("OPENAI_API_KEY"):
OpenAI().chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Say hi in one word."}],
max_tokens=5,
)
print(ctx.wait_for_ingest().accepted, ctx.run_id)
The SDK does not call a model. Inside the block, shekel reads token usage from the OpenAI or Anthropic call you make. When the block exits, that cost is posted. With no OPENAI_API_KEY, the same block posts a zero-cost run so you can see the row. Open that customer and type the monthly fee.
python examples/hello_agentcogs.py in the repository is this path. python examples/one_run.py posts one recorded cost of USD 0.84 and does not call a model.
How attribution works
set_customer() names the tenant for this request. run() watches the instrumented client calls in the block and posts one event with total_usd when the block exits. If no customer is set, run() raises before the block. A duplicate run_id is accepted as a duplicate and is not stored twice. A failed post sits in a local outbox and is retried. python -m agentcogs outbox status shows what has not been delivered.
What the budget check does
If monthly_budget_usd is already exceeded, the next run() raises CustomerBudgetExceededError and does not enter the block. Two calls already in flight can both pass. It is not an atomic reservation. A LiteLLM callback records cost after the provider has already answered, so it cannot stop that call.
LiteLLM does not ship the callback. You copy it from the repository. The FastAPI middleware is a separate extra: pip install "agentcogs[integrations]".
Supported integrations
| OpenAI and Anthropic | Usage read inside run() by shekel, which this package depends on |
| FastAPI | Set the tenant from the request. Needs the integrations extra |
| LangGraph | Wrap the graph |
| LiteLLM | A callback you register. It posts after the proxy call |
| Stripe | The subscription is the fee. An optional meter pushes usage you already attributed |
| Slack | A spike opens that customer |
One fictional account
Patternstack is a snapshot of forty fictional customers, as of 14 Nov 2026. The blended AI margin is 74.6%. Vellum Research has spent USD 5,822.84 against a fee of USD 8,200, so it is 29.0% so far, and the straight-line pace ends near −52.2%. The sample does not receive your calls.
Documentation
- Quickstart
- Self-host
- Customer id
- Docs index
- Repository README
- Sample: https://agentcogs.vercel.app
- Source: https://github.com/vaibhav11123/agentcogs
What is not guaranteed
A match against the provider invoice, refunds, credits, discounts, currency conversion, and a hard stop when two calls pass the pre-check together. Development status is Beta: the SDK surface is init, set_customer, run, ping, and shutdown, and a hosted API is not part of this release.
Metadata
Release files for agentcogs 0.2.1
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 |
|---|---|---|---|---|
| agentcogs-0.2.1.tar.gz | 27.8 kB | With provenance | Details for agentcogs-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agentcogs-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for agentcogs-0.2.1-py3-none-any.whl |
Total release size: 64.7 kB
Release files / agentcogs-0.2.1.tar.gz
| Download URL | agentcogs-0.2.1.tar.gz |
|---|---|
| Size | 27.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a98f7d43914f23bf92882f05f4ef4af99316b1458be86620c81a59a3905ec10c
|
|
BLAKE2b-256 checksum How to use checksums |
1e3288afeb7e6970f840c77eb34d81e2bddf842560c197c5aee4d73185b5727b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 25, 2026.
Transparency logRelease files / agentcogs-0.2.1-py3-none-any.whl
| Download URL | agentcogs-0.2.1-py3-none-any.whl |
|---|---|
| Size | 36.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66ec08e1a67877d5dcb061cd1c7c372e12bfb92959c6582159a775f397c7de38
|
|
BLAKE2b-256 checksum How to use checksums |
50435f1a1f7136ee495427d8001577f9f46264680d6691f6ed816446dc69dd15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 25, 2026.
Transparency logSecurity for agentcogs 0.2.1
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 agentcogs-0.2.1.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 Nov 25, 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.