Skip to content

feat(runtimes): add cost details for OpenCode models (multi-provider pricing)#1908

Open
sapk wants to merge 3 commits intomultica-ai:mainfrom
sapk-fork:agent/frontend-developer/44c228a2
Open

feat(runtimes): add cost details for OpenCode models (multi-provider pricing)#1908
sapk wants to merge 3 commits intomultica-ai:mainfrom
sapk-fork:agent/frontend-developer/44c228a2

Conversation

@sapk
Copy link
Copy Markdown

@sapk sapk commented Apr 29, 2026

What does this PR do?

Fixes the $0.00 cost display for OpenCode runs by adding multi-provider model pricing support (OpenAI, Google, Anthropic, etc.) from models.dev.

Related Issue

none

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Refactor / code improvement (no behavior change)
  • Documentation update
  • Tests (adding or improving test coverage)
  • CI / infrastructure

Changes Made

  1. Extended pricing coverage - Added 185+ models from 6 providers via generated pricing snapshot
  2. Improved resolver - Handles provider prefixes (openai/gpt-4o) and bare names (gpt-4o) with exact match + fallback passes
  3. Added tests - 20 unit tests covering exact matches, bare names, provider-prefixed, dated snapshots, and edge cases

How to Test

  1. Visit runtime page of an previously unsupported runtime/models

Checklist

  • I have included a thinking path that traces from project context to this change
  • I have run tests locally and they pass
  • I have added or updated tests where applicable
  • If this change affects the UI, I have included before/after screenshots
  • I have updated relevant documentation to reflect my changes
  • I have considered and documented any risks above
  • I will address all reviewer comments before requesting merge

AI Disclosure

AI tool used: Claude Code, Cursor, Multica Agent, Opencode

Prompt / approach:
I wanted to evaluate multica in a usefull way by fixing with it a bug/missing feature I found when testing.
I simply chat with Claude in multica to create agents needed to solve and setup a dedicated issue to fix it.

Screenshots (optional)

before

Capture d’écran du 2026-04-29 23-26-02 Capture d’écran du 2026-04-29 23-17-32

after

Capture d’écran du 2026-04-29 22-59-42 Capture d’écran du 2026-04-29 22-59-54

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 29, 2026

@sapk is attempting to deploy a commit to the IndexLabs Team on Vercel.

A member of the Team first needs to authorize it.

@sapk sapk changed the title Add cost details for OpenCode models (multi-provider pricing) feat(runtimes): add cost details for OpenCode models (multi-provider pricing) Apr 29, 2026
sapk added 3 commits April 29, 2026 23:30
OpenCode runs reported $0.00 cost in the runtime "Cost by agent" tab
because the client-side pricing table was Anthropic-only and keyed by
bare model id, while OpenCode emits `provider/model` strings (e.g.
`openai/gpt-4o`, `anthropic/claude-sonnet-4-5`).

- Generate `packages/views/runtimes/pricing.generated.ts` from
  `https://models.dev/api.json` (MIT, the dataset OpenCode uses
  internally). Snapshot covers anthropic, openai, google, moonshotai,
  opencode, opencode-go — the providers Multica's runtime presets emit.
- Replace the hand-curated `MODEL_PRICING` table in `utils.ts` with a
  lookup against the generated `PRICING` map; an internal adapter
  converts the snake_case `ModelCost` shape to the camelCase
  `{ cacheRead, cacheWrite }` shape the cost-estimation functions
  consume, defaulting missing cache tiers to `input` (conservative —
  preserves correct totals for daemon-synthesised cache_write_tokens
  and keeps `estimateCacheSavings` returning 0 for providers without a
  cache discount).
- Resolver flow: exact `provider/model` match, otherwise iterate every
  PRICING entry's bare key and match either `keyBare === bare` or
  `keyBare.startsWith(withoutDate)`. Catches bare model names
  (`gpt-4o`), bare with date suffix (`claude-opus-4-1-20260105`), and
  provider-prefixed with date suffix
  (`anthropic/claude-opus-4-1-20260105`).
- Regenerate via `node scripts/generate-pricing.mjs` whenever upstream
  prices drift.

Closes [MUL-1](mention://issue/a0010234-64a6-4c06-a0b1-27de095cb8a9)
@sapk sapk force-pushed the agent/frontend-developer/44c228a2 branch from c499637 to e70552e Compare April 29, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant