Skip to content

Meter inference usage for cost calculation - #4512

Closed
Igx22 wants to merge 8 commits into
dstackai:masterfrom
Igx22:pr_ds002_usage_counters
Closed

Igx22 wants to merge 8 commits into
dstackai:masterfrom
Igx22:pr_ds002_usage_counters

Conversation

@Igx22

@Igx22 Igx22 commented Nov 23, 2026

Copy link
Copy Markdown

Problem
Operators need to measure usage for every inference request routed through dstack and retain enough data to calculate costs by user and service.

Solution
Add Gateway metering for OpenAI-compatible API requests. Count output tokens and record total and cached prompt tokens to calculate the cache hit rate. Define how to count requests when they are retried or streams are interrupted. Store per-minute totals by user and service in a queryable table.

Implement DS-002 with verified subject/service counters, JSON and SSE token usage, durable minute checkpoints, and fetch/commit/ACK delivery to server receipts. Add the local Python testbed, six acceptance scenarios, and ingress coverage. Keep quota enforcement outside this change.
Replace collector IDs with historical Gateway and replica identities. Consolidate the unapplied usage migration into two tables, preserve legacy checkpoint and API compatibility, and cover replay, persistence, multi-replica collection, and migration behavior.

Include the local Gateway configuration retry increase from 50 to 300.

Validation: 204 tests passed, 1 opt-in real-minute test skipped; local Nginx and PostgreSQL checks enabled. Ruff and formatting checks passed for all 18 changed files.
Keep serving requests and the management connection alive during retirement. Seal the final minute and require a durable ACK before terminating the VM so another server can replay a committed batch after lease takeover.
Use numbered user/run rows to enforce delivery keys and verify full batch replays. Keep page writes atomic and acknowledge only committed batches.
@Igx22 Igx22 closed this Nov 23, 2026
@Igx22

Igx22 commented Nov 23, 2026

Copy link
Copy Markdown
Author

сlosed

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.

1 participant