Skip to content

feat(ai): llm gateway tuning cost from real traffic and no-load capacity estimates #477

Description

@dan-petty

Context & Rationale

The tuner measures cost with a probe on a synthetic prompt, and measuring capacity takes a sweep of about eight minutes that loads every backend. The vLLM backends were removed in #734, so vLLM's lifetime counters (which also counted every benchmark request, the tuner's own included) are no longer an alternative; real traffic comes from the spend ledger.

Scope & Deliverables

  • Context & Rationale*: The tuner measures cost with a probe on a synthetic prompt, and measuring capacity takes a sweep of about eight minutes that loads every backend. The vLLM backends were removed in feat(k8s): modernize monitoring stack, llm profiles, traefik routing, and remove squid proxy #734, so vLLM's lifetime counters (which also counted every benchmark request, the tuner's own included) are no longer an alternative; real traffic comes from the spend ledger.
  • Deliverable*: Take cost (tokens per review request, per backend) from the spend ledger's recorded serving backend. Persisting measurements already shipped in v0.2.23 (devops ai gateway tune records each run via record_run(Mechanism.GATEWAY_TUNE)), so add --estimate on top of those records: capacity for a new or changed deployment, scaled by GPU memory bandwidth from a measured deployment running the same model and engine, without sending load.

Strategic Alignment

Proposed design

Problem statement

The AI gateway tuner currently measures cost using synthetic prompts and capacity through time-consuming backend sweeps. With vLLM backends removed, there's no way to use lifetime counters for cost estimation, so real traffic data from the spend ledger must be used instead.

Acceptance criteria

  • Criterion 1: Cost measurements are taken from the spend ledger's recorded serving backend
    Verification: Verify that the gateway tuner reads token usage per request from the spend ledger rather than synthetic probe data
  • Criterion 2: Capacity estimates can be made without sending load to backends
    Verification: Confirm that capacity estimation uses GPU memory bandwidth scaling from measured deployments running the same model and engine, without additional load generation
  • Criterion 3: Existing measurements are persisted with new --estimate flag
    Verification: Ensure that devops ai gateway tune records each run via record_run(Mechanism.GATEWAY_TUNE) and supports a new --estimate option to add capacity estimates

Key questions

None.

Open questions

  • What is the current method of measuring cost in the AI gateway tuner? (missing verified source)
  • How long does it take to measure capacity with the current method? (missing verified source)
  • What happened to vLLM backends in issue feat(k8s): modernize monitoring stack, llm profiles, traefik routing, and remove squid proxy #734? (missing verified source)
  • How will cost be measured now that vLLM backends are gone? (missing verified source)
  • What is the expected outcome of adding --estimate flag to existing records? (missing verified source)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added this to the v0.2.23 milestone on Sep 24, 2026
  2. added
    type/feature
    scope/ai
    priority/p2-medium
    on Sep 24, 2026
  3. modified the milestones: v0.2.23, v0.2.24 on Sep 28, 2026
  4. added a commit that references this issue on Sep 28, 2026
  5. modified the milestones: v0.2.24, v0.2.23 on Sep 30, 2026
  6. removed this from the v0.2.23 milestone on Oct 1, 2026
  7. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from the shipped v0.2.23 to the backlog. It is still valid (checked 2026-10-01), and P2 items don't displace P1 work in the planned releases.

  8. added
    priority/p3-low
    and removed
    priority/p2-medium
    on Oct 2, 2026
  9. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Grooming (2026-10-02): Priority p2-medium → p3-low. An optimization of an internal tuning tool. The tuner works today with a synthetic probe, and nothing is broken or at risk.

    Checked against the code at the release/v0.2.25 tip.

  10. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #478 and #595. Gateway routing is hand-tuned from synthetic probes; #478 renders what this item measures, and #595's slice 1 stores its results here. Found by the 2026-10-08 backlog review.

  11. added this to the v0.2.39 milestone on Oct 17, 2026
  12. dan-petty commented on Oct 22, 2026

    @dan-petty
    OwnerAuthor

    Returned to New: the tuner's recommendation has no consumer, so building the item as written would add machinery nothing reads.

    • The gateway routes least-busy and sets no weight anywhere: k8s/llm/gateway/configmap.yaml:166 names the strategy, and the file holds no weight: key. devops ai gateway render deletes weight: lines (src/devops_cli/ai/gateway_render.py:14,86-88), and docs/agent/tasks/task-478-*.md records the weights as meaningless under least-busy. The only readers of the tuner's capacity and cost figures are recommend_weights and the table in commands/ai_gateway.py:342-361, so better cost and capacity numbers would change nothing the gateway does.
    • The item's two deliverables (cost from the spend ledger, a bandwidth-scaled --estimate) are buildable, but the physical model is shaky: the capacity pass relies on ignore_eos, which gateway_bench.py:12,124 says only vLLM honours, and no vLLM backend remains; summing GPU bandwidth over-predicts layer-split Ollama on multi-GPU nodes. Checking either needs a live cluster, a prior live gateway-tune run record and a populated spend ledger.
    • The priority is P3 and the 2026-10-02 owner comment says the tuner "works today with a synthetic probe, and nothing is broken".

    Proposed re-scope, a deletion item: remove recommend_weights, calculate_hardware_weights, _deployment_hardware_score, _deployment_bandwidth_sum, settings.ai.gateway_weights, the Weight, Recommended and Est. req/s columns with the "set litellm_params.weight" footer, the CONST_ENGINE_MULTIPLIER_* constants, the vLLM remnants in gateway_bench.py, and the stale weight text in k8s/README.md:87-99 and the gateway_tune.py module docstring.

  13. removed this from the v0.2.39 milestone on Oct 22, 2026
  14. added a commit that references this issue on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p3-lowscope/aitype/feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions