Skip to content

feat(finops): add provider cost arbitrage and budget governance - #1047

Merged
AmitoVrito merged 9 commits into
SynapseKit:mainfrom
DhruvGarg111:feat/issue-893-cost-governance
Sep 22, 2026
Merged

AmitoVrito merged 9 commits into
SynapseKit:mainfrom
DhruvGarg111:feat/issue-893-cost-governance

Conversation

@DhruvGarg111

Copy link
Copy Markdown
Collaborator

Summary

Closes #893.

  • Adds provider/model pricing with cached-input rates, latency SLAs, quality metadata, regional overrides, and pluggable refresh sources.
  • Extends CostQualityRouter with quality/latency-aware arbitrage, provider-aware pricing, tenant/API-key budgets, atomic reservations and settlement caps, spend attribution, fallback-chain composition, and optional carbon accounting.
  • Adds synapsekit_budget_remaining_usd and synapsekit_arbitrage_savings_usd Prometheus gauges.
  • Adds a deterministic 100-request trace replay harness and a CI gate requiring at least 40% savings at equal quality.
  • Documents the one-line cost-governance setup in the README and observability guide.

Commits

  1. feat(finops): add provider pricing and budget governance
  2. feat(observability): add FinOps spend gauges
  3. test(ci): add cost arbitrage benchmark gate

Verification

  • Focused LLM/router/fallback/observability/public API tests: 99 passed.
  • Optional Prometheus-enabled tests: 22 passed.
  • Benchmark gate: 2 passed.
  • Standalone 100-task replay: 95.2% savings ($0.036000 vs $0.750000) with equal quality (0.920 vs 0.920).
  • Ruff check and format, mypy, deptry, async-blocking, lock, CI YAML, and git diff --check passed.
  • The full local Windows suite remains affected by unrelated existing platform-sensitive tests; the first isolated failure is tests/agents/test_tools.py::TestPythonREPLTool::test_timeout_on_slow_operation.

No provider SDK or network service is required by the benchmark.

@DhruvGarg111
DhruvGarg111 force-pushed the feat/issue-893-cost-governance branch from 1e179b8 to 6d9ec5d Compare September 17, 2026 13:16
@DhruvGarg111
DhruvGarg111 force-pushed the feat/issue-893-cost-governance branch from 6d9ec5d to 10ef007 Compare September 17, 2026 13:17
AmitoVrito and others added 6 commits September 22, 2026 18:57
…et cap bypass

record_spend() wrote spend under the raw (unstringified) tenant_id/api_key_id
while every budget check reads via str(tenant_id)/str(api_key_id), so a
non-string identifier silently bypassed the cap indefinitely.

Co-authored-by: Dhruv Garg <[email protected]>
_stream_generate only re-raised BudgetExceededError after exhausting every
candidate; any other exception (network error, provider outage) silently
ended the generator with zero tokens, unlike generate()/call() which always
raise. Restores symmetry so stream() callers can distinguish a genuinely
empty response from total candidate failure.

Co-authored-by: Dhruv Garg <[email protected]>
…erage

BudgetLedger.commit() re-validates actual cost against the cap at
settlement time, which could previously raise BudgetExceededError after
the provider call already succeeded — discarding a response the caller
already paid for. commit() now accepts force=True to record real spend
without re-checking the cap, and CostQualityRouter uses it as a fallback:
log the overage and still return/stream the response. The pre-call
reserve()/check_before() cap enforcement is unchanged.

Co-authored-by: Dhruv Garg <[email protected]>
The original CostQualityRouter implementation was renamed to
_LegacyCostQualityRouter when the new finops-aware router was added, but
nothing in src/ or tests/ ever referenced it.

Co-authored-by: Dhruv Garg <[email protected]>
…dition

Once a tenant/API-key budget is configured, routing to a model missing
from the pricing table now hard-fails instead of silently costing $0 —
call this out as a precondition so custom/self-hosted models get their
pricing registered up front.

Co-authored-by: Dhruv Garg <[email protected]>
@AmitoVrito
AmitoVrito merged commit 45d12d1 into SynapseKit:main Sep 22, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provider cost-arbitrage router & budget governance

2 participants