Documentation Index
Fetch the complete documentation index at: https://kagi.micr.dev/llms.txt
Use this file to discover all available pages before exploring further.
Authentication Guide
Authentication is the foundation of the kagi CLI’s functionality. This comprehensive guide explains the two credential types, how they’re used, when each is required, and how to configure them securely.Recommended Setup Path
On a real terminal, the default setup path is:Session Link or API Token, points you to the correct Kagi settings page, accepts a paste, saves into ./.kagi.toml, and validates the selected credential immediately.
Use kagi auth set ... only when you want a non-interactive or scripted flow.
Authentication Overview
The kagi CLI supports two distinct credential types that unlock different capabilities:Session Token (KAGI_SESSION_TOKEN)
What it is: A token from your Kagi Session Link that authenticates you as a Kagi subscriber.
Where it comes from: Generated in your Kagi account settings as a Session Link URL.
What it unlocks:
- Subscriber-only web product features
- Lens-aware search (
kagi search --lens) - Session-backed filtered search
- Kagi Quick Answer (
kagi quick) - Kagi Assistant (
kagi assistant) - Custom assistant management (
kagi assistant custom) - Ask Page (
kagi ask-page) - Lens management (
kagi lens) - Custom bang management (
kagi bang custom) - Redirect rule management (
kagi redirect) - Kagi Translate (
kagi translate) - Subscriber Summarizer (
kagi summarize --subscriber) - Base search via the web product path
API Token (KAGI_API_TOKEN)
What it is: A token for Kagi’s documented public APIs.
Where it comes from: Generated in your Kagi account settings under API.
What it unlocks:
- Public API endpoints
- FastGPT (
kagi fastgpt) - Public Summarizer (
kagi summarizewithout--subscriber) - Web/News Enrichment (
kagi enrich) - Base search via the Search API (if you have API access)
Visual Authentication Flow
Getting Your Tokens
Obtaining a Session Token
Your Session Token is available in your Kagi account settings:- Log into Kagi at kagi.com
- Open Session Link settings
- Copy the full Session Link that looks like:
- This token authenticates as you - protect it like a password
- Anyone with this token can access your Kagi account features
- Don’t commit it to version control
- Don’t share it in public forums or chat
- Rotate it periodically if you suspect compromise
Obtaining an API Token
Your API Token is available separately in API settings:- Log into Kagi at kagi.com
- Open API settings
- Generate a new token if you don’t have one
- Copy the token (long alphanumeric string)
- API access requires available credit
- Monitor your usage in Kagi settings
- API calls consume credit per request
- Different endpoints may have different costs
Token Lifecycle and Management
Token Validity
| Token Type | Lifetime | Renewal |
|---|---|---|
| Session Token | Long-lived (months) | Automatic via Kagi web session |
| API Token | Long-lived (months) | Manual regeneration in settings |
Token Rotation
When to rotate:- Suspected compromise
- Regular security maintenance (every 3-6 months)
- After team member departure
- After changing Kagi account password
- Generate new token in Kagi settings
- Update your configuration with the new token
- Test that new token works
- Revoke old token in Kagi settings
- Remove old token from any saved locations
Configuration Methods
The kagi CLI supports two configuration methods with clear precedence:Method 1: Environment Variables (Highest Priority)
Environment variables take precedence over the config file, making them ideal for:- CI/CD pipelines
- Docker containers
- Temporary testing
- Overriding file configuration
Method 2: Configuration File
The.kagi.toml file provides persistent configuration:
Location:
./.kagi.tomlin the current working directory
Precedence Rules
Credentials are resolved in this order (first match wins):- Environment variables override config file values
- You can temporarily test different tokens via env vars
- CI/CD can inject tokens without modifying files
- File configuration provides defaults, env vars provide overrides
Authentication Verification
Checking Status
See which credentials are configured:Validating Credentials
Test that configured credentials actually work:- Loads credentials using precedence rules
- Attempts a test search
- Reports which token was used
- Confirms authentication succeeds
auth check is intentionally strict and does not use the base-search fallback behavior. It tests the primary credential only.
Command Authentication Requirements
No Authentication Required
These commands work without any tokens:kagi news- Public news feedkagi news --list-categories- News categorieskagi news --chaos- Chaos indexkagi smallweb- Small Web feedkagi auth status- Check configuration
Session Token Required
These commands requireKAGI_SESSION_TOKEN:
kagi search --lens <INDEX>- Lens-aware searchkagi search --region ...,--time ...,--from-date ...,--to-date ...,--order ...,--verbatim, personalization flags - session-backed filtered searchkagi assistant- AI Assistantkagi assistant custom- saved assistant CRUDkagi quick- Quick Answerkagi ask-page- Ask Assistant about one pagekagi lens- lens CRUD and enable/disablekagi bang custom- custom bang CRUDkagi redirect- redirect rule CRUD and enable/disablekagi translate- Kagi Translate text modekagi summarize --subscriber- Subscriber Summarizer- Base search (if no API token configured)
API Token Required
These commands requireKAGI_API_TOKEN:
kagi fastgpt- FastGPT querieskagi enrich web- Web enrichmentkagi enrich news- News enrichmentkagi summarize(without--subscriber) - Public Summarizer- Base search (preferred path when API token available)
Dual Token Support
Base search (kagi search without --lens or runtime filters) supports both tokens:
- Defaults to session unless
[auth.preferred_auth] = "api" - Falls back to session token only when API-first mode is enabled and the Search API rejects the request
- Enables seamless operation regardless of which token you have
Search-Specific Authentication Behavior
Thekagi search command has special authentication logic:
Normal Operation
Base Search Behavior
The base search command follows the configured base-search preference. Scenario 1: Default session-first behaviorSecurity Best Practices
Token Storage
DO:- ✅ Use
kagi authfor local setup so the CLI validates the credential as you save it - ✅ Store tokens in
./.kagi.tomlwith 600 permissions - ✅ Use environment variables in CI/CD secrets
- ✅ Use secret managers (1Password, Vault, etc.)
- ✅ Rotate tokens periodically
- ❌ Commit tokens to version control
- ❌ Hardcode tokens in scripts
- ❌ Share tokens in public channels
- ❌ Store tokens in plain text notes
- ❌ Include tokens in bug reports or logs
Shell History
Be aware thatexport KAGI_TOKEN=... commands may be saved to shell history:
Prevent history logging:
CI/CD Security
GitHub Actions:Docker Security
Avoid in Dockerfile:Team Sharing
For shared development environments:- Each developer has their own tokens
- Use environment-specific config (not committed)
- Document setup in README (without actual tokens)
- Use secret managers for shared CI/CD
.env.example (safe to commit):
.env (NEVER commit):
Troubleshooting Authentication
”missing credentials” Error
Cause: Command requires authentication but no valid token found. Solutions:- Check current status:
kagi auth status - Verify token is set:
echo $KAGI_SESSION_TOKEN - Set token if missing:
kagi authorkagi auth set --session-token '...' - Check correct variable name (SESSION not SESSSION)
“auth check failed” Error
Cause: Token is set but invalid, expired, or revoked. Solutions:- Verify token in Kagi settings
- Check token hasn’t expired
- Regenerate if necessary
- Update configuration with new token
”this command requires KAGI_SESSION_TOKEN”
Cause: Attempting to use subscriber features with only API token. Solutions:- Get Session Token from Kagi settings
- Set session token:
kagi authorkagi auth set --session-token '...' - Verify:
kagi auth status
”this command requires KAGI_API_TOKEN”
Cause: Attempting to use API features without API token. Solutions:- Get API Token from Kagi settings
- Check you have API credit available
- Set API token:
kagi authorkagi auth set --api-token '...' - Verify:
kagi auth status
Token Not Being Used from Config File
Cause: Environment variable is overriding file. Check:Session Link URL Not Working
Cause: CLI expects either full URL or just token. Solution:Advanced Configuration
Platform-Specific Configuration
macOS Keychain (alternative storage):Multiple Profiles
For users with multiple Kagi accounts:Summary
Key takeaways:- Two token types: Session (subscriber features) and API (paid API features)
- Best local setup path:
kagi auth - Clear precedence: Environment variables override config files
- Configured search preference: Base search defaults to session unless
[auth.preferred_auth] = "api" - Security first: Never commit tokens, rotate regularly, use secret managers
- Easy verification: Use
kagi auth statusandkagi auth check
- Session Token = Personal subscription features
- API Token = Paid API endpoints
- Both can coexist, each serves different commands
- Base search follows the configured search preference
Next Steps
- Auth Matrix - Complete command-to-token mapping
- Workflows - Real-world authentication patterns
- Troubleshooting - More auth debugging help
- Support and Contribution - Safe handling and contribution notes
Keep your tokens secure and happy searching!