feat: add Nadir channel support - #6578
Conversation
Nadir (https://api.getnadir.com) is an OpenAI-compatible router: the client sends model "auto" and Nadir classifies the prompt, then relays to the cheapest model that clears its quality bar, reporting the model it actually used in the response's `model` field. Because the dialect is plain OpenAI /v1/chat/completions with Bearer auth, this reuses the shared openai adaptor and only adds the registration points, mirroring the existing openrouter channel. Not registered, deliberately: - streamSupportedChannels: Nadir's request schema has no stream_options field, so it would be silently dropped. It emits usage on the terminal chunk unconditionally, so billing still works without it. - MODEL_FETCHABLE_TYPES: Nadir's /v1/models lists the underlying provider models rather than "auto", so upstream fetch would populate the wrong ids.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds Nadir as channel type 61. The change registers its API and endpoint mappings, routes it through the OpenAI adaptor, adds relay tests, and exposes Nadir in the web channel configuration and locale catalogs. ChangesNadir channel
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant relay_adaptor.GetAdaptor
participant openai.Adaptor
participant NadirAPI
Client->>relay_adaptor.GetAdaptor: request APITypeNadir
relay_adaptor.GetAdaptor->>openai.Adaptor: select OpenAI adaptor
openai.Adaptor->>NadirAPI: send chat-completions request with Bearer authorization
NadirAPI-->>openai.Adaptor: return response
openai.Adaptor-->>Client: return relay response
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Adds doc comments for ModelList, ChannelName, the nadirRelayInfo helper and the two relay tests, so the channel explains why it exposes only "auto" and what each test pins. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
暂无计划 |
📝 变更描述 / Description
Adds Nadir (https://api.getnadir.com) as channel type 61.
Nadir is an OpenAI-compatible router. The client sends
model: "auto", Nadir classifies the prompt's complexity and relays to the cheapest model that clears its quality bar, then reports the model it actually used in the response'smodelfield. The wire format is plain/v1/chat/completionswithAuthorization: Bearer <key>, so no request translation is needed and this reuses the sharedopenaiadaptor. The diff is the same shape as the existingopenrouterchannel: a two-value constants file plus the registration points.Touched:
constant/channel.go(type id, default base URL, display name),constant/api_type.go,common/api_type.go,common/endpoint_type.go(OpenAI endpoint only, grouped with OpenRouter),relay/relay_adaptor.go,relay/channel/nadir/constant.go,relay/channel/openai/adaptor.go, plus the frontend channel constants, icon map, type config and i18n catalogs.Two things are deliberately not registered:
streamSupportedChannels. Nadir's request schema has nostream_optionsfield, so it would be silently dropped. Nadir emits usage on the terminal stream chunk unconditionally, so streaming billing works without it. OpenRouter is likewise absent from this map.MODEL_FETCHABLE_TYPES. Nadir's/v1/modelslists the underlying provider models rather thanauto, so "fetch models from upstream" would populate the wrong ids. The channel shipsModelList = ["auto"]instead.Nadir does not support function calling today, so nothing tool-related is claimed here.
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
📸 运行证明 / Proof of Work
Backend (root module,
GOWORK=off):Frontend (
web/, bun 1.3.14):End-to-end against a locally running new-api on SQLite, with a type-61 channel holding a deliberately invalid upstream key so no billable upstream call was made:
That 401 body is Nadir's own error relayed back verbatim, which confirms URL construction, Bearer auth and error passthrough. Streaming (
"stream": true) took the same path with the same result.GET /api/modelsreturns"61": ["auto"].I have not put a successful paid completion through this channel, so response parsing and quota settlement are exercised only as far as the upstream error path.
Summary by CodeRabbit
New Features
Tests