[PR #7765] feat: add OpenRouter OAuth PKCE authentication #12508

Open
opened 2026-02-16 18:17:24 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7765

State: open
Merged: No


Closes #7766

Summary

Add support for authenticating with OpenRouter using OAuth PKCE flow, allowing users to log in with their OpenRouter account instead of manually entering an API key.

Changes

  • Add OpenRouterAuthPlugin in packages/opencode/src/plugin/openrouter.ts
  • Register plugin in INTERNAL_PLUGINS array
  • Add hint text for OpenRouter in provider selection

Implementation

The plugin follows the same pattern as CodexAuthPlugin:

  1. Starts a local HTTP server on port 3000 to receive the OAuth callback
  2. Generates PKCE code verifier and challenge (S256)
  3. Opens browser to OpenRouter authorization URL
  4. Exchanges authorization code for API key via POST to /api/v1/auth/keys
  5. Stores the key as type: "api" (OpenRouter returns a permanent API key, not refresh tokens)

Reference: https://openrouter.ai/docs/guides/overview/auth/oauth

Testing

  1. Run opencode auth login
  2. Select OpenRouter
  3. Select "OpenRouter Account"
  4. Browser opens to OpenRouter authorization page
  5. After authorization, callback is received and API key is stored
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7765 **State:** open **Merged:** No --- Closes #7766 ## Summary Add support for authenticating with OpenRouter using OAuth PKCE flow, allowing users to log in with their OpenRouter account instead of manually entering an API key. ## Changes - Add `OpenRouterAuthPlugin` in `packages/opencode/src/plugin/openrouter.ts` - Register plugin in `INTERNAL_PLUGINS` array - Add hint text for OpenRouter in provider selection ## Implementation The plugin follows the same pattern as `CodexAuthPlugin`: 1. Starts a local HTTP server on port 3000 to receive the OAuth callback 2. Generates PKCE code verifier and challenge (S256) 3. Opens browser to OpenRouter authorization URL 4. Exchanges authorization code for API key via POST to `/api/v1/auth/keys` 5. Stores the key as `type: "api"` (OpenRouter returns a permanent API key, not refresh tokens) Reference: https://openrouter.ai/docs/guides/overview/auth/oauth ## Testing 1. Run `opencode auth login` 2. Select OpenRouter 3. Select "OpenRouter Account" 4. Browser opens to OpenRouter authorization page 5. After authorization, callback is received and API key is stored
yindo added the pull-request label 2026-02-16 18:17:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12508