Add Multiple Grok OAuth Accounts
A practical, step-by-step journey preserved from an AI conversation.
01Add multiple Grok oauth in OpenCode .. asking this because I have multiple…
⌁User prompt
can you add multiple Grok oauth in OpenCode .. asking this because I have multiple X accounts with Premium
Assistant response
Yes. I checked the current OpenCode/xAI situation, and you can use multiple Grok OAuth accounts, but I would not rely on OpenCode's built-in xAI connection to manage them yet.
OpenCode officially supports logging into xAI using your Grok/X Premium subscription through OAuth. Their current docs say an X Premium or Grok plan that includes Grok API access can be used without an XAI_API_KEY. [Image omitted from import]OpenCode+1
For your specific situation, where you have several X Premium accounts and want all of them available in OpenCode, there is a dedicated plugin called opencode-multi-xai. It was made specifically for this. [Image omitted from import]GitHub
It supports:
-
Multiple X / Grok OAuth accounts
-
Each account keeps its own subscription quota
-
Manual switching between accounts
-
Priority ordering
-
Automatic rotation when an account encounters a recoverable limit/error
-
Per-account quota/plan information
-
Grok 4.x and Grok Build models
-
A small account-management TUI
The architecture would basically be:
OpenCode
│
▼
Grok Multi-Account provider
│
├── X Premium Account 1
├── X Premium Account 2
├── X Premium Account 3
└── X Premium Account 4
│
▼
xAI API
The plugin creates a separate OpenCode provider called:
xai-multi
instead of replacing your normal xai provider. [Image omitted from import]GitHub
So you could actually keep:
xai
↳ your normal Grok OAuth
xai-multi
↳ X account A
↳ X account B
↳ X account C
How you would use it
Since you're on Windows, I'd probably use Git Bash for the installation because the project's quick installer is Bash-based.
Bashgit clone https://github.com/zane-tv/opencode-multi-xai.git
cd opencode-multi-xai
npm install
npm run setup
The repository also provides an installer that wires the provider into OpenCode automatically. [Image omitted from import]GitHub
After installation you can run:
Bashop-xai tui
You'll get an account manager.
Press:
a
to add an account using device OAuth.
Then log into:
X Premium Account #1
Repeat:
a
and log into:
X Premium Account #2
and so on.
Alternatively:
Bashop-xai add
can be run repeatedly.
To see them:
Bashop-xai list
To see quota information:
Bashop-xai limits --probe
To manually switch:
Bashop-xai switch --index 1
The plugin can also automatically rotate accounts when the active one encounters a recoverable failure. [Image omitted from import]GitHub
One thing I'd be careful about
This is a third-party OpenCode plugin, not an official xAI/OpenCode feature. It stores the OAuth credentials locally in:
~/.config/opencode/multi-xai-accounts.json
The developer explicitly warns not to commit this file because it contains authentication tokens. [Image omitted from import]GitHub
The repository is also relatively small at the moment, so I'd treat it more cautiously than an official OpenCode integration.
For your situation
If you have, say:
X Account A → Premium
X Account B → Premium
X Account C → Premium
X Account D → Premium
and each account actually has Grok API entitlement, then yes, this is pretty much exactly what you're looking for.
You could have OpenCode use Grok as normal and maintain a pool of your X Premium OAuth accounts rather than logging out and logging into another X account every time you hit the individual account's allowance.
One important distinction is that each X account needs its own eligible Grok entitlement. Having Premium on Account A doesn't transfer quota to Account B. OpenCode's documentation explicitly says the subscription needs to include Grok API access. [Image omitted from import]OpenCode
Given that you were already using Grok 4.6 in OpenCode earlier, I'd keep your existing working xAI OAuth untouched first, install xai-multi alongside it, and test with two of your X accounts before adding the rest. That way there is essentially no downside if the plugin behaves strangely with your current OpenCode version.