kagi auth
Manage authentication credentials for the kagi CLI. This command allows you to view, set, and validate your API and session tokens.
Synopsis
Subcommands
| Subcommand | Description |
|---|---|
status | Display current credential configuration |
check | Validate credentials by testing authentication |
set | Save credentials to configuration file |
Description
Thekagi auth command group manages your authentication state. Unlike most CLI tools that simply fail when credentials are missing, kagi provides detailed visibility into which credentials are configured, where they come from, and whether they’re valid.
Credential Sources
The CLI checks credentials in this order:- Environment variables -
KAGI_API_TOKEN,KAGI_SESSION_TOKEN - Configuration file -
./.kagi.toml
kagi auth status
Display the current credential configuration without testing validity.
Synopsis
Description
Shows which credentials are configured and their sources. This is a read-only operation that does not validate tokens or make network requests.Output Examples
No credentials configured:Exit Codes
| Code | Meaning |
|---|---|
| 0 | Always succeeds (informational command) |
kagi auth check
Validate configured credentials by attempting an authenticated operation.
Synopsis
Description
Tests that your configured credentials actually work by attempting a search operation. This command is intentionally strict and does not use the base-search fallback behavior. Important: Unlike thesearch command which can fall back between API and session tokens, auth check tests the primary credential only. This ensures you get an accurate picture of which specific token is working.
Output Examples
Session token valid:What It Tests
- Loads credentials using standard precedence rules
- Selects primary credential based on availability
- Attempts a test search with that credential
- Reports success and credential type
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Credentials are valid and working |
| 1 | Credentials missing, invalid, or rejected |
When to Use
- After setting up credentials to verify they work
- When debugging authentication issues
- Before running automated scripts to ensure auth is ready
- After rotating tokens to confirm new ones work
kagi auth set
Save credentials to the configuration file.
Synopsis
Options
--session-token <TOKEN>
Set the Kagi Session Token.
Accepts:
- Full Session Link URL:
https://kagi.com/search?token=abc123... - Raw token value:
abc123...
--api-token <TOKEN>
Set the Kagi API Token.
Accepts: Raw API token string
Example:
Description
Saves the provided credentials to./.kagi.toml. You can set one or both tokens in a single command.
Behavior
- Creates
./.kagi.tomlif it doesn’t exist - Updates existing tokens if already present
- Extracts token from full Session Link URL automatically
- Saves to the current working directory
Output Examples
Set session token:File Location
./.kagi.tomlin the current working directory
File Format
The configuration file is TOML format:Exit Codes
| Code | Meaning |
|---|---|
| 0 | Credentials saved successfully |
| 1 | Error writing configuration file |
Common Workflows
Initial Setup
Adding API Token Later
Updating Tokens
Environment Override
Debugging Authentication
Security Considerations
Token Storage
- Tokens are stored in plain text in
./.kagi.toml - Set file permissions to 600 (readable only by owner):
- Don’t commit this file to version control
- Add
.kagi.tomlto your.gitignore
Token Visibility
auth statusshows that tokens exist but doesn’t display their valuesauth checktests tokens without displaying them- Environment variables may be visible in process lists
Rotation
When rotating tokens:- Generate new token in Kagi settings
- Set new token:
kagi auth set --session-token 'NEW_TOKEN' - Verify:
kagi auth check - Revoke old token in Kagi settings
Exit Codes Summary
| Subcommand | Success | Error |
|---|---|---|
auth status | 0 | 0 (always succeeds) |
auth check | 0 | 1 |
auth set | 0 | 1 |
Troubleshooting
”Config file not found”
Normal if you haven’t runauth set yet. Set your tokens to create it.
”Permission denied” when setting
Changes not taking effect
Remember environment variables override the config file:Comparison with Manual Configuration
You can also edit./.kagi.toml directly:
auth set command:
- Validates the format
- Sets proper file permissions
- Provides confirmation output
- Is less error-prone
Related Commands
kagi search- Uses authentication for searchkagi summarize- Uses authentication for summarizationkagi assistant- Requires session token
See Also
- Authentication Guide - Complete auth walkthrough
- Troubleshooting - Auth debugging help
- Auth Matrix - Which commands need which tokens