Skip to content

feat(admin): LLM_PROVIDER=anthropic routes Tier 1/2 crons to Claude Haiku - #200

Merged
Oscar-west merged 1 commit into
mainfrom
feat/anthropic-llm-provider
Jul 19, 2026
Merged

Oscar-west merged 1 commit into
mainfrom
feat/anthropic-llm-provider

Conversation

@Oscar-west

Copy link
Copy Markdown
Contributor

What

Adds an LLM_PROVIDER env switch at the mlxChat() layer. With LLM_PROVIDER=anthropic, every Tier 1/Tier 2 cron across all four pillars runs against Claude Haiku 4.5 via the Anthropic Messages API — all eight orchestrators unchanged. With it unset, behavior is byte-identical to today.

Why

The MLX Mac mini (mlx.tenki.no) is decommissioned. Since it went down, every llm-* / *-llm-tier* cron has been failing, and the media landing card is stuck on the no-signal sentinel because media_snapshot_index needs Tier 2-classified articles.

How

  • anthropicTextChat() in [lib/admin/anthropic.ts]: plain-text completion (no tool forcing — the orchestrators' JSON-in-text prompts + parse-and-retry were built for a 4-bit Gemma; Haiku follows them strictly better), cache_control on the system prompt so the K sequential calls in one tick share a cache read.
  • [lib/admin/mlx.ts]: llmProvider() switch; mlxChat/mlxPing/mlxModelId/mlxConfigured route to Anthropic in anthropic mode. AnthropicError kinds map onto MlxError kinds (rate_limit/server → retryable http), so orchestrator retry/abort semantics are identical. mlx_health + the /admin/llm badge track the active provider; the 5-min heartbeat pings GET /v1/models (free, validates the key).
  • deploy.sh: LLM_PROVIDER placeholder in admin.env + propagation to .env.production.

Cost

Steady state is small: NAV ~44 AI postings/30d, media ~tens of articles/week, offentlig/brreg similar. Per call ≈ 0.5–2k input + ~200 output tokens on Haiku ($1/$5 per MTok) → expect cents per day; the June–July backlog drain is a one-off well under $5. ANTHROPIC_MODEL can override the model if we ever want to trade up/down.

Rollout

  1. Merge (deploys via the runner)
  2. On Apollo: set LLM_PROVIDER=anthropic in /opt/kibarometer/env/admin.env (ANTHROPIC_API_KEY is already provisioned for the manual drain buttons)
  3. Verify: fire llm-classify + media-llm-tier2 ticks, check mlx_health and /admin/llm

Typecheck clean, 309/309 unit tests pass. The 3 lint errors are pre-existing on main (unescaped apostrophes in startups/companies + an <a> in about/bot).

🤖 Generated with Claude Code

…aiku

The MLX Mac mini (mlx.tenki.no) is decommissioned, which silently
stalled every Tier 1/Tier 2 cron across all four pillars and the media
index with it. This adds a provider switch at the mlxChat() layer so all
eight orchestrators run unchanged against the Anthropic Messages API:

- lib/admin/anthropic.ts: anthropicTextChat() — plain-text completion
  (no tool forcing; the orchestrators' JSON-in-text prompts + parse-retry
  work as-is) with cache_control on the system prompt so the K calls in
  one cron tick share a cache read.
- lib/admin/mlx.ts: LLM_PROVIDER env switch ('mlx' default, 'anthropic'
  routes mlxChat/mlxPing/mlxModelId to Claude Haiku); AnthropicError
  kinds map onto MlxError kinds so orchestrator retry semantics are
  identical; mlx_health tracks the active provider.
- scripts/deploy.sh: LLM_PROVIDER placeholder + propagation to
  .env.production.

Default model stays claude-haiku-4-5-20251001 (ANTHROPIC_MODEL
overrides). With LLM_PROVIDER unset nothing changes.

Co-Authored-By: Claude <noreply@anthropic.com>
@Oscar-west
Oscar-west merged commit 5ee7915 into main Jul 19, 2026
2 checks passed
@Oscar-west
Oscar-west deleted the feat/anthropic-llm-provider branch July 19, 2026 16:54
@Oscar-west
Oscar-west restored the feat/anthropic-llm-provider branch August 26, 2026 12:35
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