Skip to content

fix(chat): price DeepSeek in the AI budget at the dearest of the US and EU hosts it runs on (W4-36) - #2039

Merged
gkhngyk merged 36 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-deepseek-price
Nov 5, 2026
Merged

gkhngyk merged 36 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-deepseek-price

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Chat runs DeepSeek models only on US or EU hosts (W4-34): DeepInfra, Together, Fireworks, Parasail, Crusoe, Azure and Nebius. The AI budget, though, priced them at OpenRouter's catalog price, which is the cheapest provider's. For DeepSeek V4.1 Flash that is Baidu in China, at $0.045 in and $0.50 out per million tokens. The US and EU hosts ask $0.11–0.45 in and $0.34–1.80 out, so the budget would have counted 3–10 times less than a step costs. This PR prices such a model at the dearest of its hosts (Wave 4 plan, W4-36; owner decision 2026-11-03).

  • Price sync (server/src/lib/model-prices.js):
    • LIMITED_HOSTS lists the providers a maker's models may run on. Today only DeepSeek is listed, with the web's list.
    • After reading the catalog, the daily sync reads each DeepSeek model's endpoints (/api/v1/models/{id}/endpoints, public, no key), three at a time.
    • Each model's input, output and cache-read prices are set to the highest among its allowed hosts. The cache-read price is set only when every host has one, since a host without one bills a cached token as a full input token.
    • The catalog's overrides are dropped: they belong to the catalog's provider (DeepSeek's own off-peak prices).
    • A model whose endpoints can't be read, or that no allowed host lists, is written with no price:
      • the model menu doesn't offer it;
      • a step on it is charged improve-cost.js's FALLBACK_PRICE ($5 in / $25 out), never the cheaper catalog price;
      • the next day's sync tries again.
    • The multiplier the menu shows follows the same price: DeepSeek V4.1 Flash is about 0.5x Auto.
  • Guard (web/src/lib/chat/models.test.ts):
    • The server's DeepSeek hosts must equal DEEPSEEK_US_EU_PROVIDERS in web/src/lib/agent/openrouter.ts, read from the server's source.
    • A model whose hosts Ansvisor limits can be tested: true only when the server prices it at those hosts.
    • W4-35 blocks any tested DeepSeek model outright. This PR replaces that block with the check above, so DeepSeek can't be offered before this PR is merged.

No migration: chat_model_prices already takes a null price. No new environment variables. No user-visible change, since DeepSeek stays tested: false (W4-35), so no Help article.

Stacked on #2038. Merged, not rebased.

Related issue

None. Chat Wave 4 plan, W4-36.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd server && npx vitest run src/lib/model-prices.test.js. The block "a model run on some providers only (W4-36)" covers:
    • the price at the dearest host;
    • the cache-read rule;
    • an unread model left unpriced;
    • every other model synced as before.
  2. cd web && yarn vitest run src/lib/chat/models.test.ts.
  3. After deploy, the next sync (05:17 UTC) should leave chat_model_prices for deepseek/deepseek-v4.1-flash at about 0.45 input and 1.80 output, with empty overrides.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

CI passed on this branch (8e4e34c), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41534310981): schema is up to date; web format:check, lint, typecheck, all tests and yarn build pass; server lint, format:check and all tests pass.

🤖 Generated with Claude Code

cihan-gyk and others added 13 commits November 2, 2026 23:59
…uter calls off data collection (W4-34, 00469)

- Settings › Chat gets Model providers: Anthropic (always on, Auto runs on
  it), OpenAI, Google and DeepSeek (off by default), each on or off for an
  Admin, logged in the Activity log. chat_settings.model_providers (00469)
  keeps the choices; a provider not chosen takes its default in the web.
- A provider that is off has no model in the model menu, and the engine
  runs Auto in place of one of its models, for chats, agents and scheduled
  runs, with "Ran on Auto · Your Admin turned off this model's provider".
- Chat's and the Agent's OpenRouter calls ask for providers that keep no
  data (provider.data_collection: "deny"); a DeepSeek model runs only on
  US or EU hosts, with no fallback. The API server's analysis calls are
  unchanged.
- Help: help/settings/chat-rules.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… OpenRouter's list (W4-34)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… GPT, Gemini and DeepSeek added untested (W4-35)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tarting scenarios past a spend cap (W4-35)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts US and EU hosts (W4-35)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…idates, the cheapest of each (W4-35)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s the Anthropic SDK elsewhere (W4-35)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd EU hosts it runs on (W4-36)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…words it, and fail one that takes a side (W4-35)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 2, 2026
cihan-gyk and others added 8 commits November 3, 2026 01:33
…ls don't predict" (W4-35)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…outer, and two passes before a model is offered (W4-35)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tool names out of answers (W4-35)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e app's detector reads it, and hear "a line telling" as the notice (W4-35)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
gkhngyk previously approved these changes Nov 3, 2026
# Conflicts:
#	web/src/app/api/chat/models/route.test.ts
#	web/src/app/api/chat/models/route.ts
#	web/src/lib/chat/model-menu.ts
…s as off

Auto on another provider's own key ran on that key's model even when an
Admin turned its maker off in Settings > Chat (DeepSeek through
OpenRouter, or OpenAI through an OpenAI or Azure key). resolveChatModels
now maps the own key's model to its maker and stops the run with a clear
error when that provider is off, rather than send the run there or move
to Ansvisor's key by itself.

A failed read of the provider choices now turns every provider that can
be turned off off, instead of falling back to the defaults.
gkhngyk
gkhngyk previously approved these changes Nov 3, 2026
…roviders

# Conflicts:
#	supabase/schema.sql
#	web/messages/en.json
#	web/src/lib/chat/engine.test.ts
…vals

# Conflicts:
#	web/src/lib/chat/models.ts
…budget stand-in

Main's engine now reads meteredAs from the budget module; the test set's
mock replaced the whole module, so every scripted run failed. It now
keeps the real module and stands in for reserveChatStep only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMenyNyxsr2Doq4CaQ3
gkhngyk
gkhngyk previously approved these changes Nov 4, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 4, 2026 17:26

The merge-base changed after approval.

gkhngyk
gkhngyk previously approved these changes Nov 4, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 4, 2026 20:43

The merge-base changed after approval.

gkhngyk
gkhngyk previously approved these changes Nov 4, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 5, 2026 07:52

The merge-base changed after approval.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@gkhngyk
gkhngyk merged commit 85d0a51 into ansvisor:main Nov 5, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants