cost-attribution
Track per-client and per-feature LLM and cloud spend with cryptographic audit trail. Use whenever billable operations occur - LLM API calls, infrastructure provisioning, batch jobs. Required for any project with multiple clients or cost-sensitive operations. Integrates with Stratum's append-only billing_records table.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- cost-attribution
- description
- Track per-client and per-feature LLM and cloud spend with cryptographic audit trail. Use whenever billable operations occur - LLM API calls, infrastructure provisioning, batch jobs. Required for any project with multiple clients or cost-sensitive operations. Integrates with Stratum's append-only billing_records table.
02 资源文件 1
- 其他SKILL.md.bundle9.4 KB
03 SKILL.md 正文
Cost Attribution
Per-tenant cost attribution from day one. Cryptographically signed audit trail.
Tradeoff: Every billable op needs a ledger entry. Worth it: client invoicing is automatic, surprise bills are caught early, and cost-by-feature guides optimization.
How it works
DevOPs ships two pieces of this: the Stratum billing_records ledger and the
budget caps below. The exporter, the report command and the anomaly job on
this page are the design to build in each project; none of them exists in
DevOPs yet.
- OTel baggage carries
tenant.idanduser.idon every span. - LLM calls auto-add
cost_usdvia OpenInference instrumentation. - The cost-attribution exporter aggregates costs by
tenant.idper hour. - Aggregates are written to:
- File:
.workflow/state/cost-ledger.jsonl(per-project) - Stratum:
billing_recordstable (HMAC-signed, append-only) if configured
- File:
- A report command (not yet built; see Reports below) summarizes the ledger.
Ledger entry shape
{
"ts": 1716372013,
"tenant_id": "client-abc",
"user_id": "user-123",
"session_id": "s-7f3a",
"operation": "llm.call",
"provider": "anthropic",
"model": "claude-sonnet-4-6",
"input_tokens": 1234,
"output_tokens": 567,
"cost_usd": 0.0122,
"hmac": "sha256:..." // Stratum signs server-side
}
Reports
Example monthly report for one client (illustrative figures; the devops
CLI has no cost-report command yet):
Client: client-abc
Period: 2026-05-01 to 2026-05-31
Total spend: $124.37
By provider:
Anthropic: $118.42
OpenAI: $5.95
By model:
claude-opus-4-7: $42.18 (12% of calls)
claude-sonnet-4-6: $63.71 (44% of calls)
claude-haiku-4-5: $12.53 (44% of calls)
By feature:
/api/auth: $34.21
/api/payments: $18.42
/api/search: $71.74
Cost per session: avg $0.34, p95 $1.21
Cost per request: avg $0.0023, p95 $0.012
Hard caps integration
hooks/universal/pre-tool/budget-brake.sh enforces the caps in
.workflow/state/budget.yml against its own ledger,
.workflow/state/budget-ledger.jsonl (not the cost ledger above):
- Per-session cap (default $5)
- Per-hour cap (default $20)
- Per-day cap (default $100)
When a cap is hit, the hook exits 2 and the tool call is blocked; the agent
cannot override it. It runs only once the harness registers it as a
PreToolUse hook (for Claude Code, in .claude/settings.json).
analyzer/install.ts copies the script without registering it, so check the
settings before relying on the cap.
Anomaly detection
A daily anomaly job (not yet built) should flag:
- Day-over-day spend > 3x weekly average
- Per-client spend exceeding contract terms
- Calls with token counts > 90th percentile (potential prompt bloat)
It should write anomalies to governance/telemetry/cost-anomalies.jsonl.
Anti-patterns
Tagging by session only: lose per-feature breakdown. Always include endpoint or skill name in span attributes.
No HMAC: ledger entries can be tampered. Always sign server-side.
No retention policy: ledger grows unbounded. Roll up to monthly aggregates after 90 days; archive raw to cold storage.
This skill is working when: client invoices reconcile to ledger entries exactly, and cost-anomaly alerts fire before manual review notices the spike.
04 同仓库更多 Skills
karpathy-guidelines
Behavioral guidelines that reduce common LLM coding mistakes. Apply whenever writing, modifying, or reviewing code. Don't assume requirements, don't overcomplicate, don't refactor unrelated code, and define success criteria before implementing. Use this skill on every non-trivial coding task to avoid bloat, silent assumptions, and completion-bias.
unsigned-missing-sig-fixture
Test fixture (F.09) — SKILL.md without an accompanying .sig file. Default install rejects with exit 2; --allow-unsigned --rationale="..." proceeds.
unsigned-mismatched-sig-fixture
Test fixture (F.09) — SKILL.md whose accompanying .sig signs different content. NFR-F3 hash check catches this even with --allow-unsigned.
karpathy-guidelines
Behavioral guidelines that reduce common LLM coding mistakes. Apply whenever writing, modifying, or reviewing code. Don't assume requirements, don't overcomplicate, don't refactor unrelated code, and define success criteria before implementing. Use this skill on every non-trivial coding task to avoid bloat, silent assumptions, and completion-bias.
webhook-idempotency
Defend against double-processing of webhook events across every provider (Stripe, GitHub, Slack, Twilio, SendGrid). Idempotency-key pattern + replay-window enforcement + dedupe-storage strategy. Triggers on any webhook handler authoring (route matching /webhook(s)?/, Stripe-Signature / X-Hub-Signature-256 header references). Defense against OWASP ASI02 (Tool Misuse) -- a replayed webhook that re-triggers a destructive tool is the canonical control-flow-level replay attack. Universal across providers; stack-specific signature verification lives in stack-specific skills.
semgrep-scan
Run Semgrep static analysis to detect insecure code patterns - SQL injection, XSS, path traversal, weak crypto, broken auth, OWASP Top 10 issues. Use on every file change touching security-sensitive code and as part of the tiered security gate. Complements gitleaks (which catches secrets) by catching insecure logic.