Visitar URL original
Add native OpenRouter OAuth support by rsaryev · Pull Request #6927 · earendil-works/pi · GitHub
Skip to content

Add native OpenRouter OAuth support - #6927

Merged
badlogic merged 2 commits into
earendil-works:mainfrom
rsaryev:feat/openrouter-oauth
Jul 22, 2026
Merged

badlogic merged 2 commits into
earendil-works:mainfrom
rsaryev:feat/openrouter-oauth

Conversation

@rsaryev

@rsaryev rsaryev commented Jul 21, 2026

Copy link
Copy Markdown

Summary

Adds native OpenRouter OAuth support through Provider.auth.oauth.

The flow uses browser authorization, PKCE S256, and a one-shot ephemeral localhost callback with timeout, cancellation, and response validation. The returned user-controlled API key works with both text and image providers, while OPENROUTER_API_KEY remains supported.

Testing

  • npm run check
  • npm run build
  • OpenRouter OAuth tests
  • Manual login and request smoke test

Closes #6814

@rsaryev

rsaryev commented Jul 21, 2026

Copy link
Copy Markdown
Author

I manually tested the complete OpenRouter OAuth flow locally: started pi, signed in through the browser, completed the loopback callback, and sent a real request successfully. The OpenRouter model responded as expected

@rsaryev
rsaryev force-pushed the feat/openrouter-oauth branch from 5a6f959 to 64946d5 Compare July 21, 2026 20:28
@rsaryev
rsaryev force-pushed the feat/openrouter-oauth branch from 64946d5 to 01c7d57 Compare July 21, 2026 20:30
@badlogic

Copy link
Copy Markdown
Collaborator

@rsaryev lgtm please resolve the merge co flicts

@badlogic
badlogic merged commit 7b52cef into earendil-works:main Jul 22, 2026
@badlogic

Copy link
Copy Markdown
Collaborator

cheers!

hamishfromatech added a commit to hamishfromatech/a-coder-cli that referenced this pull request Sep 9, 2026
/login openrouter runs a PKCE authorization flow against a one-shot
loopback callback server (ephemeral port, PI_OAUTH_CALLBACK_HOST
override) and exchanges the authorization code for a permanent,
user-controlled OpenRouter API key — no refresh cycle, expires
MAX_SAFE_INTEGER. Both OpenRouter providers expose OAuth alongside
OPENROUTER_API_KEY via lazyOAuth; the OAuth registry registers
openRouterOAuthProvider as a built-in.

OAuthAuth gained an optional loginLabel ("Sign in with OpenRouter") for
login menus, passed through lazyOAuth. Ported the upstream test suite
(PKCE verification, single-use callback, exchange failure surfacing,
cancel semantics, callback-host override) adapted to the fork's
Models.getAuth(model) and module paths. The manual-code race surface in
loginOpenRouter stays dormant until the headless fallback port wires it.
jinhuang712 pushed a commit to jinhuang712/pi that referenced this pull request Sep 11, 2026
qaworkfree referenced this pull request in qaworkfree/pipipiPopopo Oct 8, 2026
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.

Add native OpenRouter OAuth support

2 participants