feat: surface per-model cost and limit from static catalog#2
Merged
Conversation
amplifier-app-opencode hard-depends on three things added in amplifier-agent 0.8.0 (PR #65 + the release commit ee04f9f): - The `serve chat-completions` HTTP face (the wire amplifier-opencode talks to) - Multi-provider routing in lifespan (so `/v1/models` lists more than anthropic) - The `auth` subcommand (so credentials persist across terminals) Older amplifier-agent versions silently skip these features, which surfaces as cryptic 'amplifier-agent server did not become ready' or '/v1/models returned 0 models' errors during `amplifier-opencode` startup. Make the version requirement explicit in the README's prerequisites section so users upgrade BEFORE running the adapter rather than after debugging the first failed launch. 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
0c2a131 to
b17cb9e
Compare
b17cb9e to
020c6c5
Compare
Re-enables per-model cost and limit in build_provider_block(). Both
fields were previously stripped to avoid opencode's silent
config-decode-failure mode (a single malformed cost or limit entry
wipes the entire provider's models block).
## Why a static catalog
opencode's bundled models.dev registry has pricing for canonical
providers (anthropic, openai, gemini, etc.) but it keys lookups by
(providerID, modelID). Our amplifier provider has its own providerID
even though we serve the SAME model IDs anthropic uses (claude-haiku-4-5,
claude-sonnet-4-6, etc.), so opencode never matches our entries to the
catalog -- it renders our turns at $0.00 unless cost is declared in
the opencode.json model block.
We tested two alternatives first:
1. opencode's `provider.api: 'anthropic'` field as a catalog-
inheritance hint -- empirically does NOT cause inheritance from
anthropic's catalog entries. cost remained zeros after restart.
2. Submitting amplifier as a provider to models.dev (sst/models) --
would require external review, and our served model set varies
by amplifier-agent's host_config.json, so we can't declare a
fixed list upstream.
Hardcoded MODEL_PRICING_PER_MILLION catalog in cli.py is the
self-contained path. Initial entries cover Anthropic's Claude 4
family; OpenAI placeholders left commented for when amplifier-agent
serves them. Source of truth: https://github.com/sst/models (same
registry opencode bundles).
## Companion telemetry path
amplifier-agent#68 surfaces real per-turn `cost_usd` on the
chat-completions response. opencode's @ai-sdk/openai-compatible
adapter doesn't read it today (non-standard OpenAI field), but it
ships on the wire for any cost-aware client.
## Generated config -- before vs after
before: { 'name': 'Claude Haiku 4.5' }
after: { 'name': 'Claude Haiku 4.5',
'cost': { 'input': 1.0, 'output': 5.0,
'cache_read': 0.1, 'cache_write': 1.25 },
'limit': { 'context': 200000, 'output': 64000 } }
Verified end-to-end against opencode v1.17.8: the picker now shows
real per-million rates per model.
🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier)
Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
020c6c5 to
3a527c5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Re-enables
costandlimitfields inbuild_provider_block(). Both were stripped earlier to dodge opencode's silent config-decode failure mode (a single malformed entry wipes the whole provider's models block).Why a static catalog is necessary
opencode bundles the models.dev registry — the catalog has rich pricing for canonical provider IDs (anthropic, openai, gemini, etc.). But opencode keys catalog lookups by
(providerID, modelID), not justmodelID. Our customamplifierprovider serves the same model IDs Anthropic uses (claude-haiku-4-5,claude-sonnet-4-6, ...) but opencode treats them as un-cataloged because the providerID doesn't match.Empirically confirmed: Without per-model cost in our config, opencode renders every turn at $0.00:
Two alternatives we tested first
provider.api: 'anthropic'field as catalog-inheritance hintamplifierto models.dev (sst/models)host_config.json— can't declare a fixed list upstream.Hardcoded catalog in the adapter is the self-contained path. Maintenance: when a provider changes prices, update
MODEL_PRICING_PER_MILLION. Source of truth referenced inline: github.com/sst/models.Generated config — before vs after
Before:
After:
opencode normalizes flat
cache_read/cache_writeto nestedcache: {read, write}internally — confirmed via/providerendpoint probe.Initial coverage
Compatibility with the cost telemetry path
microsoft/amplifier-agent#68surfaces real per-turncost_usdon the chat-completions response (Decimal-as-string, from provider modules' compute_cost). That ships on the wire today; this PR is for opencode's TUI picker display (per-model rate) and the rolling cost calc opencode does fromtokens × rates. The two complement each other:cost_usd: authoritative $$ for cost-aware clients (curl, custom wrappers, telemetry tools)