CLI OAuth Login
Sign in to LLM providers using browser-based OAuth or device-code flow — tokens auto-refresh in the background
Sign in to any supported provider with a single command. OAuth tokens refresh automatically, so you never have to re-paste an API key.
from praisonaiagents import Agent
agent = Agent(
name="Researcher",
instructions="Answer questions using Gemini.",
model="gemini/gemini-1.5-pro",
)
agent.start("Summarise the RFC 8628 device-code flow in three bullets.")The user runs praisonai auth login; OAuth tokens are stored and refreshed so agents call the provider without pasting API keys.
Quick Start
- Log in with browser (recommended)
bash praisonai auth login github --method oauth --client-id <your-github-oauth-app-client-id>GitHub uses the device-code flow (no local browser callback listener): a short code prints, a browser tab opens to the verification page, and credentials are stored once you approve.
- Log in on a headless server (device code)
On a machine without a browser, add
--no-browserto get a device code:bash praisonai auth login github --method oauth --client-id <your-github-oauth-app-client-id> --no-browserTo sign in, visit https://github.com/login/device and enter code: ABCD-1234Enter the code on any device, then come back — the CLI detects approval automatically.
- Force API-key login
If you prefer to manage keys manually, use
--method apikey:bash praisonai auth login openai --method apikeyYou’ll be prompted for the key interactively (hidden input), or pipe it:
bash echo "sk-..." | praisonai auth login openai --method apikey --key-stdin - Check auth status and expiry
bash praisonai auth listProvider Method Expiry ---------- -------- ------- github oauth 2h 14m openai apikey (n/a)bash praisonai auth status githubShows whether the current token is valid and when it expires.
How It Works
Auth Methods
| Method | Flag | When to use |
|---|---|---|
auto | (default) | Uses OAuth if provider supports it and no --key is given; falls back to API-key prompt |
oauth | --method oauth | Always use OAuth, even if a key is available |
apikey | --method apikey | Always use API key, skip OAuth discovery |
Provider Compatibility
| Provider | API-key login | OAuth login |
|---|---|---|
github | ✅ | ✅ (requires --client-id) |
google / gemini | ✅ | ✅ (requires --client-id) |
azure | ✅ | ✅ (requires --client-id) |
anthropic | ✅ | ❌ |
openai | ✅ | ❌ |
| Custom / self-hosted | ✅ | ✅ (supply endpoints via flags) |
Use praisonai auth login <provider> --method auto — the CLI auto-detects whether OAuth is supported. Registry providers need a --client-id; without one, auto prints how to switch to OAuth and falls back to the API-key prompt.
Token Storage
Credentials are stored at ~/.praisonai/credentials.json (or the path returned by praisonai paths). Legacy ~/.praison/credentials.json is read as a fallback and migrated on the next write — no re-login required. Each provider gets its own entry containing:
- Auth method (
apikeyoroauth) - Token value (API key or access token)
- Refresh token (OAuth only)
- Expiry timestamp (OAuth only)
Tokens are refreshed transparently before each agent run when they are within the refresh window.
Best Practices
Use API keys in CI — not OAuth
OAuth device-code flows require human interaction. In automated pipelines (CI/CD, cron jobs), always use API keys via environment variables:
ANTHROPIC_API_KEY=sk-ant-... praisonai run task.yamlOr store them with --method apikey and a --key-stdin pipe from your secrets manager.
Log out when rotating credentials
When you rotate an API key or revoke an OAuth token:
praisonai auth logout github
praisonai auth login github --method oauth --client-id <your-github-oauth-app-client-id>This removes the old credential and re-runs the login flow.
Pin the model when using OAuth
OAuth credentials are provider-scoped. If a provider has multiple models, pin the default model at login time:
praisonai auth login gemini --method oauth --client-id <your-google-oauth-client-id> --model gemini-1.5-proSupply your OAuth app client id
Registry providers ship endpoints but no client_id. Register your OAuth app with the provider (GitHub App / Google OAuth client for TVs / Azure AD app), then pass its id with --client-id. Until a first-party PraisonAI app is provisioned, you use your own.
praisonai auth login github --method oauth --client-id <your-github-oauth-app-client-id>Sign in to a self-hosted gateway
For a provider outside the registry, supply the OAuth endpoints directly with CLI flags:
praisonai auth login my-gateway --method oauth \
--client-id cli \
--device-authorization-url https://gateway.example.com/oauth/device \
--token-url https://gateway.example.com/oauth/token \
--scope "read write"