Lightweight Python SDK for LLM cost tracking and attribution. Track every OpenAI, Anthropic, and Gemini call — cost, tokens, latency — by feature, team, and user.
Project description
CogsLayer
Know the true cost of every feature you ship.
CogsLayer tracks the direct costs of delivering your software — starting with AI. Attribute spend to features, teams, and models. Cut what's wasted.
Start free at cogslayer.com.
Two ways in
1. Python SDK (2 lines of code)
pip install cogslayer
import cogslayer
from cogslayer.openai import OpenAI
cogslayer.init(api_key="cl_live_xxx", service="my-api")
client = OpenAI()
@cogslayer.track(feature="chat", team="growth")
def ask(prompt: str) -> str:
resp = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": prompt}],
)
return resp.choices[0].message.content
Drop-in replacement clients for OpenAI, Anthropic, and Gemini. Every call is automatically tracked with cost, tokens, latency, and attribution context.
2. Provider integration (60 seconds, zero code)
Paste your OpenAI org key or Anthropic admin key. CogsLayer pulls actual billed costs — not token-based estimates — and syncs automatically.
Supported: OpenAI, Anthropic, Cursor, Claude Code.
Track. Understand. Save.
| What you get | |
|---|---|
| Track | Every call tracked with cost, tokens, and latency. Attribute spend to features, teams, models, and services with @cogslayer.track. Agent sessions grouped automatically. |
| Understand | Dashboard with spend by team, feature, model, provider. Actual billed costs from provider APIs. Estimate vs. billed drift detection. Budget alerts and forecasting. |
| Save | Waste detection flags duplicates, retry bloat, and oversized models. Optimization rules with one-click apply. Realized savings ledger proves ROI. |
Wrapped clients
OpenAI
from cogslayer.openai import OpenAI, AsyncOpenAI
client = OpenAI() # exact same API as openai.OpenAI
async_client = AsyncOpenAI() # exact same API as openai.AsyncOpenAI
Tracks chat.completions.create(), chat.completions.parse(), chat.completions.stream(), and responses.create().
OpenAI-compatible providers
from cogslayer.openai import OpenAI
groq = OpenAI(
base_url="https://api.groq.com/openai/v1",
api_key="gsk_...",
provider="groq",
)
Works with Groq, Together, Fireworks, Ollama, or any OpenAI-compatible API.
Anthropic
from cogslayer.anthropic import Anthropic, AsyncAnthropic
client = Anthropic()
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
Tracks messages.create() and messages.stream(). Captures cache tokens.
Google Gemini
from cogslayer.gemini import Client
client = Client(api_key="...")
response = client.models.generate_content(
model="gemini-2.0-flash",
contents="Hello",
)
Tracks models.generate_content() (sync and async). Streaming supported.
What gets tracked
| Metric | Description |
|---|---|
prompt_tokens |
Input tokens |
completion_tokens |
Output tokens |
reasoning_tokens |
Thinking tokens (o1, o3, o4-mini) |
cached_tokens |
Prompt tokens served from cache |
cost_usd |
Estimated cost from pricing registry |
latency_ms |
Round-trip time |
has_tool_calls |
Whether the response included tool calls |
api_type |
chat / responses / messages / generate |
Attribution
Every call is tagged with context from @cogslayer.track():
| Field | Description |
|---|---|
feature |
Product feature (e.g. "chat", "code-review") |
team |
Owning team (e.g. "engineering", "support") |
user_id |
End-user identifier |
service |
Service name (set in init()) |
environment |
"production" / "staging" / etc. |
Streaming
Fully supported across all providers. CogsLayer injects stream_options for OpenAI and captures token counts from the final chunk automatically.
stream = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
Custom pricing
cogslayer.register_model(
"my-fine-tuned-gpt4",
prompt_price_per_1k=0.006,
completion_price_per_1k=0.012,
)
Running locally
./dev.sh
Requires Docker and Node 20+. Starts Supabase, platform API (:8000), dashboard (:3000), and website (:3001).
Supported providers
| Provider | SDK wrapper | Integration (billed costs) |
|---|---|---|
| OpenAI | from cogslayer.openai import OpenAI |
Yes |
| Anthropic | from cogslayer.anthropic import Anthropic |
Yes |
| Google Gemini | from cogslayer.gemini import Client |
— |
| Cursor | — | Yes |
| Claude Code | — | Yes |
| Any OpenAI-compatible | OpenAI(base_url=..., provider="groq") |
— |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cogslayer-0.1.0.tar.gz.
File metadata
- Download URL: cogslayer-0.1.0.tar.gz
- Upload date:
- Size: 32.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2da1eb78966f78fbc141aa66aa64a98f03f7b00b690a782a8b0a329a4b3b7d8
|
|
| MD5 |
535b854769a7d095e53c29d34d47ac76
|
|
| BLAKE2b-256 |
780be7534efb4e38553e526f657c5c30ff015529ff36875cfd16cfb8d2a24b50
|
File details
Details for the file cogslayer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cogslayer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 48.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e5964c1d6de99401e9f4cf4343df0a983f65a7c5fbe675fc28aff91769916d4
|
|
| MD5 |
32221bc377aec662ede61a079c80bb37
|
|
| BLAKE2b-256 |
a07e80369ad71a117a89244fb99d5426a0096ec7e31a467c1ae2ab83f9af100b
|