[PR #5498] feat(auth): add support for multiple profiles per provider #11433

Closed
opened 2026-02-16 18:16:16 -05:00 by yindo · 0 comments
Owner

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

State: closed
Merged: No


implements https://github.com/sst/opencode/issues/5391

Summary

  • Allow users to store multiple API keys for the same provider with named profiles (e.g., separate OpenRouter keys for different cost tracking)
  • Add auth set-default command to swap a named profile to become the default

Changes

  • Auth module: Added profile support to get/set/remove, plus profiles(), hasDefault(), setDefault() functions
  • CLI commands: login prompts for profile name when default exists, logout/list show profile names, new set-default command
  • Provider: parseModel() extracts profile from provider:profile/model format
  • Config: Added optional profile field to provider schema
  • Errors: Added ProfileNotFoundError and InvalidProfileNameError

Usage

# First login creates default profile
opencode auth login  # select openrouter, enter key

# Second login prompts for profile name
opencode auth login  # select openrouter, enter "work", enter key

# List shows profiles
opencode auth list
# OpenRouter (default) api
# OpenRouter:work api

# Use profile in model string
opencode --model openrouter:work/claude-sonnet-4

# Swap profiles
opencode auth set-default  # select openrouter, select "work"
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/5498 **State:** closed **Merged:** No --- implements https://github.com/sst/opencode/issues/5391 ## Summary - Allow users to store multiple API keys for the same provider with named profiles (e.g., separate OpenRouter keys for different cost tracking) - Add `auth set-default` command to swap a named profile to become the default ## Changes - **Auth module**: Added profile support to get/set/remove, plus `profiles()`, `hasDefault()`, `setDefault()` functions - **CLI commands**: `login` prompts for profile name when default exists, `logout`/`list` show profile names, new `set-default` command - **Provider**: `parseModel()` extracts profile from `provider:profile/model` format - **Config**: Added optional `profile` field to provider schema - **Errors**: Added `ProfileNotFoundError` and `InvalidProfileNameError` ## Usage ```bash # First login creates default profile opencode auth login # select openrouter, enter key # Second login prompts for profile name opencode auth login # select openrouter, enter "work", enter key # List shows profiles opencode auth list # OpenRouter (default) api # OpenRouter:work api # Use profile in model string opencode --model openrouter:work/claude-sonnet-4 # Swap profiles opencode auth set-default # select openrouter, select "work" ```
yindo added the pull-request label 2026-02-16 18:16:16 -05:00
yindo closed this issue 2026-02-16 18:16:16 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11433