{
  "author": {
    "address": "0x18db6DA36c14918623F99465d08b1D8f6B82380F",
    "signature": "59e5e92d13192c845057fba40d6f67344d46df915aef8da7c9a4642899eb304043e8b541c7fc3831bb0efc0b0762bb82b21a36951a202e3ac6707fb5eb6c986e1b"
  },
  "available_to_orchestrator": true,
  "changelog": "Reads the whole OpenCode catalog from models.dev in one request (~0.7 s), with context window, max output, prices and capabilities filled in.",
  "content_hash": "sha256:54fde095021f152482de294e3cc94a68e00da627ce28c002e3d390d2ab5bac47",
  "created_at": "2026-11-18T21:02:00Z",
  "format": "osaurus.template",
  "format_version": 1,
  "id": "17633CD3-F5FD-4496-8FCE-04F755716187",
  "kind": "workflow",
  "name": "OpenCode Model Prices",
  "requirements": {
    "knowledge": [],
    "mcp_servers": [],
    "models": [],
    "network": [
      "models.dev"
    ],
    "notes": {},
    "permissions": [],
    "plugins": [],
    "secrets": []
  },
  "summary": "Lists every OpenCode model with its prices per 1M tokens, for deciding what to use in Osaurus.",
  "version": 2,
  "workflow": {
    "edges": [],
    "examples": [
      {
        "input": {
          "filter": "claude",
          "sort": "name"
        },
        "name": "Narrow to Claude"
      },
      {
        "input": {
          "filter": "",
          "sort": "input price"
        },
        "name": "Cheapest input first"
      },
      {
        "input": {
          "filter": "zzz-not-a-model",
          "sort": "name"
        },
        "name": "No match"
      }
    ],
    "input_schema": {
      "additionalProperties": false,
      "properties": {
        "filter": {
          "description": "Leave empty for every OpenCode model. Otherwise show only models whose id, name, or family contains this text, e.g. claude.",
          "title": "Only models matching (optional)",
          "type": "string"
        },
        "sort": {
          "default": "name",
          "description": "How to order the list.",
          "enum": [
            "name",
            "input price",
            "output price",
            "context window"
          ],
          "title": "Sort by",
          "type": "string"
        }
      },
      "required": [],
      "type": "object",
      "x-order": [
        "filter",
        "sort"
      ]
    },
    "model_slots": [],
    "nodes": [
      {
        "code": {
          "network": [
            "models.dev"
          ],
          "secrets": [],
          "source": "function decode(s) {\n  return String(s)\n    .replace(/&amp;/g, \"&\")\n    .replace(/&lt;/g, \"<\")\n    .replace(/&gt;/g, \">\")\n    .replace(/&quot;/g, '\"')\n    .replace(/&#0?39;/g, \"'\")\n    .replace(/&nbsp;/g, \" \");\n}\n\nfunction textOf(html) {\n  return decode(String(html).replace(/<[^>]*>/g, \" \")).replace(/\\s+/g, \" \").trim();\n}\n\nfunction attr(attrs, name) {\n  const m = String(attrs).match(new RegExp(name + \"=\\\"([^\\\"]*)\\\"\", \"i\"));\n  return m ? decode(m[1]) : null;\n}\n\nfunction numValue(raw) {\n  if (raw === null || raw === undefined) return null;\n  const t = String(raw).trim();\n  if (!t || t === \"-\" || t === \"—\" || t === \"–\") return null;\n  const lower = t.toLowerCase().replace(/[$,\\s]/g, \"\");\n  if (lower.indexOf(\"free\") !== -1) return 0;\n  const m = lower.match(/^([0-9]*\\.?[0-9]+)([km])?$/);\n  if (!m) return null;\n  let n = Number(m[1]);\n  if (!isFinite(n)) return null;\n  if (m[2] === \"k\") n = n * 1000;\n  else if (m[2] === \"m\") n = n * 1000000;\n  return n;\n}\n\nfunction pricePair(raw) {\n  const t = String(raw === null || raw === undefined ? \"\" : raw).trim();\n  if (!t || t === \"-\" || t === \"—\") return [null, null];\n  if (/free/i.test(t)) return [0, 0];\n  const parts = t.split(/[\\/|·]|–|—|\\s+/).map((s) => s.trim()).filter((s) => s.length);\n  if (!parts.length) return [null, null];\n  if (parts.length === 1) {\n    const n = numValue(parts[0]);\n    return [n, n];\n  }\n  return [numValue(parts[0]), numValue(parts[1])];\n}\n\nfunction cellsOf(chunk) {\n  const out = [];\n  const re = /<t([hd])\\b([^>]*)>([\\s\\S]*?)<\\/t\\1>/gi;\n  let m;\n  while ((m = re.exec(chunk)) !== null) {\n    out.push({ tag: m[1].toLowerCase(), attrs: m[2], raw: m[3], sort: attr(m[2], \"data-sort\"), text: textOf(m[3]) });\n  }\n  return out;\n}\n\nasync function run(input, ctx) {\n  const url = \"https://models.dev/providers/opencode\";\n  const res = await ctx.fetch(url, { headers: { accept: \"text/html\" } });\n  if (!res.ok) throw new Error(\"models.dev provider page returned HTTP \" + res.status);\n  const html = await res.text();\n\n  const tableStart = html.indexOf(\"<table\");\n  const tableEnd = tableStart === -1 ? -1 : html.indexOf(\"</table>\", tableStart);\n  if (tableStart === -1 || tableEnd === -1) throw new Error(\"models.dev provider page has no model table\");\n  const table = html.slice(tableStart, tableEnd);\n\n  const chunks = table.split(/<tr\\b/i).slice(1);\n  let header = null;\n  const rowsRaw = [];\n  for (let i = 0; i < chunks.length; i++) {\n    const chunk = chunks[i].split(/<\\/tr>/i)[0];\n    const cells = cellsOf(chunk);\n    if (!cells.length) continue;\n    const joined = cells.map((c) => c.text.toLowerCase()).join(\" | \");\n    if (!header && /context|price|\\$/.test(joined)) { header = cells; continue; }\n    rowsRaw.push(cells);\n  }\n  if (!header) throw new Error(\"models.dev model table has no header row\");\n\n  const cols = { id: -1, ctx: -1, maxOut: -1, inP: -1, outP: -1, price: -1 };\n  const flagCols = [];\n  for (let i = 0; i < header.length; i++) {\n    const h = header[i].text.toLowerCase();\n    const isPrice = h.indexOf(\"$\") !== -1 || h.indexOf(\"price\") !== -1 || h.indexOf(\"cost\") !== -1;\n    if (h.indexOf(\"context\") !== -1) cols.ctx = i;\n    else if (isPrice && h.indexOf(\"in\") !== -1) cols.inP = i;\n    else if (isPrice && h.indexOf(\"out\") !== -1) cols.outP = i;\n    else if (isPrice) cols.price = i;\n    else if (h.indexOf(\"cache\") !== -1) continue;\n    else if (h.indexOf(\"out\") !== -1) cols.maxOut = i;\n    else if (h === \"id\" || h.indexOf(\"model id\") !== -1 || h.indexOf(\"slug\") !== -1) cols.id = i;\n    else if (h.indexOf(\"reason\") !== -1) flagCols.push({ at: i, label: \"reasoning\" });\n    else if (h.indexOf(\"tool\") !== -1) flagCols.push({ at: i, label: \"tools\" });\n    else if (h.indexOf(\"vis\") !== -1 || h.indexOf(\"image\") !== -1) flagCols.push({ at: i, label: \"sees images\" });\n    else if (h.indexOf(\"attach\") !== -1) flagCols.push({ at: i, label: \"attachments\" });\n  }\n\n  const rawFilter = input.filter === null || input.filter === undefined ? \"\" : String(input.filter);\n  const needle = rawFilter.trim().toLowerCase();\n  const all = [];\n  const hays = [];\n  for (let i = 0; i < rowsRaw.length; i++) {\n    const cells = rowsRaw[i];\n    const first = cells[0] || { raw: \"\", text: \"\", sort: null };\n    const link = first.raw.match(/<a[^>]*>([\\s\\S]*?)<\\/a>/i);\n    const canonical = first.raw.match(/<span[^>]*class=\"[^\"]*subtle[^\"]*\"[^>]*>([\\s\\S]*?)<\\/span>/i);\n    const name = link ? textOf(link[1]) : (first.sort || first.text);\n    let id = cols.id >= 0 && cells[cols.id] ? (cells[cols.id].sort || cells[cols.id].text) : \"\";\n    const canon = canonical ? textOf(canonical[1]) : \"\";\n    if (!id && canon) id = canon;\n    if (canon.indexOf(\"/\") !== -1 && (!id || id.indexOf(\"/\") !== -1)) id = canon.split(\"/\").pop();\n    id = String(id || \"\").trim();\n    if (!id || !name) continue;\n    const val = (idx) => (idx >= 0 && cells[idx] ? (cells[idx].sort !== null && cells[idx].sort !== \"\" ? cells[idx].sort : cells[idx].text) : null);\n    const flags = [];\n    for (let f = 0; f < flagCols.length; f++) {\n      const v = String(val(flagCols[f].at) || \"\").toLowerCase();\n      if (v === \"yes\" || v === \"true\" || v === \"1\" || v.indexOf(\"✓\") !== -1) flags.push(flagCols[f].label);\n    }\n    let inP = numValue(val(cols.inP));\n    let outP = numValue(val(cols.outP));\n    if (cols.price >= 0 && cells[cols.price]) {\n      const cell = cells[cols.price];\n      const label = String(cell.text || \"\");\n      if (/[\\/|·]|in\\b/i.test(label)) {\n        const pair = pricePair(label);\n        if (inP === null) inP = pair[0];\n        if (outP === null) outP = pair[1];\n      } else {\n        const single = numValue(cell.sort !== null && cell.sort !== \"\" ? cell.sort : label);\n        if (inP === null) inP = single;\n        if (outP === null) outP = single;\n      }\n    }\n    if (inP === 0 && outP === 0) flags.push(\"free\");\n    all.push({\n      id: id,\n      name: name,\n      ctx: numValue(val(cols.ctx)),\n      maxOut: numValue(val(cols.maxOut)),\n      inP: inP,\n      outP: outP,\n      flags: flags.join(\", \")\n    });\n    hays.push((name + \" \" + id + \" \" + canon).toLowerCase());\n  }\n  if (!all.length) throw new Error(\"could not read any model row (\" + rowsRaw.length + \" rows on the page)\");\n  ctx.log(\"read \" + all.length + \" OpenCode models from one models.dev page\");\n\n  const rows = needle ? all.filter((r, i) => hays[i].indexOf(needle) !== -1) : all.slice();\n\n  const sortBy = (input.sort === null || input.sort === undefined || input.sort === \"\") ? \"name\" : String(input.sort);\n  const byNum = (field, dir) => (a, b) => {\n    const x = a[field];\n    const y = b[field];\n    if (x === null && y === null) return a.name.localeCompare(b.name);\n    if (x === null) return 1;\n    if (y === null) return -1;\n    return dir * (x - y) || a.name.localeCompare(b.name);\n  };\n  if (sortBy === \"input price\") rows.sort(byNum(\"inP\", 1));\n  else if (sortBy === \"output price\") rows.sort(byNum(\"outP\", 1));\n  else if (sortBy === \"context window\") rows.sort(byNum(\"ctx\", -1));\n  else rows.sort((a, b) => a.name.localeCompare(b.name));\n\n  const money = (v) => {\n    if (v === null || v === undefined) return \"—\";\n    const n = Number(v);\n    if (!isFinite(n)) return \"—\";\n    if (n === 0) return \"free\";\n    const s = n >= 1 ? n.toFixed(2) : n.toFixed(3);\n    return \"$\" + s.replace(/0+$/, \"\").replace(/\\.$/, \"\");\n  };\n  const kfmt = (v) => {\n    if (v === null || v === undefined) return \"—\";\n    const n = Number(v);\n    if (!isFinite(n)) return \"—\";\n    return n >= 1000 ? Math.round(n / 1000) + \"k\" : String(n);\n  };\n\n  const lines = [\"| Model | ID | Context | Max out | In $/1M | Out $/1M | Flags |\", \"| --- | --- | --- | --- | --- | --- | --- |\"];\n  for (let i = 0; i < rows.length; i++) {\n    const r = rows[i];\n    lines.push(\"| \" + [r.name, \"`\" + r.id + \"`\", kfmt(r.ctx), kfmt(r.maxOut), money(r.inP), money(r.outP), r.flags || \"—\"].join(\" | \") + \" |\");\n  }\n\n  const pricedIn = rows.filter((r) => r.inP !== null && isFinite(r.inP));\n  const pricedOut = rows.filter((r) => r.outP !== null && isFinite(r.outP));\n  const free = rows.filter((r) => r.inP === 0 && r.outP === 0).length;\n  const spread = (arr, field) => {\n    if (!arr.length) return null;\n    let lo = arr[0][field];\n    let hi = arr[0][field];\n    for (let i = 0; i < arr.length; i++) {\n      if (arr[i][field] < lo) lo = arr[i][field];\n      if (arr[i][field] > hi) hi = arr[i][field];\n    }\n    return [lo, hi];\n  };\n  const inR = spread(pricedIn, \"inP\");\n  const outR = spread(pricedOut, \"outP\");\n\n  const notes = [];\n  if (rows.length === 0) {\n    notes.push(\"No OpenCode model matches \\\"\" + rawFilter.trim() + \"\\\"; \" + all.length + \" models are listed.\");\n  } else {\n    notes.push(rows.length + \" of \" + all.length + \" OpenCode models shown\" + (needle ? \" (matching \\\"\" + rawFilter.trim() + \"\\\")\" : \"\") + (free ? \", \" + free + \" free\" : \"\") + \".\");\n  }\n  if (inR && outR) {\n    notes.push(\"Input \" + money(inR[0]) + \"–\" + money(inR[1]) + \" and output \" + money(outR[0]) + \"–\" + money(outR[1]) + \" per 1M tokens.\");\n  }\n  notes.push(\"Source: models.dev, OpenCode provider (USD per 1M tokens).\");\n\n  const report = (rows.length ? lines.join(\"\\n\") + \"\\n\\n\" : \"\") + notes.join(\" \");\n  const summary = rows.length\n    ? rows.length + \" OpenCode models\" + (inR && outR ? \", input \" + money(inR[0]) + \"–\" + money(inR[1]) + \" and output \" + money(outR[0]) + \"–\" + money(outR[1]) + \" per 1M tokens\" : \"\") + \".\"\n    : \"No OpenCode models matched.\";\n\n  return { report: report, count: rows.length, summary: summary };\n}",
          "timeout": 60
        },
        "id": "list_models",
        "input": {
          "filter": "{{input.filter}}",
          "sort": "{{input.sort}}"
        },
        "intent": "Fetches the models.dev catalog, keeps the OpenCode provider, and builds a priced Markdown table.",
        "kind": "code",
        "name": "Build OpenCode price table",
        "output_schema": {
          "additionalProperties": false,
          "properties": {
            "count": {
              "type": "integer"
            },
            "report": {
              "type": "string"
            },
            "summary": {
              "type": "string"
            }
          },
          "required": [
            "report",
            "count",
            "summary"
          ],
          "type": "object"
        },
        "retry": {
          "backoff_seconds": 2,
          "max_attempts": 2
        },
        "timeout": 60
      }
    ],
    "output": {
      "count": "{{nodes.list_models.output.count}}",
      "report": "{{nodes.list_models.output.report}}",
      "summary": "{{nodes.list_models.output.summary}}"
    },
    "output_schema": {
      "additionalProperties": false,
      "properties": {
        "count": {
          "title": "Models listed",
          "type": "integer"
        },
        "report": {
          "description": "Markdown table of the OpenCode models with their prices per 1M tokens, followed by a short notes line.",
          "title": "OpenCode models and prices",
          "type": "string"
        },
        "summary": {
          "description": "One line: how many OpenCode models are listed and the price range.",
          "title": "Summary",
          "type": "string"
        }
      },
      "required": [
        "report",
        "summary",
        "count"
      ],
      "type": "object"
    },
    "requirement_notes": {},
    "secrets": []
  }
}