[PR #2970] [Engine] expose configured pricing in model listings #4370

Open
opened 2026-11-07 15:35:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2970
Author: @lindestad
Created: 10/17/2026
Status: 🔄 Open

Base: main ← Head: model-listing-pricing


📝 Commits (1)

  • d0ca672 serve: expose configured pricing in model listings

📊 Changes

3 files changed (+183 additions, -0 deletions)

View changed files

📝 docs/DETAILS.md (+26 -0)
📝 serve/server.py (+29 -0)
➕ serve/test_model_pricing.py (+128 -0)

📄 Description

Problem and result

I want to compare Hermes and OpenCode usage using the same simulated external API rates. Hermes can discover rates from an endpoint's model listing, but Strata 0.2.0-beta still omits them.

This adds an optional top-level pricing object to the run config and reports it in /v1/models and /models, including aliases. Existing configs need no edits: missing, null and empty pricing blocks leave the listing unchanged.

Closes #2969. This updates the existing PR after the tracker reset.

Approach

Validate known rates before loading the engine, then publish the supplied values unchanged. Rates accept finite, nonnegative numbers or decimal strings, including zero. Token rates are USD per token; request is USD per API request. The documented example uses OpenRouter's input_cache_read and input_cache_write; Hermes-style cache_read and cache_write also work. Unknown fields are preserved for extensions.

Rebased onto main e88ee39d, keeping the new config parsing and API-key preflight. The diff remains limited to the Python server, pricing tests and configuration documentation.

Validation

Tested revision 901c7be0 on 0.2.0-beta, based on e88ee39d. CachyOS Linux x86_64, Python 3.12.14, 91 GiB RAM; RTX 5080 (16 GB VRAM, driver 615.78.08), unused by these mock-engine tests.

Passed:

.venv/bin/python -m unittest serve.test_model_pricing \
  serve.test_server.ModelAliases serve.test_server.ConfigApiKey \
  serve.test_runconfig -q

25 tests passed, including config startup, both endpoints, aliases, free rates and exact response bytes without pricing.

.venv/bin/python -m unittest serve.test_model_pricing \
  serve.test_server serve.test_runconfig serve.test_lifecycle -q

368 tests passed in 110.086 seconds. git diff e88ee39d...901c7be0 --check also passed.

Direct comparison with unmodified main reproduced missing pricing there and confirmed that the patch publishes the configured rates. Both endpoints stayed byte-identical to main for no config file, an empty config, a model config and aliases without pricing. The reproduction command and output are below.

Baseline comparison command and output

Run from the PR checkout:

PYTHONPATH=. .venv/bin/python - <<'PY'
import json
import subprocess
import sys
import types
from pathlib import Path
from unittest import mock
from serve import test_model_pricing as T

base = 'e88ee39d'
parent = types.ModuleType('serve._pricing_baseline')
parent.__file__ = str(Path('serve/server.py').resolve())
sys.modules[parent.__name__] = parent
source = subprocess.check_output(['git', 'show', f'{base}:serve/server.py'], text=True)
exec(compile(source, parent.__file__, 'exec'), parent.__dict__)
probe = T.PricingStartup()
for cfg in (None, {}, {'model_name': 'review-model'}, {'model_name': 'review-model', 'aliases': ['local']}):
    actual = probe.listings(cfg)
    with mock.patch.object(T, 'S', parent):
        expected = probe.listings(cfg)
    assert actual == expected, cfg
print('PASS: byte-identical bodies to e88ee39d for both endpoints in all four no-pricing cases')
config = {'model_name': 'review-model', 'pricing': T.CARD}
with mock.patch.object(T, 'S', parent):
    previous = probe.listings(config)
for body in previous.values():
    assert 'pricing' not in json.loads(body)['data'][0]
for body in probe.listings(config).values():
    assert json.loads(body)['data'][0]['pricing'] == T.CARD
print('PASS: missing pricing reproduced on main; patch publishes exact configured rates on both endpoints')
PY
PASS: byte-identical bodies to e88ee39d for both endpoints in all four no-pricing cases
PASS: missing pricing reproduced on main; patch publishes exact configured rates on both endpoints

Failed: None observed.

Not run: GPU inference, a new live Hermes/OpenCode session, or backend builds. This change touches no engine or backend code; the HTTP checks use the mock engine.

Limits

These are operator-defined accounting rates. Clients calculate estimates from their own usage; Strata adds no billing or usage storage. This does not establish that OpenCode discovers rates through /v1/models.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/2970 **Author:** [@lindestad](https://github.com/lindestad) **Created:** 10/17/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `model-listing-pricing` --- ### 📝 Commits (1) - [`d0ca672`](https://github.com/Niko1221/Strata/commit/d0ca672f5d226a49aab2a7cb5db66119bfc322c9) serve: expose configured pricing in model listings ### 📊 Changes **3 files changed** (+183 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+26 -0) 📝 `serve/server.py` (+29 -0) ➕ `serve/test_model_pricing.py` (+128 -0) </details> ### 📄 Description ## Problem and result I want to compare Hermes and OpenCode usage using the same simulated external API rates. Hermes can discover rates from an endpoint's model listing, but Strata 0.2.0-beta still omits them. This adds an optional top-level `pricing` object to the run config and reports it in `/v1/models` and `/models`, including aliases. Existing configs need no edits: missing, `null` and empty pricing blocks leave the listing unchanged. ## Related discussion Closes #2969. This updates the existing PR after the tracker reset. ## Approach Validate known rates before loading the engine, then publish the supplied values unchanged. Rates accept finite, nonnegative numbers or decimal strings, including zero. Token rates are USD per token; `request` is USD per API request. The documented example uses OpenRouter's `input_cache_read` and `input_cache_write`; Hermes-style `cache_read` and `cache_write` also work. Unknown fields are preserved for extensions. Rebased onto main `e88ee39d`, keeping the new config parsing and API-key preflight. The diff remains limited to the Python server, pricing tests and configuration documentation. ## Validation Tested revision `901c7be0` on 0.2.0-beta, based on `e88ee39d`. CachyOS Linux x86_64, Python 3.12.14, 91 GiB RAM; RTX 5080 (16 GB VRAM, driver 615.78.08), unused by these mock-engine tests. **Passed:** ```sh .venv/bin/python -m unittest serve.test_model_pricing \ serve.test_server.ModelAliases serve.test_server.ConfigApiKey \ serve.test_runconfig -q ``` 25 tests passed, including config startup, both endpoints, aliases, free rates and exact response bytes without pricing. ```sh .venv/bin/python -m unittest serve.test_model_pricing \ serve.test_server serve.test_runconfig serve.test_lifecycle -q ``` 368 tests passed in 110.086 seconds. `git diff e88ee39d...901c7be0 --check` also passed. Direct comparison with unmodified main reproduced missing pricing there and confirmed that the patch publishes the configured rates. Both endpoints stayed byte-identical to main for no config file, an empty config, a model config and aliases without pricing. The reproduction command and output are below. <details> <summary>Baseline comparison command and output</summary> Run from the PR checkout: ```sh PYTHONPATH=. .venv/bin/python - <<'PY' import json import subprocess import sys import types from pathlib import Path from unittest import mock from serve import test_model_pricing as T base = 'e88ee39d' parent = types.ModuleType('serve._pricing_baseline') parent.__file__ = str(Path('serve/server.py').resolve()) sys.modules[parent.__name__] = parent source = subprocess.check_output(['git', 'show', f'{base}:serve/server.py'], text=True) exec(compile(source, parent.__file__, 'exec'), parent.__dict__) probe = T.PricingStartup() for cfg in (None, {}, {'model_name': 'review-model'}, {'model_name': 'review-model', 'aliases': ['local']}): actual = probe.listings(cfg) with mock.patch.object(T, 'S', parent): expected = probe.listings(cfg) assert actual == expected, cfg print('PASS: byte-identical bodies to e88ee39d for both endpoints in all four no-pricing cases') config = {'model_name': 'review-model', 'pricing': T.CARD} with mock.patch.object(T, 'S', parent): previous = probe.listings(config) for body in previous.values(): assert 'pricing' not in json.loads(body)['data'][0] for body in probe.listings(config).values(): assert json.loads(body)['data'][0]['pricing'] == T.CARD print('PASS: missing pricing reproduced on main; patch publishes exact configured rates on both endpoints') PY ``` ```text PASS: byte-identical bodies to e88ee39d for both endpoints in all four no-pricing cases PASS: missing pricing reproduced on main; patch publishes exact configured rates on both endpoints ``` </details> **Failed:** None observed. **Not run:** GPU inference, a new live Hermes/OpenCode session, or backend builds. This change touches no engine or backend code; the HTTP checks use the mock engine. ## Limits These are operator-defined accounting rates. Clients calculate estimates from their own usage; Strata adds no billing or usage storage. This does not establish that OpenCode discovers rates through `/v1/models`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4370
No description provided.