Skip to content

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.

PropertyValue
RequiredYes (unless set in config file)
Formatsk-or-v1-...
Overridesapi_key in config file

Get a key: openrouter.ai/keys

Terminal window
export OPENROUTER_API_KEY="sk-or-v1-your-key-here"

Optional Variables

KICODE_MODEL

Override the default AI model.

PropertyValue
RequiredNo
FormatOpenRouter model ID
Defaultx-ai/grok-code-fast-1
Overridesmodel in config file
Terminal window
export KICODE_MODEL="anthropic/claude-3.5-sonnet"

KICODE_DEBUG

Enable debug output for troubleshooting.

PropertyValue
RequiredNo
Format1 to enable
DefaultDisabled
Terminal window
export KICODE_DEBUG=1

When enabled, kicode prints:

  • API request/response details
  • Tool execution details
  • Configuration loading info

Setting Environment Variables

Temporary (Current Session)

Terminal window
# Set for current terminal session
export OPENROUTER_API_KEY="sk-or-v1-..."
# Or set for a single command
OPENROUTER_API_KEY="sk-or-v1-..." kicode

Permanent (Shell Profile)

Add to your shell configuration file:

Bash (~/.bashrc):

Terminal window
export OPENROUTER_API_KEY="sk-or-v1-..."
export KICODE_MODEL="anthropic/claude-3.5-sonnet"

Zsh (~/.zshrc):

Terminal window
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:

Terminal window
source ~/.bashrc # or ~/.zshrc

Per-Project (dotenv)

While kicode doesn’t automatically load .env files, you can use tools like direnv:

Terminal window
# .envrc in your project
export KICODE_MODEL="anthropic/claude-3.5-sonnet"

Priority Order

When a setting is available from multiple sources:

  1. CLI arguments (highest priority)

    • kicode --model xyz
  2. Environment variables

    • KICODE_MODEL="xyz"
  3. Config file

    • model = "xyz" in config.toml
  4. Built-in defaults (lowest priority)

Example:

Terminal window
# 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:

Terminal window
# Enable debug mode
KICODE_DEBUG=1 kicode
# Output shows loaded configuration

Common Patterns

Different Models per Project

Terminal window
# In project A
cd ~/project-a
KICODE_MODEL="anthropic/claude-3.5-sonnet" kicode
# In project B
cd ~/project-b
KICODE_MODEL="openai/gpt-4-turbo" kicode

Testing with Debug Mode

Terminal window
# One-time debug session
KICODE_DEBUG=1 kicode

Quick Model Override

Terminal window
# Use a specific model without changing config
kicode --model anthropic/claude-3-opus

Troubleshooting

”API key not found” Error

The API key is not set anywhere.

Check:

Terminal window
echo $OPENROUTER_API_KEY
# Should print your key

Fix:

Terminal window
export OPENROUTER_API_KEY="sk-or-v1-..."

Environment Variable Not Taking Effect

Shell may need to be reloaded.

Fix:

Terminal window
source ~/.bashrc # or ~/.zshrc
# Or open a new terminal

Variable Set but Wrong Value Used

CLI argument or later-set variable may be overriding.

Check:

Terminal window
KICODE_DEBUG=1 kicode
# Look for "Using model:" in output

Security Notes

  1. Don’t commit API keys

    • Never add keys to version control
    • Use .gitignore for any local env files
  2. Restrict file permissions

    • Shell profiles should be readable only by you
    • chmod 600 ~/.bashrc
  3. Consider secret managers

    • For production/team use, consider tools like:
    • 1Password CLI
    • HashiCorp Vault
    • AWS Secrets Manager