nanocoder
nanocoder copied to clipboard
[Bug] Local models get a bogus cost in the usage footer because pricing is matched by partial name
Description
getModelPricing finds a price with an exact id match and then falls back to a partial name match across every provider on models.dev. A local model run through Ollama or LM Studio can match a hosted model with a similar name, so the response footer shows a cost for a free local model.
Environment
- OS: Windows 11 Home 10.0.26300
- Node version: v22.22.3
- Nanocoder version: 1.32.0 (built from main at eb7dee57)
- Provider: Ollama / LM Studio (local)
- Model: gpt-oss:20b, qwen3-coder, llama3
Steps to Reproduce
- Fill the models.dev cache with the real database (https://models.dev/api.json) and call
getModelPricing(<model>)for typical local model names. - Price a response of 100,000 input and 2,000 output tokens with
calculateUsageCost. - With the small test fixture database: call
getModelPricing('llama3').
Expected Behavior
A local model has no cost (null), or the lookup is skipped for local providers.
Actual Behavior
gpt-oss:20b pricing={"input":0.07,"output":0.3} cost = $0.0076
qwen3-coder pricing={"input":0.22,"output":0.95} cost = $0.0239
llama3 pricing={"input":0,"output":0} (partial match)
gemma3, llama3.1:8b, phi4 -> no price
fixture database: llama3 -> the price of the Groq-hosted llama3-70b-8192
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder (main)
Suggested fix:
source/models/models-dev-client.ts:548-570(getModelPricing): drop thefindModelByNamefallback (:283, which was written for context-limit lookups of local models) and keep exact id matches only.- Better, pass the provider into
buildResponseUsage(source/usage/response-usage.ts:179) and skip pricing for local base URLs. - Add a test that
llama3has no price with the fixture database.
Related: #756 / PR #796 (the cost footer), #2271 (per-model pricing overrides).
Picked this up, fix is in the linked PR.