Skip to content

fix(ai): price the DeepSeek group and its cached input - #4454

Merged
dan-petty merged 2 commits into
mainfrom
fix/4403-price-deepseek-models
Nov 11, 2026
Merged

dan-petty merged 2 commits into
mainfrom
fix/4403-price-deepseek-models

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The group deepseek-v4.1-flash-1017 runs every chat slot of the Service. genai-prices does not know it, so each call recorded 0 USD with the source unknown, and devops ai cost and the alert HostedSpendDailyHigh could not see it.

  • _HOSTED_GROUP_PRICES in the pricing registry prices the group under its route name and its deployment model: 0.0784 USD input, 0.002352 USD cached input and 0.2352 USD output per million tokens (OpenRouter endpoint deepinfra/fp8/flex, 2026-11-11). ai.price_overrides and the file of set-price win over it.
  • A price has an optional cached input rate. A prompt token that the provider read from its cache costs that rate. An agent run gives the cached tokens of its replies.
  • The gateway config holds the same rates. A test fails when a hosted group or a model of the Service template has no price, or when the two prices differ.

Closes #4403

Change: openspec/changes/archive/2026-11-11-4403-price-the-deepseek-models-in-the/

@dan-petty dan-petty added type/bug Type bug: the code does not do what it must scope/ai AI review pipeline, personas, prompts, LLM client, or RAG labels Nov 11, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Verification

  • uv run devops ci fail-to-pass --base origin/main: 7 tests fail on the base and pass on this branch (0 errored):
    • tests/ai/spend/test_hosted_group_prices.py: 5 of the 6 new tests fail (no price for the group under the route name and the deployment model, the Service template model records unknown, no cache_read_tokens argument, no cached input rate in AIPriceOverride).
    • tests/ai/client/test_roadmap_agent_run.py::test_a_run_on_the_deepseek_group_costs_its_cached_and_new_input_and_its_output: the base records 0.0 USD, the branch records 0.033477 USD on the ledger and on devops_cli_ai_spend_usd_total.
    • tests/ai/client/test_roadmap_agent_run.py::test_a_reply_that_names_a_model_keeps_that_name_for_the_price: the base gives the source unknown.
  • uv run devops ci test tests/ai/spend/ tests/ai/client/test_roadmap_agent_run.py tests/ai/benchmark/test_k8s_llm_gateway.py: 270 passed.
  • Full local CI (uv run devops ci) did not run: another agent held the shared CI lock for more than 10 minutes. This pull request relies on the GitHub checks.

Price source

OpenRouter API https://openrouter.ai/api/v1/models/deepseek/deepseek-v4.1-flash-1017/endpoints, read with no key on 2026-11-11 at 00:37 UTC. The endpoint deepinfra/fp8/flex gives 0.0784 USD input, 0.002352 USD cached input and 0.2352 USD output per million tokens. At these rates the cost of the three gateway callers from 2026-11-08 to 2026-11-11 is within 7% of the cost that the gateway recorded from OpenRouter. The archived proposal holds the comparison with the other endpoints.

Live cluster

  • The live ConfigMap devops/devops-cli-config needs no change. I read it on 2026-11-11: its ai.price_overrides holds only qwen3.8:27b and qwen/qwen3-embedding-8b. The Service pod has no pricing_overrides.json. So the built-in price applies when the Service runs the new image.
  • Do not apply the lines of chore(k8s): apply the DeepSeek price to the live devops-cli-config #4423 (deepseek-v4.1-flash-1017:floor at 0.05 and 0.192 USD). An ai.price_overrides entry wins over the built-in price, and those rates differ from the recorded cost by 20% to 117%. chore(k8s): apply the DeepSeek price to the live devops-cli-config #4423 has no work left after this change.
  • Argo CD applies the new rates of k8s/llm/gateway/config.yaml. The gateway records the cost that OpenRouter reports, so these rates are only its fallback.

Alerts

HostedSpendDailyHigh (sum(increase(devops_cli_ai_spend_usd_total[24h])) > 25) now sees the DeepSeek spend. At the new price the Service records about 5 USD a day, so the threshold still fits. ClaudeSpendDailyHigh reads only claude-sonnet-5-5, and this change does not change its price.

Other hosted models

genai-prices 0.1.13 prices gemini-3.8-flash, claude-sonnet-5-5 and claude-haiku-5-5. The new test fails when a hosted group of the gateway config has no price. Jev through the pass-through is #4296.

Follow-up

The group deepseek-v4.1-flash-1017 runs every chat slot of the Service, but genai-prices 0.1.13 does not know it, so each call recorded 0 USD with the source unknown. The spend counter, `devops ai cost` and the alert HostedSpendDailyHigh could not see the spend of the Service.

- `_HOSTED_GROUP_PRICES` in the pricing registry holds the price of the group under its route name and its deployment model: 0.0784 USD input, 0.002352 USD cached input and 0.2352 USD output per million tokens (OpenRouter endpoint deepinfra/fp8/flex, 2026-11-11). The file of set-price and `ai.price_overrides` win over it.
- A price has an optional cached input rate. The registry prices the prompt tokens that the provider read from its cache at that rate, and passes them to genai-prices. An agent run gives the cached tokens of its replies. 94% of the prompt tokens of the group come from the cache.
- The gateway config sets the same three rates, and a test fails when a hosted group has no price, when a model of the Service template is not priced or local, or when the client and gateway prices differ.
@dan-petty
dan-petty force-pushed the fix/4403-price-deepseek-models branch from 5a6e622 to bd7ea6d Compare November 11, 2026 02:55
@dan-petty
dan-petty marked this pull request as ready for review November 11, 2026 03:08
@dan-petty
dan-petty enabled auto-merge (squash) November 11, 2026 03:09
@dan-petty
dan-petty merged commit 3b1f6bd into main Nov 11, 2026
31 of 32 checks passed
@dan-petty
dan-petty deleted the fix/4403-price-deepseek-models branch November 11, 2026 03:12
@dan-petty

Copy link
Copy Markdown
Owner Author

Review follow-up. This pull request merged before the fix, so I did not push to it.

Finding 1 (major, src/devops_cli/ai/client/factory.py:228): the build_agent spend hook gives no cache_read_tokens. Confirmed.

  • Code on main at 54743c4: _spend_hook gives track_request_spend the input, output and reasoning tokens, but not cache_read_tokens. Only record_run_spend (src/devops_cli/roadmap/agent_run.py) gives it, and only the implement step calls record_run_spend.
  • Run on merged code: a build_agent reply with 1,000,000 input, 900,000 cached and 100,000 output tokens on deepseek-v4.1-flash-1017. The hook gave no cache_read_tokens. The recorded cost is 0.10192 USD; the correct cost is 0.033477 USD.
  • Workstation ledger (read-only query): 2,657 DeepSeek agent_run rows with stage analysis (189.8 M prompt tokens), and 1 row with stage implement (2.1 M prompt tokens). The analysis rows come from the factory hook.
  • Action: filed fix(ai): price cached prompt tokens of build_agent runs #4483 with the fix and a test that expects 0.033477 USD. I commented on fix(ai): price cached prompt tokens of chat calls #4442 to correct its sentence about agent runs. I did not widen fix(ai): price cached prompt tokens of chat calls #4442, because it is refined to Ready for the LLMClient chat path only.

dan-petty pushed a commit that referenced this pull request Nov 11, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.111.0](v0.110.0...v0.111.0)
(2026-11-11)


### Features

* **roadmap:** a decision-point registry with a resolver chain
([#4453](#4453))
([b73e97a](b73e97a))
* **roadmap:** eval verify stores each case and resumes
([#4451](#4451))
([7c59565](7c59565))
* **roadmap:** extend a step budget when the run makes progress
([#4464](#4464))
([c8ed108](c8ed108))


### Bug Fixes

* **ai:** a failed model transport names its phase and its error
([#4460](#4460))
([54743c4](54743c4))
* **ai:** price the DeepSeek group and its cached input
([#4454](#4454))
([3b1f6bd](3b1f6bd))
* **roadmap:** stage and refine send no answer count or row
([#4484](#4484))
([d9c8ee8](d9c8ee8))
* **roadmap:** tool docstrings garble the answer format
([#4486](#4486))
([2f6114f](2f6114f))


### Performance Improvements

* **roadmap:** parse only the bodies that hold a job record
([#4455](#4455))
([c653bde](c653bde))
* **tests:** evaluate hour-scale promtool tests every hour
([#4462](#4462))
([0ac2f76](0ac2f76))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/ai AI review pipeline, personas, prompts, LLM client, or RAG type/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ai): price the DeepSeek models in the price table

1 participant