Commit Graph
12 Commits
Author SHA1 Message Date
Susana Ferreira 3ed8548e78 fix: unblock AI price book refresh for gpt-6-astra and qwen3.8-max (#29170)
The weekly `aigateway-prices-refresh` job
[failed](https://github.com/coder/coder/actions/runs/34458761592)
because two upstream-guard assertions in the generator tripped:
models.dev now lists OpenAI's `gpt-6-astra` (so its `overrides.jq`
injection must be dropped), and the curated OpenRouter
`qwen/qwen3.8-max` identifier was renamed upstream to
`qwen/qwen3.8-max-0902`.

This removes the `gpt-6-astra` injection, repoints the qwen curation
entry to `qwen/qwen3.8-max-0902` (with a `displayName` override to keep
the clean "Qwen3.8 Max" label in the UI), and regenerates `prices.json`
and `knownModelsGenerated.json`.

Note: because the artifacts regenerate from live models.dev, this diff
also carries unrelated upstream drift, the same content the scheduled
refresh PR would produce.

> [!NOTE]
> Generated with Coder Agents on behalf of @ssncferreira.
2026-09-10 11:31:23 +01:00
Jake Howell 257c6f1dca refactor: move shared AI model UI into modules/aiModels (#29040)
> 🤖 Refactoring with Cursor.

AI settings was importing model form fields, ModelSelector, and
ProviderIcon from AgentsPage. Those now live in
`site/src/modules/aiModels`.

No user-facing behavior change.

- Move ProviderIcon, ModelSelector, and the model admin form fields into
`modules/aiModels`
- Point AgentsPage and AI settings at the new paths
- Drop the leftover ChatModelAdminPanel ProviderIcon duplicate and the
knownModels barrel
- Update the known-models catalog generator paths
2026-09-08 14:34:51 +10:00
Michael Suchacz 9cd66d3773 feat: add GPT-6 Astra to the known models catalog, price book, and chatd (#28955) 2026-09-04 11:19:29 +02:00
cdrciandgithub-actions[bot] b938495bf5 chore: refresh AI model price book (#28939)
## Price book changes

7 models added, 0 models removed, 15 models changed.

<details>
<summary>Added</summary>

- openrouter/meta/muse-spark-1.3
- openrouter/meta/muse-spark-1.3-contributor
- vercel/alibaba/qwen3.8-max-0902
- vercel/google/gemini-3.8-flash
- vercel/meta/muse-spark-1.3
- vercel/meta/muse-spark-1.3-contributor
- vercel/zai/glm-5.3-promo-50
</details>

<details>
<summary>Changed</summary>

- azure/gpt-5.6-sol
- openrouter/deepseek/deepseek-v4-flash
- openrouter/deepseek/deepseek-v4-flash-vision-exp
- openrouter/deepseek/deepseek-v4-pro
- openrouter/deepseek/deepseek-v4-pro-0813
- openrouter/meta-llama/llama-3.3-70b-instruct
- openrouter/meta/muse-glimmer-30b
- openrouter/nvidia/nemotron-3-nano-30b-a3b
- openrouter/nvidia/nemotron-3-ultra-550b-a55b
- openrouter/qwen/qwen3.5-397b-a17b
- openrouter/qwen/qwen3.8-2.4t-a95b
- openrouter/tencent/hy3
- openrouter/z-ai/glm-4.6
- openrouter/z-ai/glm-5.3
- openrouter/~z-ai/glm-latest
</details>

## Review notes

Regenerated by `make gen/aibridge-prices` from the live
[models.dev](https://models.dev) catalog. Both artifacts come from one
snapshot, so they ship together:

- `coderd/aibridge/prices/data/prices.json`
-
`site/src/pages/AgentsPage/components/ChatModelAdminPanel/knownModels/knownModelsGenerated.json`

These are customer-visible cost numbers taken from upstream data, so
this PR is never merged automatically. The summary above lists what
moved; check the diff for exact figures before approving.

Opened automatically by the [aigateway-prices-refresh
workflow](https://github.com/coder/coder/actions/runs/33736992948).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-09-03 13:41:16 +02:00
Michael Suchacz a8f7591627 chore: add Gemini 3.8 Flash to the known models catalog and price book (#28909) 2026-09-02 18:35:51 +00:00
Michael Suchacz 560ef00c15 chore: add Claude Fable 5.1 and other new models to the known models catalog (#28887)
Add the models that landed on models.dev since the August curation pass
to the Agents-page known models list, so they appear as suggestions when
an admin adds a chat model in `/agents` settings.

| Model | Providers |
|---|---|
| Claude Fable 5.1 | anthropic, azure, bedrock (plus `global.` alias),
openrouter, vercel |
| Claude Opus 5 | anthropic (already curated on the other providers) |
| Gemini 3.7 Flash | google |
| GLM 5.3 | openrouter, vercel |

Fable 5.1 and Opus 5 use `reasoningEffort: high` like their curated
siblings, and new entries sort ahead of the models they supersede.
`knownModelsGenerated.json` and
`coderd/aibridge/prices/data/prices.json` are both regenerated with
`make gen/aibridge-prices` from the same models.dev snapshot; the
`prices.json` changes are upstream drift since the last weekly refresh.

Left out pending a decision: azure now lists `claude-mythos-5` upstream
but it is not curated for azure here, and `copilot` has no curation
entries at all.

> Xum opened this PR on behalf of @ibetitsmike.
2026-09-02 09:50:57 +02:00
cdrciandgithub-actions[bot] debe8e51bb chore: refresh AI model price book (#28711)
## Price book changes

36 models added, 27 models removed, 47 models changed.

<details>
<summary>Added</summary>

- openrouter/deepseek/deepseek-v4-flash-vision-exp
- openrouter/mancer/weaver
- openrouter/meta/muse-spark-1.2-contributor
- openrouter/minimax/minimax-m2.7:free
- openrouter/minimax/minimax-m3:free
- openrouter/mistralai/devstral-2512
- openrouter/mistralai/ministral-8b
- openrouter/qwen/qwen3.8-flash
- openrouter/tencent/hy-mt2-1.8b
- openrouter/tencent/hy-mt2-30b-a3b
- openrouter/tencent/hy-mt2-7b
- openrouter/thinkingmachines/inkling-small:free
- openrouter/thinkingmachines/inkling:free
- openrouter/z-ai/glm-5.3-flash
- vercel/alibaba/qwen3.8-flash
- vercel/deepseek/deepseek-v4-flash-vision-exp
- vercel/google/gemini-3.5-transcribe
- vercel/minimax/minimax-m2.7-free
- vercel/minimax/minimax-m3-free
- vercel/openai/gpt-oss-safeguard-120b
- vercel/spacexai/grok-4.1-fast-non-reasoning
- vercel/spacexai/grok-4.1-fast-reasoning
- vercel/spacexai/grok-4.20-multi-agent
- vercel/spacexai/grok-4.20-multi-agent-beta
- vercel/spacexai/grok-4.20-non-reasoning
- vercel/spacexai/grok-4.20-non-reasoning-beta
- vercel/spacexai/grok-4.20-reasoning
- vercel/spacexai/grok-4.20-reasoning-beta
- vercel/spacexai/grok-4.3
- vercel/spacexai/grok-4.5
- vercel/spacexai/grok-4.6
- vercel/spacexai/grok-build-0.1
- vercel/tencent/hy-mt2-lite
- vercel/tencent/hy-mt2-plus
- vercel/tencent/hy-mt2-pro
- vercel/zai/glm-5.3-flash
</details>

<details>
<summary>Removed</summary>

- openrouter/deepcogito/cogito-v2.1-671b
- openrouter/google/gemma-3n-e4b-it
- openrouter/inclusionai/ling-2.6-1t
- openrouter/inclusionai/ling-2.6-flash
- openrouter/inclusionai/ring-2.6-1t
- openrouter/nvidia/nemotron-3-nano-30b-a3b:free
- openrouter/nvidia/nemotron-nano-12b-v2-vl:free
- openrouter/nvidia/nemotron-nano-9b-v2:free
- openrouter/openai/gpt-oss-20b:free
- openrouter/qwen/qwen-plus-2025-07-28:thinking
- vercel/arcee-ai/trinity-mini
- vercel/mistral/magistral-medium
- vercel/mistral/magistral-small
- vercel/openai/gpt-4o-mini-search-preview
- vercel/openai/o3-deep-research
- vercel/xai/grok-4.1-fast-non-reasoning
- vercel/xai/grok-4.1-fast-reasoning
- vercel/xai/grok-4.20-multi-agent
- vercel/xai/grok-4.20-multi-agent-beta
- vercel/xai/grok-4.20-non-reasoning
- vercel/xai/grok-4.20-non-reasoning-beta
- vercel/xai/grok-4.20-reasoning
- vercel/xai/grok-4.20-reasoning-beta
- vercel/xai/grok-4.3
- vercel/xai/grok-4.5
- vercel/xai/grok-4.6
- vercel/xai/grok-build-0.1
</details>

<details>
<summary>Changed</summary>

- bedrock/global.openai.gpt-5.6-luna
- bedrock/global.openai.gpt-5.6-sol
- bedrock/global.openai.gpt-5.6-terra
- bedrock/openai.gpt-5.6-sol
- copilot/gpt-5.6-sol
- google/gemini-3.6-flash
- google/gemini-flash-latest
- google/gemini-flash-lite-latest
- openai/gpt-5.6
- openai/gpt-5.6-sol
- openrouter/deepseek/deepseek-chat-v3.1
- openrouter/deepseek/deepseek-v3.1-terminus
- openrouter/deepseek/deepseek-v3.2
- openrouter/deepseek/deepseek-v4-flash
- openrouter/deepseek/deepseek-v4-flash-0731
- openrouter/deepseek/deepseek-v4-pro
- openrouter/deepseek/deepseek-v4-pro-0813
- openrouter/meta-llama/llama-3.3-70b-instruct
- openrouter/meta-llama/llama-4-scout
- openrouter/minimax/minimax-m2.5
- openrouter/mistralai/mistral-small-3.2-24b-instruct
- openrouter/moonshotai/kimi-k2.5
- openrouter/moonshotai/kimi-k2.7-code
- openrouter/nvidia/nemotron-3-nano-30b-a3b
- openrouter/openai/gpt-5.6-sol
- openrouter/openai/gpt-5.6-sol-pro
- openrouter/openai/gpt-oss-120b
- openrouter/qwen/qwen2.5-vl-72b-instruct
- openrouter/qwen/qwen3-235b-a22b-2507
- openrouter/qwen/qwen3-30b-a3b
- openrouter/qwen/qwen3-next-80b-a3b-instruct
- openrouter/qwen/qwen3.6-27b
- openrouter/qwen/qwen3.6-35b-a3b
- openrouter/qwen/qwen3.8-27b
- openrouter/z-ai/glm-4.6
- openrouter/z-ai/glm-5.1
- openrouter/z-ai/glm-5.2
- openrouter/~deepseek/deepseek-v4-flash-latest
- openrouter/~moonshotai/kimi-latest
- openrouter/~openai/gpt-latest
- vercel/deepseek/deepseek-v4-flash-0731
- vercel/deepseek/deepseek-v4-pro-0813
- vercel/nvidia/nemotron-3.5-lightning
- vercel/openai/gpt-5.6-sol
- vercel/openai/gpt-5.6-sol-fast
- vercel/openai/gpt-oss-safeguard-20b
- vercel/tencent/hy3
</details>

## Review notes

Regenerated by `make gen/aibridge-prices` from the live
[models.dev](https://models.dev) catalog. Both artifacts come from one
snapshot, so they ship together:

- `coderd/aibridge/prices/data/prices.json`
-
`site/src/pages/AgentsPage/components/ChatModelAdminPanel/knownModels/knownModelsGenerated.json`

These are customer-visible cost numbers taken from upstream data, so
this PR is never merged automatically. The summary above lists what
moved; check the diff for exact figures before approving.

Opened automatically by the [aigateway-prices-refresh
workflow](https://github.com/coder/coder/actions/runs/33072075172).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-08-27 15:03:51 +01:00
cdrciandgithub-actions[bot] 5e0710de92 chore: refresh AI model price book (#28365)
## Price book changes

61 models added, 14 models removed, 51 models changed.

<details>
<summary>Added</summary>

- azure/claude-mythos-5
- azure/claude-opus-4-7
- azure/kimi-k2.7-code
- bedrock/global.openai.gpt-5.6-luna
- bedrock/global.openai.gpt-5.6-sol
- bedrock/global.openai.gpt-5.6-terra
- bedrock/xai.grok-4.6
- copilot/gemini-3.7-flash
- copilot/grok-4.6
- copilot/kimi-k3
- copilot/mai-code-1.1-flash
- google/gemini-3.7-flash
- openrouter/bytedance-seed/seed-2-1-turbo
- openrouter/bytedance-seed/seed-2.0-code
- openrouter/deepseek/deepseek-v4-pro-0813
- openrouter/dots-studio/dots-3-note-preview:free
- openrouter/google/gemini-3.7-flash
- openrouter/inclusionai/ling-3.0-flash
- openrouter/liquid/lfm-2.5-2.6b:free
- openrouter/meta/muse-glimmer-30b
- openrouter/meta/muse-spark-1.2
- openrouter/nvidia/nemotron-3.5-lightning
- openrouter/nvidia/nemotron-3.5-lightning:free
- openrouter/qwen/qwen3.8-2.4t-a95b
- openrouter/qwen/qwen3.8-27b
- openrouter/sakana/sakana-namazu
- openrouter/upstage/solar-pro4
- openrouter/x-ai/grok-4.6
- openrouter/z-ai/glm-5.2:free
- openrouter/z-ai/glm-5.3
- openrouter/~z-ai/glm-latest
- vercel/alibaba/qwen3.8-2.4t-a95b
- vercel/alibaba/qwen3.8-27b
- vercel/deepseek/deepseek-v4-pro-0813
- vercel/google/gemini-3.7-flash
- vercel/inclusionai/ling-3.0-flash
- vercel/meta/muse-glimmer-30b
- vercel/meta/muse-spark-1.2
- vercel/meta/muse-spark-1.2-contributor
- vercel/nvidia/nemotron-3.5-lightning
- vercel/openai/gpt-4.1-fast
- vercel/openai/gpt-4.1-mini-fast
- vercel/openai/gpt-4.1-nano-fast
- vercel/openai/gpt-4o-fast
- vercel/openai/gpt-4o-mini-fast
- vercel/openai/gpt-5-fast
- vercel/openai/gpt-5-mini-fast
- vercel/openai/gpt-5.1-thinking-fast
- vercel/openai/gpt-5.2-fast
- vercel/openai/gpt-5.3-codex-fast
- vercel/openai/gpt-5.4-fast
- vercel/openai/gpt-5.4-mini-fast
- vercel/openai/gpt-5.5-fast
- vercel/openai/gpt-5.6-luna-fast
- vercel/openai/gpt-5.6-sol-fast
- vercel/openai/gpt-5.6-terra-fast
- vercel/openai/o3-fast
- vercel/openai/o4-mini-fast
- vercel/sakana/namazu
- vercel/xai/grok-4.6
- vercel/zai/glm-5.3
</details>

<details>
<summary>Removed</summary>

- anthropic/claude-opus-4-1
- anthropic/claude-opus-4-1-20250805
- google/gemini-2.0-flash
- google/gemini-2.0-flash-lite
- google/gemini-3-pro-preview
- openrouter/ai21/jamba-large-1.7
- openrouter/inclusionai/ling-3.0-flash:free
- openrouter/mancer/weaver
- openrouter/openai/gpt-5.3-chat
- vercel/anthropic/claude-opus-4.1
- vercel/inclusionai/ling-3.0-flash-free
- vercel/openai/gpt-5.1-instant
- vercel/openai/gpt-5.3-chat
- vercel/zai/glm-4.6v
</details>

<details>
<summary>Changed</summary>

- azure/gpt-5.6-luna
- azure/gpt-5.6-sol
- azure/gpt-5.6-terra
- bedrock/openai.gpt-5.6-sol
- openrouter/deepseek/deepseek-chat-v3-0324
- openrouter/deepseek/deepseek-v3.1-terminus
- openrouter/deepseek/deepseek-v4-flash
- openrouter/deepseek/deepseek-v4-flash-0731
- openrouter/deepseek/deepseek-v4-pro
- openrouter/google/gemini-3.6-flash
- openrouter/google/gemma-4-31b-it
- openrouter/gryphe/mythomax-l2-13b
- openrouter/minimax/minimax-m2.5
- openrouter/minimax/minimax-m2.7
- openrouter/mistralai/mistral-small-3.2-24b-instruct
- openrouter/moonshotai/kimi-k2.5
- openrouter/moonshotai/kimi-k2.6
- openrouter/moonshotai/kimi-k2.7-code
- openrouter/openai/gpt-5.6-luna
- openrouter/openai/gpt-5.6-luna-pro
- openrouter/openai/gpt-5.6-sol
- openrouter/openai/gpt-5.6-sol-pro
- openrouter/openai/gpt-5.6-terra
- openrouter/openai/gpt-5.6-terra-pro
- openrouter/openai/gpt-oss-120b
- openrouter/qwen/qwen-plus-2025-07-28:thinking
- openrouter/qwen/qwen2.5-vl-72b-instruct
- openrouter/qwen/qwen3-14b
- openrouter/qwen/qwen3-235b-a22b-2507
- openrouter/qwen/qwen3-30b-a3b
- openrouter/qwen/qwen3-coder-30b-a3b-instruct
- openrouter/qwen/qwen3-vl-235b-a22b-thinking
- openrouter/qwen/qwen3-vl-30b-a3b-instruct
- openrouter/qwen/qwen3.5-35b-a3b
- openrouter/qwen/qwen3.6-27b
- openrouter/qwen/qwen3.6-35b-a3b
- openrouter/tencent/hy3-preview
- openrouter/thinkingmachines/inkling
- openrouter/thinkingmachines/inkling-small
- openrouter/z-ai/glm-5
- openrouter/z-ai/glm-5.2
- openrouter/~deepseek/deepseek-v4-flash-latest
- openrouter/~google/gemini-flash-latest
- openrouter/~moonshotai/kimi-latest
- openrouter/~openai/gpt-latest
- openrouter/~x-ai/grok-latest
- vercel/deepseek/deepseek-v4-flash
- vercel/deepseek/deepseek-v4-pro
- vercel/google/gemini-3.6-flash
- vercel/openai/gpt-5.6-sol
- vercel/zai/glm-5.2
</details>

## Review notes

Regenerated by `make gen/aibridge-prices` from the live
[models.dev](https://models.dev) catalog. Both artifacts come from one
snapshot, so they ship together:

- `coderd/aibridge/prices/data/prices.json`
-
`site/src/pages/AgentsPage/components/ChatModelAdminPanel/knownModels/knownModelsGenerated.json`

These are customer-visible cost numbers taken from upstream data, so
this PR is never merged automatically. The summary above lists what
moved; check the diff for exact figures before approving.

Opened automatically by the [aigateway-prices-refresh
workflow](https://github.com/coder/coder/actions/runs/32352560765).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-08-20 10:46:48 +01:00
Cian JohnstonandSusana Ferreira 60161fd375 chore: update model prices to include more providers (#27837)
Adds the full set of supported provider types to
`scripts/aibridgepricesgen` and updates stored model prices.

Notes:
* We need to rename a few keys from models.dev JSON to match our
internal provider types.
* `prices.json` is now marked as generated.

---------

Co-authored-by: Susana Ferreira <susana@coder.com>
2026-08-04 14:17:50 +01:00
Yevhenii Shcherbina d57965ee7f chore: regenerate prices.json from models.dev (#27549)
Implements:
https://linear.app/codercom/issue/AIGOV-493/update-pricesjson-with-current-model-rates-before-cost-control-release

Run `make gen/aibridge-prices` to regenerate `prices.json` from
`models.dev`.

This update:
- adds support for the upstream `claude-opus-5` model;
- removes older `openai` models that have been removed upstream, keeping
us in sync with `models.dev`.
2026-07-27 23:45:22 +02:00
Cian JohnstonandCopilot Autofix powered by AI 8eaf4f507b feat: generate the known-models catalog and aigateway prices (#27146)
- Regenerates `prices.json` from models.dev. The seeder only upserts, so
existing deployments keep delisted models.
- Generate the frontend known-models catalog instead of hand-writing it.
`make gen/aibridge-prices` fetches models.dev once
- Moved patches to model definitions to separate `overrides.jq` which 
  handles both `claude-sonnet-4-5` 200k context and 'aliasing' Fable 5
  as Mythos 5.
- Editorial choices of selection, order, aliases, and reasoning defaults 
  live in `curation.json`.
- Adds golden join tests with one error case per validation, a
no-network drift test comparing curation to the checked-in artifact, and
pinned invariants for the Anthropic thinking-mode split (the wrong side
returns HTTP 400) and the sonnet-4-5 context pin.

Adding a model is now one `curation.json` entry plus `make
gen/aibridge-prices`, assuming it is present on models.dev.

> This PR was authored by Coder Agents on Cian's behalf.

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-07-14 19:36:27 +00:00
Yevhenii Shcherbina 4124d1137d feat: add ai_model_prices table (#24932)
# Summary

Implements
https://linear.app/codercom/issue/AIGOV-282/add-ai-model-price-table-and-seed-generator

This PR lays the groundwork for AI Bridge cost controls (per the AI
Governance RFC). It adds the foundation needed for future cost tracking:
a place to store per-model token prices, a way to keep those prices in
sync with upstream pricing data, and a startup mechanism that ensures
every deployment has prices loaded before AI Bridge starts processing
requests.

The price data comes from [models.dev](https://models.dev/), a
community-maintained catalogue of AI provider pricing. A generator
script fetches the latest prices, filters to Anthropic and OpenAI for
now, and produces a seed file checked into the repository.

On every server startup the seed is applied to the database, so new
releases automatically pick up any price corrections that landed since
the previous one. Existing rows are overwritten with the latest prices;
rows for models no longer in the seed are left untouched.

# Batching the AI model price seed: three approaches

Context: at server startup we seed the `ai_model_prices` table from an
embedded JSON price book (~70 rows today, will grow as we add providers,
potentially 4000+).

Each row is:

```text
(provider, model, input_price, output_price, cache_read_price, cache_write_price)
```

Any of the four price columns can be:

- `NULL` → “price unknown for this dimension”
- explicit `0` → “free”

The batch must be an UPSERT so re-running is idempotent and existing
rows pick up new prices.

We considered three implementations.

---

## Approach 1 — Per-row UPSERT in a Go loop

```go
for _, row := range rows {
    if err := db.UpsertAIModelPrice(ctx, database.UpsertAIModelPriceParams{
        Provider:   row.Provider,
        Model:      row.Model,
        InputPrice: nullInt64(row.InputPrice),
        // ...
    }); err != nil {
        return err
    }
}
```

### Pros

- Trivial.
- NULL handling falls out naturally from `sql.NullInt64`.

### Cons

- `N` round-trips per seed.
- With ~70 rows that means ~70 statement executions on every startup,
even inside a transaction.
- Doesn't scale gracefully as the price book grows, potentially 4000+.

---

## Approach 2 — `UNNEST` with parallel arrays

Pass each column as a separate Go slice. Postgres unnests them in
parallel into a virtual table, then `INSERT ... SELECT`.

```sql
INSERT INTO ai_model_prices (
    provider,
    model,
    input_price,
    output_price,
    cache_read_price,
    cache_write_price
)
SELECT
    UNNEST(@providers::text[]),
    UNNEST(@models::text[]),
    NULLIF(UNNEST(@input_prices::bigint[]), -1),
    NULLIF(UNNEST(@output_prices::bigint[]), -1),
    NULLIF(UNNEST(@cache_read_prices::bigint[]), -1),
    NULLIF(UNNEST(@cache_write_prices::bigint[]), -1)
ON CONFLICT (provider, model) DO UPDATE SET
    input_price       = EXCLUDED.input_price,
    output_price      = EXCLUDED.output_price,
    cache_read_price  = EXCLUDED.cache_read_price,
    cache_write_price = EXCLUDED.cache_write_price,
    updated_at        = NOW();
```

Go side: flatten rows into six parallel slices.

Use a sentinel (`-1`) for “missing”, since `lib/pq` can't encode `NULL`
into a `bigint[]` element.

```go
providers := make([]string, len(rows))
models    := make([]string, len(rows))
inputs    := make([]int64,  len(rows))
outputs   := make([]int64,  len(rows))
cacheR    := make([]int64,  len(rows))
cacheW    := make([]int64,  len(rows))

for i, r := range rows {
    providers[i] = r.Provider
    models[i]    = r.Model

    inputs[i] = -1
    if r.InputPrice != nil {
        inputs[i] = *r.InputPrice
    }

    outputs[i] = -1
    if r.OutputPrice != nil {
        outputs[i] = *r.OutputPrice
    }

    cacheR[i] = -1
    if r.CacheReadPrice != nil {
        cacheR[i] = *r.CacheReadPrice
    }

    cacheW[i] = -1
    if r.CacheWritePrice != nil {
        cacheW[i] = *r.CacheWritePrice
    }
}

return db.UpsertAIModelPrices(ctx, database.UpsertAIModelPricesParams{
    Providers:        providers,
    Models:           models,
    InputPrices:      inputs,
    OutputPrices:     outputs,
    CacheReadPrices:  cacheR,
    CacheWritePrices: cacheW,
})
```

### Pros

- Single round-trip.

### Cons

- The generated `sqlc` params become plain `[]int64`, which can't
represent `NULL`.

---

## Approach 3 — `jsonb_array_elements` over a single `@seed::jsonb`
(chosen)

Pass the raw seed JSON as one parameter; let Postgres expand and parse
it.

```sql
INSERT INTO ai_model_prices (
    provider,
    model,
    input_price,
    output_price,
    cache_read_price,
    cache_write_price
)
SELECT
    elem->>'provider',
    elem->>'model',
    (elem->>'input_price')::bigint,
    (elem->>'output_price')::bigint,
    (elem->>'cache_read_price')::bigint,
    (elem->>'cache_write_price')::bigint
FROM jsonb_array_elements(@seed::jsonb) AS elem
ON CONFLICT (provider, model) DO UPDATE SET
    input_price       = EXCLUDED.input_price,
    output_price      = EXCLUDED.output_price,
    cache_read_price  = EXCLUDED.cache_read_price,
    cache_write_price = EXCLUDED.cache_write_price,
    updated_at        = NOW();
```

Go side reduces to:

```go
return db.UpsertAIModelPrices(ctx, seedJSON)
```

### Pros

- Single round-trip.
- NULLs fall out naturally:
  - `(elem->>'cache_write_price')::bigint` becomes `NULL`
  - no sentinels
- The seed is already JSON:
- Existing precedent:
  - `jsonb_array_elements` is already used elsewhere in the codebase

### Cons

- Less type-safe at the SQL boundary than `UNNEST`
- Slightly less standard than `UNNEST`
- Readers need familiarity with:
  - `jsonb_array_elements`
  - `->>` extraction syntax
- Postgres pays JSON parse cost
  - negligible at our scale

---

---

# Decision

We picked Approach 3.

It collapses the round-trips like `UNNEST` does, but without:

- nullable-array workarounds
- sentinel values
2026-05-08 16:45:14 -04:00