Skip to content

feat: add Nadir channel support - #6578

Closed
doramirdor wants to merge 2 commits into
QuantumNous:mainfrom
doramirdor:feat/nadir-channel
Closed

feat: add Nadir channel support#6578
doramirdor wants to merge 2 commits into
QuantumNous:mainfrom
doramirdor:feat/nadir-channel

Conversation

@doramirdor

@doramirdor doramirdor commented Jul 31, 2026

Copy link
Copy Markdown

📝 变更描述 / 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's model field. The wire format is plain /v1/chat/completions with Authorization: Bearer <key>, so no request translation is needed and this reuses the shared openai adaptor. The diff is the same shape as the existing openrouter channel: 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 no stream_options field, 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/models lists the underlying provider models rather than auto, so "fetch models from upstream" would populate the wrong ids. The channel ships ModelList = ["auto"] instead.

Nadir does not support function calling today, so nothing tool-related is claimed here.

🚀 变更类型 / Type of change

  • ✨ 新功能 (New feature)

🔗 关联任务 / Related Issue

  • N/A

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 Issues 与 PRs,确认不是重复提交。
  • Bug fix 说明: N/A,本 PR 不是 bug fix。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 见下方运行证明。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

Disclosure, per AGENTS.md: this change was AI-assisted. The description above was reviewed and edited by hand, and every command and result below was actually run.

📸 运行证明 / Proof of Work

Backend (root module, GOWORK=off):

go vet ./...    # clean
go build ./...  # clean
make test       # 31 root packages ok, 6 relaykit packages ok, 0 failures

$ go test ./relay/channel/openai/... -run Nadir -v
--- PASS: TestNadirChannelRelaysToOpenAIChatCompletionsWithBearerAuth (0.00s)
--- PASS: TestNadirChannelExposesAutoModelOverOpenAIEndpointOnly (0.00s)
ok      github.com/QuantumNous/new-api/relay/channel/openai      0.758s

$ go test ./controller/... -run TestChannelOwnerName -v
--- PASS: TestChannelOwnerNameUsesAdaptorChannelName/nadir (0.00s)

Frontend (web/, bun 1.3.14):

bun run typecheck   # exit 0
bun test            # 122 pass, 0 fail, 24 files

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:

[DEBUG] fullRequestURL: https://api.getnadir.com/v1/chat/completions
[DEBUG] http transport negotiated: host=api.getnadir.com negotiated=HTTP/1.1
[ERR]   channel error (channel #1, status code: 401): Invalid API key
[GIN]   401 | POST /v1/chat/completions

$ curl -s .../v1/chat/completions -d '{"model":"auto","messages":[...]}'
{"error":{"message":"Invalid API key","type":"bad_response_status_code",...}}

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/models returns "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

    • Added Nadir as a supported channel.
    • Added automatic model selection and OpenAI-compatible connectivity.
    • Added Nadir to the channel selector with branding, icon, base URL, and API key guidance.
    • Added localized Nadir labels across supported languages.
  • Tests

    • Added coverage for Nadir requests, authentication, endpoint handling, channel naming, and model support.

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.
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 15aa0363-8079-4d1f-899f-23e95cee8ad4

📥 Commits

Reviewing files that changed from the base of the PR and between 4d31418 and f49f456.

📒 Files selected for processing (2)
  • relay/channel/nadir/constant.go
  • relay/channel/openai/nadir_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • relay/channel/nadir/constant.go

Walkthrough

Adds 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.

Changes

Nadir channel

Layer / File(s) Summary
Channel contracts and mappings
common/api_type.go, common/endpoint_type.go, constant/*.go, controller/model_owned_by_test.go
Defines Nadir identifiers, metadata, base URL, API mapping, endpoint classification, and owner-name coverage.
OpenAI relay integration
relay/channel/nadir/constant.go, relay/channel/openai/..., relay/relay_adaptor.go
Routes Nadir through the OpenAI adaptor, exposes the auto model, and tests URL, authorization, metadata, and endpoint behavior.
Web channel presentation
web/src/features/channels/..., web/src/i18n/locales/*, web/scripts/sync-i18n.mjs
Adds Nadir to channel ordering, configuration, icon mapping, locale catalogs, and literal-key handling.

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
Loading

Possibly related PRs

Poem

A rabbit hops through Nadir’s gate,
“auto” models choose their fate.
OpenAI paths carry each call,
Bearer headers guard them all.
Nadir now appears for all.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: adding Nadir channel support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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>
@seefs001

seefs001 commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

暂无计划

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.

2 participants