Environment Variables
kicode uses several environment variables for configuration. These override settings from the config file.
Required Variables
OPENROUTER_API_KEY
Your OpenRouter API key for authentication.
| Property | Value |
|---|---|
| Required | Yes (unless set in config file) |
| Format | sk-or-v1-... |
| Overrides | api_key in config file |
Get a key: openrouter.ai/keys
export OPENROUTER_API_KEY="sk-or-v1-your-key-here"Optional Variables
KICODE_MODEL
Override the default AI model.
| Property | Value |
|---|---|
| Required | No |
| Format | OpenRouter model ID |
| Default | x-ai/grok-code-fast-1 |
| Overrides | model in config file |
export KICODE_MODEL="anthropic/claude-3.5-sonnet"KICODE_DEBUG
Enable debug output for troubleshooting.
| Property | Value |
|---|---|
| Required | No |
| Format | 1 to enable |
| Default | Disabled |
export KICODE_DEBUG=1When enabled, kicode prints:
- API request/response details
- Tool execution details
- Configuration loading info
Setting Environment Variables
Temporary (Current Session)
# Set for current terminal sessionexport OPENROUTER_API_KEY="sk-or-v1-..."
# Or set for a single commandOPENROUTER_API_KEY="sk-or-v1-..." kicodePermanent (Shell Profile)
Add to your shell configuration file:
Bash (~/.bashrc):
export OPENROUTER_API_KEY="sk-or-v1-..."export KICODE_MODEL="anthropic/claude-3.5-sonnet"Zsh (~/.zshrc):
export OPENROUTER_API_KEY="sk-or-v1-..."export KICODE_MODEL="anthropic/claude-3.5-sonnet"Fish (~/.config/fish/config.fish):
set -gx OPENROUTER_API_KEY "sk-or-v1-..."set -gx KICODE_MODEL "anthropic/claude-3.5-sonnet"After editing, reload your shell:
source ~/.bashrc # or ~/.zshrcPer-Project (dotenv)
While kicode doesn’t automatically load .env files, you can use tools like direnv:
# .envrc in your projectexport KICODE_MODEL="anthropic/claude-3.5-sonnet"Priority Order
When a setting is available from multiple sources:
-
CLI arguments (highest priority)
kicode --model xyz
-
Environment variables
KICODE_MODEL="xyz"
-
Config file
model = "xyz"in config.toml
-
Built-in defaults (lowest priority)
Example:
# Config file: model = "gpt-4"# Environment: KICODE_MODEL="claude-3"# CLI: --model opus
kicode --model opus# Uses: opus (CLI wins)
kicode# Uses: claude-3 (env wins over config)Checking Current Values
To see what values kicode is using:
# Enable debug modeKICODE_DEBUG=1 kicode
# Output shows loaded configurationCommon Patterns
Different Models per Project
# In project Acd ~/project-aKICODE_MODEL="anthropic/claude-3.5-sonnet" kicode
# In project Bcd ~/project-bKICODE_MODEL="openai/gpt-4-turbo" kicodeTesting with Debug Mode
# One-time debug sessionKICODE_DEBUG=1 kicodeQuick Model Override
# Use a specific model without changing configkicode --model anthropic/claude-3-opusTroubleshooting
”API key not found” Error
The API key is not set anywhere.
Check:
echo $OPENROUTER_API_KEY# Should print your keyFix:
export OPENROUTER_API_KEY="sk-or-v1-..."Environment Variable Not Taking Effect
Shell may need to be reloaded.
Fix:
source ~/.bashrc # or ~/.zshrc# Or open a new terminalVariable Set but Wrong Value Used
CLI argument or later-set variable may be overriding.
Check:
KICODE_DEBUG=1 kicode# Look for "Using model:" in outputSecurity Notes
-
Don’t commit API keys
- Never add keys to version control
- Use
.gitignorefor any local env files
-
Restrict file permissions
- Shell profiles should be readable only by you
chmod 600 ~/.bashrc
-
Consider secret managers
- For production/team use, consider tools like:
- 1Password CLI
- HashiCorp Vault
- AWS Secrets Manager
Related
- Configuration Reference - Config file options
- Models Reference - Available models