Skip to content

feat(cli): add [upstream] preset = "openrouter" - #1640

Closed
flazouh wants to merge 14 commits into
NVIDIA:mainfrom
flazouh:upstream-openrouter-preset
Closed

flazouh wants to merge 14 commits into
NVIDIA:mainfrom
flazouh:upstream-openrouter-preset

Conversation

@flazouh

@flazouh flazouh commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Stacked on #1611. Review only these two commits:

The merge commits only bring in new #1611 heads.

Adds [upstream] preset = "openrouter", so one line sets up both providers for OpenRouter:

[upstream]
preset = "openrouter"

It stands for:

[upstream]
openai_base_url = "https://openrouter.ai/api/v1"
anthropic_base_url = "https://openrouter.ai/api"

[upstream.openai_oidc]
preset = "openrouter"

[upstream.anthropic_oidc]
preset = "openrouter"

Both sign-ins use the same issuer and client, so one nemo-relay auth login covers both, with no --provider.

  • I confirm this contribution is my own work, or I have the right to submit it under this project's license.
  • I searched existing issues and open pull requests, and this does not duplicate existing work.

Details

Exclusive in its file. The preset stands for both base URLs and both sign-ins, so it is not combined with them. A file that sets [upstream] preset and also openai_base_url, anthropic_base_url, openai_oidc, anthropic_oidc, or another credential for those providers (*_api_key, *_auth_header, *_api_key_helper) is a configuration error that names the file and the field. Other [upstream] settings, such as timeouts, can sit next to the preset.

Layering. Each file expands its preset before the merge, so the existing layering rules apply unchanged:

  • A higher layer, such as a user config over the system config, can still set a base URL. When it sets another address, that provider loses the preset's sign-in, as for every other credential source.
  • NEMO_RELAY_OPENAI_BASE_URL or NEMO_RELAY_ANTHROPIC_BASE_URL set to another address clears that provider's sign-in, through the existing apply_env_config rule.
  • An unknown preset name stays in place, so FileUpstreamConfig rejects it with its name.

I kept the override across layers on purpose. Rejecting it would stop a user from pointing one provider at their own gateway under a system preset.

OidcPreset now also holds the two base URLs. The per-section [upstream.<provider>_oidc] preset from #1611 stays.

Docs. The OIDC section of docs/nemo-relay-cli/basic-usage.mdx shows the one-line form first, then the per-section form for another provider or a gateway in front of OpenRouter.

Tests. Each new test was seen failing before its change:

  • the preset sets both base URLs and both sign-ins;
  • the preset and a field it fills in the same file is an error that names the field (six fields);
  • the preset and a setting it does not fill, such as a timeout, load together;
  • a higher layer that changes a base URL drops that provider's sign-in;
  • an environment base URL drops that provider's sign-in;
  • an unknown preset is rejected;
  • auth login with only the [upstream] preset needs no --provider.

The auth tests that load a config file now hold the environment lock with the two base-URL variables removed, so they do not race the environment test under cargo test.

cargo clippy -p nemo-relay-cli --all-targets -- -D warnings and cargo fmt --check pass. cargo test -p nemo-relay-cli --lib -- oidc commands::auth error::tests configuration::tests --test-threads=1 passes except managed_worker_dynamic_plugin_loading_reads_user_lifecycle_state, which also fails on #1611's head on this machine (it depends on the umask).

🤖 Generated with Claude Code

flazouh and others added 6 commits November 3, 2026 02:51
Add `nemo-relay auth login|token|logout`. `login` runs the OAuth 2.0
device authorization grant against an OpenID Connect issuer and keeps
the sign-in in the per-user config directory with owner-only access.
`token` prints a current access token and refreshes it near expiry,
so an `[upstream.openai_api_key_helper]` can supply it to every
upstream request without a separate credential tool.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: flazouh <[email protected]>
Follow RFC 8628 polling rules, keep the sign-in on transient issuer
errors, lock login, refresh and logout, require same-origin endpoints,
and let login and logout read the issuer, client ID and scopes from the
configured API key helper. Document the sign-in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: flazouh <[email protected]>
Replace the API key helper wiring with [upstream.openai_oidc] and
[upstream.anthropic_oidc]. The gateway reads the stored sign-in for each
upstream request, so the token expiry and a logout apply at once, and
a missing sign-in returns HTTP 401 naming nemo-relay auth login.

- auth login and logout read the provider from the effective config,
  including --config, and support an Anthropic-only setup.
- Device polling keeps the issuer interval and slow_down without a cap,
  checks expiry before each poll, and retries network errors.
- OAuth error codes and descriptions reach the user.
- nemo-relay doctor reports each configured sign-in state.
- Split the sign-in code into oidc/{mod,client,session}.rs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: flazouh <[email protected]>
…h errors

- A higher config layer replaces [upstream.*_oidc] as a whole, like an
  API key helper, so an issuer and a client ID from different layers
  never mix.
- A token reply without expires_in is refused instead of being stored
  as an expired session.
- A temporary refresh failure keeps using an access token that has not
  expired yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: flazouh <[email protected]>
preset = "openrouter" in [upstream.*_oidc] and --preset openrouter on
nemo-relay auth set OpenRouter's issuer, public client ID and scopes, so
users do not paste a client ID into config.toml. Explicit fields still
override the preset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: flazouh <[email protected]>
One line in [upstream] now sets both base URLs and an OpenRouter
sign-in for each provider. Fields written next to the preset win, and a
base URL changed by the same layer, a higher layer or an environment
variable drops that provider's sign-in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: flazouh <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions github-actions Bot added size:XL PR is extra large Feature a new feature lang:rust PR changes/introduces Rust code labels Nov 4, 2026
Comment thread docs/nemo-relay-cli/basic-usage.mdx Outdated
Comment on lines +796 to +798
Fields written next to the preset win. A provider whose base URL is set to
another address, by the same layer, a higher layer, or an environment variable,
does not get the preset's sign-in.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be more strict. Presets should not be combined with other options.

flazouh and others added 8 commits November 4, 2026 21:50
The gateway read the time once, before the lock wait, discovery and the
refresh request. A token that expired during a slow failed refresh was
still returned, and a refreshed token lost the time the request took.
The token path now takes a clock: it reads it again before it uses the
fallback token, and the refresh reads it when the reply arrives.

A preset in [upstream.<provider>_oidc] now holds no other field, and
auth login --preset cannot be combined with --issuer, --client-id or
--scope. Each case is an error that names the field.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: flazouh <[email protected]>
Signed-off-by: flazouh <[email protected]>

# Conflicts:
#	crates/cli/tests/coverage/commands/auth_tests.rs
A file that sets [upstream] preset and also a field the preset fills
(either base URL, an *_oidc section, or another credential for those
providers) is now a configuration error that names the field. Other
[upstream] settings can still sit next to the preset. A higher layer
or an environment variable can still change a base URL, and that
provider then loses the preset sign-in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: flazouh <[email protected]>
A request that waits too long for another request's refresh now reads the stored sign-in again and uses its access token while it is unexpired, instead of failing. The sign-in file is keyed by issuer, client ID and scope, so sources with other scopes no longer overwrite each other. The docs list the OIDC sign-in first in the credential order.

Signed-off-by: flazouh <[email protected]>
The architecture test limits direct stderr to emergency and UI boundaries, so auth login and logout print their status on stdout, as the plugin lifecycle commands do. The credential-order docs say an inbound credential is kept only without an oidc section, since a configured section with no sign-in fails.

Signed-off-by: flazouh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature a new feature lang:rust PR changes/introduces Rust code size:XL PR is extra large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants