SDK Quick Start
Wrap your LLM client with the SuperPenguin Python SDK to get per-request cost tracking, customer attribution, and spend analytics.
Install the SDK & get your key
Install the SDK with pip install superpenguin, then go to SDK Keys and create an SDK API key. You'll get a key starting with sp_. Copy it — it's only shown once.
Wrap your LLM client
Initialize the SDK with your sp_ key, then wrap your OpenAI, Anthropic, or LiteLLM client. No base URL changes needed — calls go directly to the provider.
Python (OpenAI)
import superpenguin as sp
from openai import OpenAI
sp.init(api_key="sp_...")
client = sp.wrap(OpenAI())
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}]
)Add metadata for attribution
Set default metadata on your client, or pass per-call metadata via extra_body to attribute costs to customers, features, teams, or environments.
Python (OpenAI)
# Set default metadata for all calls from this client
client = sp.wrap(OpenAI(), metadata={
"customer_id": "cust_acme_123",
"feature": "doc_summary",
"team": "product",
"environment": "production",
})
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Summarize this"}],
)Metadata Fields
| Field | Type | Purpose |
|---|---|---|
prompt_key | string | Identifies the prompt — appears on the Prompts analytics page |
prompt_version | string | number | Version identifier of the prompt (e.g. "1", "beta", "2.1") |
customer_id | string | End-customer or account consuming the AI call |
feature | string | Product feature name (e.g., search, support_agent) |
team | string | Internal team owning the feature |
environment | string | production, staging, dev, etc. |
* | string | Any other key is stored as a custom tag |
All fields are optional. Start with none and add them incrementally.
View your data
Go to the Attribution page. You'll see:
KPI Cards
Total SDK spend, request count, avg cost per request
Breakdown Tabs
Slice by model, provider, customer, feature, team, or environment
Drilldowns
Click any row to see nested attribution (e.g., models per customer)
Recent Requests
Individual request log with tokens, cost, latency, metadata
Switch to the Reconciliation tab to compare SDK-estimated costs against your actual provider bills.
Prompt Tracking
Track cost and performance per prompt by passing prompt_key and optionally prompt_version in your request metadata.
How it works
- Add
prompt_keyto yourmetadataorsp_metadata - The SDK logs each request with that key
- Open the Prompts page to see cost, request count, and active version per prompt
- Click into a prompt to compare versions side-by-side (avg cost, request volume)
Version comparison
Use prompt_version to A/B test prompt changes. Versions can be numbers (1, 2) or strings ("beta", "v2.1"). The Prompts detail page shows a bar chart comparing cost and volume across versions.
Recommended naming
summarize-articleKebab-case, descriptive
support-agent-v2Include context if needed
onboarding.welcomeDot notation for grouping
extract-invoice-dataAction-oriented names
Cost Estimation
The SDK includes a built-in pricing table for automatic cost estimation. Models with known pricing:
| Model Prefix | Provider |
|---|---|
gpt-*, o3-*, o4-* | OpenAI |
claude-* | Anthropic |
gemini-* | |
grok-* | xAI |
Unknown models still get tracked (tokens, latency, metadata) — cost shows as $0 until pricing is added.
What Gets Logged
Every request logs: provider, model, token counts, estimated cost, latency, status code, streaming/tools/vision flags, and all metadata fields.
Never logged
Prompt content, response content, images, audio, tool arguments, or function results. The SDK does not capture conversation data.
Troubleshooting
| Problem | Fix |
|---|---|
sp.init() has not been called | Call sp.init(api_key="sp_...") or set SP_API_KEY env var |
Unsupported client type | sp.wrap() supports OpenAI, AsyncOpenAI, Anthropic, and AsyncAnthropic |
| Attribution page is empty | Data appears within seconds — try refreshing |
| Cost shows as $0 | Model may not be in the pricing table yet — tokens and latency still track correctly |