From d49651b2dcd7331b27cc9ed899fefcc9280373f7 Mon Sep 17 00:00:00 2001 From: Tom Beckenham <34339192+tombeckenham@users.noreply.github.com> Date: Fri, 27 Nov 2026 18:57:33 +1100 Subject: [PATCH] opencode: price embedding models from the Embedding pricing table (#774) OpenCode Zen's models page now lists 12 embedding models in Endpoints and prices them in a ### Embedding pricing table (Model | Input, per 1M, input tokens only). Read it into input-only token cards; a missing row, changed header, unreadable cell or a model priced in two tables throws. --- src/server/providers/opencode-pricing.test.ts | 56 +++++++++++++++++++ src/server/providers/opencode-pricing.ts | 42 +++++++++++++- 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/src/server/providers/opencode-pricing.test.ts b/src/server/providers/opencode-pricing.test.ts index a0c027dd..aa3929b8 100644 --- a/src/server/providers/opencode-pricing.test.ts +++ b/src/server/providers/opencode-pricing.test.ts @@ -64,6 +64,28 @@ const IMAGE_PAGE = PAGE.replace( `, ) +/** Two live Embedding pricing rows (issue #774), on the fixture page. */ +const EMBEDDING_PAGE = PAGE.replace( + '| Pickle | pickle |', + `| text-embedding-3-small | text-embedding-3-small | \`https://opencode.ai/inference/openai/v1/embeddings\` | \`@ai-sdk/openai-compatible\` | +| Qwen3 Embedding 8B | qwen3-embedding-8b | \`https://opencode.ai/inference/openai/v1/embeddings\` | \`@ai-sdk/openai-compatible\` | +| Pickle | pickle |`, +).replace( + '\n## Privacy\n', + ` +### Embedding pricing + +Embedding models charge for input tokens only. Prices are **per 1M tokens**. + +| Model | Input | +| ---------------------- | ----- | +| text-embedding-3-small | $0.02 | +| Qwen3 Embedding 8B | $0.01 | + +## Privacy +`, +) + const doc = (text: string) => ({ text, hash: 'a'.repeat(64), @@ -175,7 +197,41 @@ describe('parseOpenCodePricing', () => { ).toBeCloseTo(39) }) + it('prices embedding rows on input tokens only', () => { + const cards = parseOpenCodePricing(doc(EMBEDDING_PAGE)) + const small = cards.get('text-embedding-3-small') as Card + expect(small.tables.rate).toEqual({ base: { input_tokens: 0.02 / 1e6 } }) + expect(Object.keys(small.inputs)).toEqual(['input_tokens']) + expect(price(small, {}, { input_tokens: 1_000_000 })).toBeCloseTo(0.02) + expect((cards.get('qwen3-embedding-8b') as Card).tables.rate.base).toEqual({ + input_tokens: 0.01 / 1e6, + }) + }) + it.each([ + [ + 'an embedding row removed', + EMBEDDING_PAGE.replace(/\| Qwen3 Embedding 8B {5}\| \$0\.01 \|\n/, ''), + /Qwen3 Embedding 8B has an endpoint but no price row/, + ], + [ + 'a changed embedding header', + EMBEDDING_PAGE.replace('| Input |', '| Price |'), + /Embedding pricing header changed/, + ], + [ + 'an unreadable embedding price', + EMBEDDING_PAGE.replace('| $0.02 |', '| TBD |'), + /unreadable price TBD/, + ], + [ + 'an embedding model priced in both tables', + EMBEDDING_PAGE.replace( + '| Pickle | Free', + '| Qwen3 Embedding 8B | $0.01 | Free | - | - |\n| Pickle | Free', + ), + /Qwen3 Embedding 8B is priced twice/, + ], [ 'an unreadable cell', PAGE.replace('$4.00 ', 'TBD '), diff --git a/src/server/providers/opencode-pricing.ts b/src/server/providers/opencode-pricing.ts index 183e52c2..398c58f6 100644 --- a/src/server/providers/opencode-pricing.ts +++ b/src/server/providers/opencode-pricing.ts @@ -1,7 +1,8 @@ /** * OpenCode Zen prices from OpenCode's own console models page (issue #314). * Token rows are the Pricing table. Image models are the Image pricing - * table (issue #100007). It is the only Zen price source: models.dev + * table (issue #100007). Embedding models are the Embedding pricing table, + * input tokens only (issue #774). It is the only Zen price source: models.dev * `cost` is not read, and an id the page does not price states no price. */ import { compileTokenCard } from '@modelschemas/rate-card' @@ -16,6 +17,7 @@ export const OPENCODE_PRICING_URL = const PRICE_HEADER = ['Model', 'Input', 'Output', 'Cached Read', 'Cached Write'] const IMAGE_HEADER = ['Model', 'Price', 'Notes'] +const EMBEDDING_HEADER = ['Model', 'Input'] const PRICE_LEVERS = [ 'input_tokens', 'output_tokens', @@ -308,6 +310,27 @@ export function parseOpenCodePricing( } } + // "Embedding models charge for input tokens only", per 1M tokens. + const embeddingTable = sectionTable(doc.text, 'Embedding pricing', 3) + const embeddingRows = new Map() + if (embeddingTable) { + if (embeddingTable[0]!.join('|') !== EMBEDDING_HEADER.join('|')) { + throw new Error('opencode: pricing page Embedding pricing header changed') + } + for (const [name, input, ...rest] of embeddingTable.slice(2)) { + const rate = input === undefined ? undefined : usd(input, name ?? '') + if (!name || rate === undefined || rest.length > 0) { + throw new Error( + `opencode: unreadable embedding price row ${name ?? ''}`, + ) + } + if (embeddingRows.has(name) || rows.has(name) || imageRows.has(name)) { + throw new Error(`opencode: ${name} is priced twice`) + } + embeddingRows.set(name, rate) + } + } + const source = { url: OPENCODE_PRICING_URL, hash: doc.hash, @@ -328,6 +351,13 @@ export function parseOpenCodePricing( : [] cards.set(id, compileOpenCodeCost(row.base, tiers, id, source)) } + for (const [name, rate] of embeddingRows) { + const id = idByName.get(name) + if (!id) throw new Error(`opencode: price row ${name} names no model id`) + const card = compileTokenCard({ input_tokens: rate / 1e6 }, [], source) + if (!card) throw new Error(`opencode: unreadable price for ${id}`) + cards.set(id, card) + } const imagePriced = new Set() const unverified = new Set() for (const [name, cells] of imageRows) { @@ -342,10 +372,16 @@ export function parseOpenCodePricing( } // The Endpoints table names the model set. A price table that ends early // (a blank line, a split table) would otherwise clear the rows after it. - // An image model is priced in Image pricing, not in the token table. + // An image model is priced in Image pricing, an embedding model in + // Embedding pricing, not in the token table. // An unverified image row is an explicit absence, not a missing row. for (const name of idByName.keys()) { - if (!rows.has(name) && !imagePriced.has(name) && !unverified.has(name)) { + if ( + !rows.has(name) && + !embeddingRows.has(name) && + !imagePriced.has(name) && + !unverified.has(name) + ) { throw new Error(`opencode: ${name} has an endpoint but no price row`) } }