Skip to content

Anthropic (Claude)

TL;DR

bash
ONGRID_ANTHROPIC_API_KEY=sk-ant-...
ONGRID_ANTHROPIC_MODEL=claude-sonnet-4-6     # default
ONGRID_ANTHROPIC_BASE_URL=                   # optional; relay / regional endpoint

Provider id: anthropic. SDK adapter: native Anthropic Messages API (via the eino Anthropic client under internal/pkg/llm/).

Env vars

VarDefaultNotes
ONGRID_ANTHROPIC_API_KEYEmpty = provider dropped from the catalog
ONGRID_ANTHROPIC_MODELclaude-sonnet-4-6The model used when no per-call override is set
ONGRID_ANTHROPIC_BASE_URL(Anthropic API default)Override for relays / regional endpoints
ONGRID_ANTHROPIC_MODELSclaude-opus-4-7,claude-sonnet-4-6,claude-haiku-4-5Comma-separated; the closed-set the SPA picker shows

All four are seeded on first boot into system_settings.llm.anthropic_* via SetIfAbsent — re-boots never overwrite operator edits in the Settings UI.

Default catalog

Out of box, the model picker shows these three Claude models:

  • claude-opus-4-7 — the frontier model. Use for hard root-cause passes where the marginal accuracy beats the cost.
  • claude-sonnet-4-6 — the default. Balanced cost / quality; what the chat picker preselects.
  • claude-haiku-4-5 — the cheap one. Recommended for the RCA Pass-2 structured extractor and for translate calls — short prompts, short replies, no tool loop.

Edit the list in the SPA's /settings/llm page or by overriding ONGRID_ANTHROPIC_MODELS at boot.

BaseURL override

bash
ONGRID_ANTHROPIC_BASE_URL=https://api.anthropic-relay.example.com/v1

Use this for:

  • Corporate relay proxies (the request still uses your Anthropic key — the relay is transparent).
  • Regional endpoints — Anthropic doesn't publish multiple regions today, but the knob is here for parity with other providers.

The default base URL is wired in cmd/ongrid/main.go:507:

go
BaseURL: firstNonEmpty(cfg.LLM.Anthropic.BaseURL, "https://api.anthropic.com/v1"),

Making Anthropic the default

bash
ONGRID_LLM_DEFAULT_PROVIDER=anthropic

Or, from the SPA: /settings/llm → "Default provider" radio.

The default-provider knob controls what Chat() uses when no per-call provider is pinned (the RCA worker, translate, the home-page chat when nothing's selected). See Routing for the dynamic-default mechanism that lets this take effect without a restart.

Per-call selection

The chat UI's model picker writes both provider and model into the chat send envelope. The router (RoutingChatModel.pick) takes the WithProvider(id) eino option:

go
resp, err := chatModel.Generate(ctx, msgs,
    model.WithModel("claude-opus-4-7"),
    llm.WithProvider("anthropic"),
)

Quirks

  • Stop reasons — Anthropic returns its own stop-reason vocabulary (end_turn, tool_use, max_tokens). The Ongrid adapter maps these to the eino-standard FinishReason so downstream code doesn't have to branch.
  • Tool use — Anthropic's tool-use API uses content blocks, not the OpenAI flat-tool_calls shape. The adapter does the translation transparently; you write tools the same way regardless of provider.
  • System messages — Claude takes a single system parameter (string), not a leading role:system message. The adapter merges multiple system messages with \n\n separators before sending.

See also

  • Models overview — how the catalog assembles.
  • RoutingWithProvider, dynamic defaults.
  • Budget — per-day token caps that apply globally across providers.