Skip to content

feat(ai): hold the reference prices in a repository-owned setting #4244

Closed

Description

@devops-cli-service

Split from #4241.

Problem: the price of the two reference models is the file pricing_overrides.json in /home/devops/.data/ai/ on the PVC roadmap-service-home. A person writes it by hand with devops ai cost set-price in the pod. genai-prices 0.1.13 returns LookupError for qwen3.8:27b and qwen/qwen3-embedding-8b, so without the file the reports show no savings and log an unpriced warning. A new PVC loses the file.

Why deferred: the repository-owned price needs new code, a setting that holds the price and that PricingRegistry reads. That is a separate change from the ConfigMap template fix.

Acceptance criteria: a setting holds the input and output price per million tokens of a reference model. PricingRegistry reads the setting before it asks genai-prices. The ConfigMap template sets the prices of qwen3.8:27b (0.035 and 1.50 USD) and qwen/qwen3-embedding-8b (0.01 USD). A test shows that the reports price both models with no pricing_overrides.json file. The key-walk test of tests/k8s/test_k8s_configmap_keys.py passes.

Proposed design

Problem statement

The price of the two reference models, qwen3.8:27b and qwen/qwen3-embedding-8b, lives only in the hand-written file pricing_overrides.json on the PVC roadmap-service-home. genai-prices 0.1.13 returns LookupError for both models. Without the file, the reports show no savings and log an unpriced warning. A new PVC loses the file. The repository must own these prices in a setting that PricingRegistry reads. The example ConfigMap sets no ai.reference_model or ai.reference_embedding_model today, so the change must also name the two models there, or the prices would never be used.

Acceptance criteria

Requirement: Reference price setting

The AIConfig model of Settings SHALL hold a mapping from model name to the input price and the output price per million tokens, in USD.

Scenario: A setting with both prices loads

  • WHEN a config with ai.reference_prices naming a model with an input and an output price is validated by Settings
  • THEN the validation passes and Settings returns both prices for that model

Requirement: Setting read before genai-prices

PricingRegistry MUST read the price from the setting before it asks genai-prices, in get_pricing, price_reference and calculate_request_cost.

Scenario: The setting wins over genai-prices

  • WHEN the setting holds a price for a model, no pricing_overrides.json exists, and genai-prices is replaced by a stub that raises an error
  • THEN PricingRegistry returns the price of the setting with a source that names the setting, and does not call the stub

Requirement: Override file wins over the setting

A price in pricing_overrides.json MUST win over the price of the setting for the same model.

Scenario: File and setting name one model

  • WHEN pricing_overrides.json and the setting both hold a price for one model
  • THEN PricingRegistry returns the price of the file

Requirement: Fallback to genai-prices

PricingRegistry SHALL ask genai-prices for a model that neither the override file nor the setting names.

Scenario: A model with no setting entry

  • WHEN PricingRegistry prices a model that the setting does not hold
  • THEN PricingRegistry returns the price of genai-prices

Requirement: ConfigMap template prices

The ConfigMap template SHALL set ai.reference_model to qwen3.8:27b and ai.reference_embedding_model to qwen/qwen3-embedding-8b, with 0.035 USD input and 1.50 USD output for the first and 0.01 USD input for the second.

Scenario: The rendered ConfigMap holds the prices

  • WHEN the test renders the active devops ConfigMap and loads its settings
  • THEN the setting holds the three prices as stated for the two models, and the embedding output price is 0

Requirement: Reports price both models without the file

The reports MUST price both reference models when no pricing_overrides.json file exists.

Scenario: Reports with no override file

  • WHEN a report runs on local usage of chat and embedding tokens with settings from the ConfigMap template and no pricing_overrides.json file
  • THEN each reference model has a price, the savings show, and no unpriced warning is logged

Requirement: Key-walk test passes

The ConfigMap template MUST name only keys that Settings declares.

Scenario: Key walk of the example ConfigMap

  • WHEN tests/k8s/test_k8s_configmap_keys.py runs
  • THEN unknown_setting_keys returns an empty list and the test passes

Existing Tool Considered

genai-prices 0.1.13 is already in use and is open and maintained. It lacks a price for qwen3.8:27b and qwen/qwen3-embedding-8b, and it has no repository-owned override that a ConfigMap can set. Its own custom-snapshot route (set_custom_snapshot, used for pricing_snapshot.json in src/devops_cli/ai/spend/pricing.py:440-452) needs a provider file on disk, so it is no lighter than the existing override file. The change builds a small pydantic field in AIConfig and one lookup step beside the existing _get_override_pricing in PricingRegistry. Cost: a few thousand tokens to build and test, one pull request, and under one hour of elapsed time. Upkeep is low because the prices change rarely.

Key questions

  • Where does the price setting live, and what is its shape?: Add the field reference_prices to AIConfig, a mapping from model name to a small pydantic model with input_usd_per_million and output_usd_per_million (defaults 0.0, ge=0, no NaN). AIConfig already holds reference_model, reference_embedding_model and reference_provider, and the ConfigMap renders the ai section. unknown_setting_keys does not read the keys of a plain mapping field, so model names such as qwen3.8:27b need no declaration. ModelPricing (prompt_usd_per_million, completion_usd_per_million) is the type the registry already returns, so the registry converts the entry to a ModelPricing. (best practice) [sources: src/devops_cli/config/settings.py:671, src/devops_cli/config/settings.py:682, src/devops_cli/config/setting_keys.py:24, src/devops_cli/ai/spend/models.py:15, k8s/devops/configmap.example.yaml:13]
    • Chosen: Field reference_prices in AIConfig, model name to prices. AIConfig already owns the reference model settings, the ConfigMap template renders it, and the key-walk test accepts the mapping.
    • Rejected: A second JSON file in the repository. It adds a file format, and the ConfigMap would not carry it to the pod.
    • Rejected: Fields on AIConfig for each of the two models (chat input, chat output, embedding input). It ties the setting to two slots and breaks when a reference model changes; a mapping keyed by model name follows the model.
  • Which price wins when the setting and pricing_overrides.json both name a model?: The override file wins over the setting, and the setting wins over genai-prices. The registry already resolves an override before genai-prices in get_pricing and calculate_request_cost, so the new lookup goes right after _get_override_pricing in both. A person's devops ai cost set-price keeps its effect, and the setting is a default that survives a new PVC. A local call still costs 0 before either lookup. (best practice) [sources: src/devops_cli/ai/spend/pricing.py:469, src/devops_cli/ai/spend/pricing.py:503, src/devops_cli/ai/spend/pricing.py:609, src/devops_cli/ai/spend/pricing.py:615]
    • Chosen: Override file, then setting, then genai-prices. It keeps the existing override semantics and adds a repository default below the person's choice.
    • Rejected: Setting, then override file, then genai-prices. A set-price command would have no effect for a model that the setting names.
  • Does the key-walk test render the example ConfigMap that the template change edits?: Yes. The test renders the active devops ConfigMap from the k8s directory, validates it with Settings and walks each key with unknown_setting_keys, so ai.reference_prices must be a field of AIConfig. [sources: tests/k8s/test_k8s_configmap_keys.py:26, tests/k8s/test_k8s_configmap_keys.py:36, src/devops_cli/config/setting_keys.py:18]
  • Does the ConfigMap template name the reference models today?: No. k8s/devops/configmap.example.yaml sets no ai.reference_model and no ai.reference_embedding_model, so the Service uses the defaults (gpt-4o-mini and text-embedding-3-small). The change must set both to qwen3.8:27b and qwen/qwen3-embedding-8b next to the prices. Repository docs (docs/CONFIGURATION.md, docs/ENV_VARS.md) are generated from the field declarations, so they need regeneration with the new field. [sources: k8s/devops/configmap.example.yaml:13, src/devops_cli/config/settings.py:682, src/devops_cli/config/settings.py:686, docs/CONFIGURATION.md:203]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-18: none.
Tool: none found.
Reason: Searches found only genai-prices, already in use; its custom snapshot needs a provider file on disk, so no open tool offers a repository-owned price table that the ConfigMap sets and PricingRegistry reads.

Covers:

  • Price lookup for models the upstream snapshot knows
  • Custom snapshot route loaded from a provider file
  • Per-token input and output cost of a request

Lacks:

  • No price for qwen3.8:27b or qwen/qwen3-embedding-8b
  • No ConfigMap-settable price a pod can read
  • Custom snapshot needs a file on disk, lost with a new PVC
  • No setting that a pydantic Settings field holds

Activity

  1. added
    source/agent
    type/feature
    scope/ai
    status/new
    value/medium
    effort/medium
    on Nov 9, 2026
  2. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    ContributorAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/ai. The (ai) scope of the title gives the scope.
    • Priority: P2-Medium. A lost price file hides the savings in the reports, but the service continues to run.
    • Value: Medium. The reports price both reference models on a new PVC or cluster with no hand-written file.
    • Effort: Medium. The change needs a new setting, a PricingRegistry change, a template change and a test.
    • Possible duplicate: feat(ai): a setting holds the price of a reference model #4242, which may ask for the same change. The model names A repository-owned setting holds the input and output price of a reference model, and PricingRegistry reads the setting before genai-prices. as the change that both ask for. Both items ask for the same setting that holds the reference model price and that PricingRegistry reads before genai-prices. A person closes one of the two if that is so.
  3. added
    priority/p2-medium
    status/ready
    and removed
    status/new
    on Nov 9, 2026
  4. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    ContributorAuthor

    Status set to Ready at cc3d22e (see proposed design in issue body).

  5. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    ContributorAuthor

    Alternatives check: in-use

    Reason: Searches turned up no open, maintained tool that supplies a repository-owned price setting which this project's own PricingRegistry reads before its lookup. genai-prices is the pricing library the project already uses: it covers per-million-token price lookup and cost calculation, but it holds no price for qwen3.8:27b or qwen/qwen3-embedding-8b and offers no ConfigMap-settable override (its custom-snapshot route still needs a provider file on disk), so the settings field, the ConfigMap template change and the registry lookup order remain repository code.

    The item already names this tool.

    Tool: genai-prices (https://pypi.org/project/genai-prices)

    • License: MIT
    • Last activity: 2026-11-10
    • Maintained: yes

    Covers:

    • Looks up per-million-token input and output prices for the models it knows
    • Computes request cost from token counts, which PricingRegistry already returns as ModelPricing
    • Runs in the existing pipeline beside the pricing_overrides.json file, so no new dependency or service

    Lacks:

    • No price for qwen3.8:27b or qwen/qwen3-embedding-8b; it raises LookupError for both
    • No repository-owned setting that a ConfigMap can carry to the pod
    • Its custom-snapshot route (set_custom_snapshot) needs a provider file on disk, no lighter than the existing override file
    • A pydantic AIConfig field, the ai.reference_prices keys in the ConfigMap template and the override-then-setting-then-genai-prices lookup order are this repository's own code
    • The key-walk test of the example ConfigMap needs the new Settings field, which no library provides

    Tools considered:

    Searches run:

    • python library LLM model token pricing per million tokens lookup, results: 5
    • litellm model_prices_and_context_window.json custom pricing override, results: 5
    • open source LLM pricing database JSON maintained model cost map, results: 5
    • genai-prices pydantic model price lookup library, results: 5
    • models.dev open catalog of model prices API, results: 5
    • pydantic-settings mapping field configmap kubernetes model prices, results: 5

    Sources:

    Checked on 2026-11-10. A person decides what this means for the item. The check changes no label and closes no issue.

  6. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    ContributorAuthor

    The result in the alternatives block of the issue body changed. Before this check: in-use, tool https://pypi.org/project/genai-prices. A person decides what the new result means for the item.

    Searches (8)

    Tools considered:

    Searches run:

    • python library configurable model pricing table override per million tokens, results: 5
    • genai-prices custom snapshot pricing override python, results: 5
    • "genai-prices" set_custom_snapshot LookupError, results: 5
    • genai-prices pypi package, results: 5
    • genai prices github repository pydantic-ai pricing, results: 5
    • LLM price table open source library custom model pricing yaml config, results: 5
    • litellm model prices json override cost tracking python, results: 5
    • pydantic genai-prices custom snapshot provider file, results: 5

    Sources:

  7. added
    owner/service
    on Nov 22, 2026
  8. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    ContributorAuthor

    Plan state: branch feat/4244-hold-the-reference-prices-in-a, draft pull request #6766. The pull request plans the item and closes no issue. The stage job and the step fix-plan edit this comment, and a comment of each run tells what the run did.

    The task groups, with the tokens of the inputs of each step, for a budget of 64000 tokens:

    1. Test both reference prices from the committed ConfigMap template: 23240 tokens

    A model review of the plan found these points. They stop no draft, and a person judges them:

  9. 8 remaining items

  10. added
    status/in-progress
    status/in-review
    and removed
    status/in-progress
    on Nov 22, 2026
  11. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    ContributorAuthor

    The draft pull request #6779 holds the final title and body. In mode on of roadmap.fix_checks.mode, the watch row marks it ready when its checks pass, and a fix-checks Job repairs a failed check whose name gives the class test, lint or types. In each other case the watch row stops the item: another failed check, a cancelled check, a conflict, a fix-checks Job that ended with no repair, or another mode.

    Spend: 50 model requests, 3468494 input tokens, 22690 output tokens.

  12. removed
    owner/service
    on Nov 22, 2026
  13. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    ContributorAuthor

    Stopped at pull request.

    Failure class: lint.
    Action taken: none.
    Action left: repair: give the failure to a fix step.

    Reason:

    The check Static Analysis of the draft pull request #6779 failed or was cancelled, and no fix-checks Job repairs it.

    The item is Blocked: the implement Job ended at the draft, and no fix-checks Job takes this case. Fix the cause. Then comment implement: retry.

  14. added
    status/blocked
    and removed
    status/in-review
    on Nov 22, 2026
  15. added
    status/in-review
    and removed
    status/blocked
    on Nov 23, 2026
  16. removed
    status/in-review
    on Nov 23, 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

    effort/mediumpriority/p2-mediumscope/aisource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions