Skip to content

feat(smith): OpenRouter as a first-class provider and route target - #1303

Merged
edwin-zvs merged 1 commit into
mainfrom
openrouter-provider
Aug 22, 2026
Merged

feat(smith): OpenRouter as a first-class provider and route target#1303
edwin-zvs merged 1 commit into
mainfrom
openrouter-provider

Conversation

@edwin-zvs

Copy link
Copy Markdown
Contributor

What

Adds OpenRouter (https://openrouter.ai) as a first-class model provider, following the DeepSeek/Grok pattern: a thin variant of the existing OpenAI chat-completions client plus a built-in route target. Motivated by stealth models like stealth/ox-alpha (1M context, tool calling, currently free) that appear on OpenRouter before they have official SDKs — with this, any new routed model is reachable the day it drops via /model openrouter:vendor/model, no per-model code.

  • openrouter: model prefix in smith's spec routing. Explicit only — no bare-name sniff: OpenRouter ids are vendor/model slash paths, which collide with Ollama namespaces (hf.co/user/model), and an aggregator is a distinct billing path (spec 0028). Variant suffixes (:free, :nitro) pass through in the model id.
  • OpenRouter mode on the OpenAI client (OpenAi::openrouter): sends OpenRouter's usage: {include: true} accounting knob and reads the response's cost field, so Usage.usd carries the generation's actual USD cost for any routed model — no price table. Also sends the optional HTTP-Referer / X-Title attribution headers.
  • Built-in route target (spec 0179): OPENROUTER_API_KEY alone makes openrouter a route target (default model openrouter/auto, the aggregator's meta-router id). provider_dialect maps it to OpenAI-chat, so native harnesses can be routed through it like any other openai-compatible target. A declared [smith.models.openrouter] profile still overrides the built-in.
  • Auto-detect ladder: OPENROUTER_API_KEY is the new last rung (yields to every direct vendor key), for both sessions and title-gen.
  • Context budgeting: 128K floor for openrouter (heterogeneous models; overflow learn-and-retry tightens per model). Effort support stays unadvertised until a routed model is measured to grade it (spec 0160's model-aware rule).
  • Surface updates: /model completions (openrouter:openrouter/auto, openrouter:stealth/ox-alpha), /configure smith-auth method + guidance, config.toml template comments, credential-error hints.
  • Spec 0208 records the decision (explicit aggregator route, wire-reported cost, meta-router default).

Testing

  • cargo build + cargo test --workspace: all green (1455 daemon, 748 protocol, 229 smith, …, 0 failures).
  • New tests: prefix parsing incl. slash ids and :free suffixes, bare-slash-id does NOT route to OpenRouter, auto-detect precedence with the new rung, profile endpoint/key defaults; the existing every_builtin_target_is_routable_and_self_consistent guard covers the new built-in.

No TUI-visible rendering change, so no recording — the new surface is model specs, route targets, and the /configure list.

🤖 Generated with Claude Code

- `openrouter:` model prefix in smith (explicit only — no bare-name
  sniff: vendor/model slash ids collide with Ollama namespaces and an
  aggregator is a distinct billing path, spec 0028)
- OpenRouter mode on the OpenAI chat client: usage-cost accounting
  (Usage.usd now carries the generation's real USD cost from the wire)
  and app attribution headers
- built-in route target (spec 0179): OPENROUTER_API_KEY alone makes
  `openrouter` a route target defaulting to openrouter/auto
- auto-detect ladder rung (last), title-gen rung, /configure and
  /model completion entries, 128K context-window floor
- spec 0208 records the decision
@edwin-zvs
edwin-zvs merged commit 7ba4aff into main Aug 22, 2026
1 check passed
@edwin-zvs
edwin-zvs deleted the openrouter-provider branch August 22, 2026 18:13
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