LLM Model Configuration By Environment Variable
Carry Code supports configuring AI models through environment variables, enabling seamless integration with CI/CD pipelines, containerized deployments, and existing development workflows.
Overview
Section titled “Overview”Environment variable configuration allows you to:
- Quick Setup: Configure models without editing config files
- CI/CD Integration: Use secrets management in pipelines
- Container Deployment: Inject credentials via environment variables
- Multi-Environment: Different models for different environments
Priority
Section titled “Priority”Environment variable configurations have higher priority than config file settings. When both are present, environment variables take precedence.
Supported Environment Variables
Section titled “Supported Environment Variables”Provider-Specific Variables
Section titled “Provider-Specific Variables”Carry Code automatically detects and configures models from the following environment variables:
| Provider | API Key Variable | Base URL Variable (Optional) | Model Variable (Optional) |
|---|---|---|---|
| Anthropic | ANTHROPIC_AUTH_TOKEN | ANTHROPIC_BASE_URL | ANTHROPIC_MODEL |
| OpenAI | OPENAI_API_KEY | OPENAI_BASE_URL | OPENAI_MODEL |
| Google Gemini | GEMINI_API_KEY | GOOGLE_GEMINI_BASE_URL | GEMINI_MODEL |
| OpenRouter | OPENROUTER_API_KEY | OPENROUTER_BASE_URL | OPENROUTER_MODEL |
Global Default Model
Section titled “Global Default Model”| Variable | Description | Example |
|---|---|---|
CARRYCODE_MODEL | Set the default model to use | anthropic-env:claude-opus-4-6 or gpt-4o |
Usage Examples
Section titled “Usage Examples”Basic Setup
Section titled “Basic Setup”Set the API key for your preferred provider:
# Anthropic Claudeexport ANTHROPIC_AUTH_TOKEN="your-anthropic-api-key"
# OpenAIexport OPENAI_API_KEY="your-openai-api-key"
# Google Geminiexport GEMINI_API_KEY="your-gemini-api-key"
# OpenRouterexport OPENROUTER_API_KEY="your-openrouter-api-key"Custom Base URL
Section titled “Custom Base URL”Override the default API endpoint:
# Use a custom Anthropic endpointexport ANTHROPIC_AUTH_TOKEN="your-key"export ANTHROPIC_BASE_URL="https://your-proxy.example.com"
# Use a custom OpenAI endpoint (e.g., Azure OpenAI)export OPENAI_API_KEY="your-azure-key"export OPENAI_BASE_URL="https://your-resource.openai.azure.com/openai/deployments/your-deployment"Specify Model
Section titled “Specify Model”Override the default model for a provider:
# Use Claude Opus 4.5export ANTHROPIC_AUTH_TOKEN="your-key"export ANTHROPIC_MODEL="claude-opus-4-5-20250514"
# Use GPT-4o miniexport OPENAI_API_KEY="your-key"export OPENAI_MODEL="gpt-4o-mini"
# Use Gemini 2.5 Proexport GEMINI_API_KEY="your-key"export GEMINI_MODEL="gemini-2.5-pro"Set Default Model
Section titled “Set Default Model”Use CARRYCODE_MODEL to specify which model to use by default:
# Use Anthropic model configured via environment variableexport ANTHROPIC_AUTH_TOKEN="your-key"export CARRYCODE_MODEL="anthropic-env:claude-opus-4-6"
# Or use a model name directly (matches first provider with that model)export OPENAI_API_KEY="your-key"export OPENAI_MODEL="gpt-4o"export CARRYCODE_MODEL="gpt-4o"Provider ID Naming
Section titled “Provider ID Naming”When models are configured via environment variables, Carry Code creates provider entries with the ID format {provider}-env:
| Environment Variable | Generated Provider ID |
|---|---|
ANTHROPIC_AUTH_TOKEN | anthropic-env |
OPENAI_API_KEY | openai-env |
GEMINI_API_KEY | gemini-env |
OPENROUTER_API_KEY | openrouter-env |
This allows you to reference these models in commands:
# Switch to environment-configured Anthropic model/model switch anthropic-env
# Set as default/model default openai-envConfiguration Inheritance
Section titled “Configuration Inheritance”Models configured via environment variables inherit default parameters from Carry Code’s built-in provider presets:
- Context Window: Maximum context length
- Temperature: Default sampling temperature
- Top-P: Nucleus sampling parameter
- Max Tokens: Maximum output tokens
These defaults are defined in ConfigProviders.toml and are automatically applied when you configure a model via environment variables.
Shell Configuration
Section titled “Shell Configuration”Add to ~/.bashrc or ~/.bash_profile:
# Carry Code Model Configurationexport ANTHROPIC_AUTH_TOKEN="your-anthropic-key"export OPENAI_API_KEY="your-openai-key"export CARRYCODE_MODEL="anthropic-env:claude-opus-4-6"Add to ~/.zshrc:
# Carry Code Model Configurationexport ANTHROPIC_AUTH_TOKEN="your-anthropic-key"export OPENAI_API_KEY="your-openai-key"export CARRYCODE_MODEL="anthropic-env:claude-opus-4-6"Add to ~/.config/fish/config.fish:
# Carry Code Model Configurationset -gx ANTHROPIC_AUTH_TOKEN "your-anthropic-key"set -gx OPENAI_API_KEY "your-openai-key"set -gx CARRYCODE_MODEL "anthropic-env:claude-opus-4-6"Docker & Kubernetes
Section titled “Docker & Kubernetes”Docker
Section titled “Docker”Pass environment variables when running a container:
docker run -it \ -e ANTHROPIC_AUTH_TOKEN="your-key" \ -e CARRYCODE_MODEL="anthropic-env:claude-opus-4-6" \ carrycode/carrycode:latestOr use an environment file:
# .env fileANTHROPIC_AUTH_TOKEN=your-keyOPENAI_API_KEY=your-keyCARRYCODE_MODEL=anthropic-env:claude-opus-4-6docker run -it --env-file .env carrycode/carrycode:latestKubernetes
Section titled “Kubernetes”Use ConfigMap or Secret:
apiVersion: v1kind: Secretmetadata: name: carrycode-secretstype: OpaquestringData: anthropic-auth-token: "your-key" openai-api-key: "your-key"---apiVersion: v1kind: Podmetadata: name: carrycodespec: containers: - name: carrycode image: carrycode/carrycode:latest env: - name: ANTHROPIC_AUTH_TOKEN valueFrom: secretKeyRef: name: carrycode-secrets key: anthropic-auth-token - name: CARRYCODE_MODEL value: "anthropic-env:claude-opus-4-6"CI/CD Integration
Section titled “CI/CD Integration”GitHub Actions
Section titled “GitHub Actions”Use GitHub Secrets for API keys:
name: AI Code Reviewon: [pull_request]
jobs: review: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run CarryCode env: ANTHROPIC_AUTH_TOKEN: ${{ secrets.ANTHROPIC_API_KEY }} CARRYCODE_MODEL: "anthropic-env:claude-opus-4-6" run: | # Install and run CarryCode carrycode "Review the changes in this PR"GitLab CI
Section titled “GitLab CI”Use GitLab CI/CD variables:
code-review: stage: test script: - carrycode "Review the code changes" variables: ANTHROPIC_AUTH_TOKEN: $ANTHROPIC_API_KEY CARRYCODE_MODEL: "anthropic-env:claude-opus-4-6"Debugging
Section titled “Debugging”Verify Environment Variables
Section titled “Verify Environment Variables”Check if your environment variables are set correctly:
# List all Carry Code-related environment variablesenv | grep -E "(ANTHROPIC|OPENAI|GEMINI|OPENROUTER|CARRYCODE)"Check Active Configuration
Section titled “Check Active Configuration”Within Carry Code, use the /model command to see all configured models, including those from environment variables. Environment-configured models will appear with provider IDs ending in -env.
Common Issues
Section titled “Common Issues”| Issue | Solution |
|---|---|
| Model not appearing | Ensure the API key variable is set and non-empty |
| Wrong model selected | Check CARRYCODE_MODEL format matches provider-id:model-name |
| API errors | Verify the API key is valid and has sufficient credits |
| Custom URL not working | Ensure base URL includes the full API path |
Security Best Practices
Section titled “Security Best Practices”- Never commit API keys to version control
- Use secrets management in CI/CD (GitHub Secrets, GitLab Variables, etc.)
- Rotate keys regularly for production environments
- Restrict key permissions when possible (e.g., read-only for CI)
- Use environment-specific keys for different stages (dev, staging, prod)
See Also
Section titled “See Also”- Model Configuration - Configure models via config file
- MCP Servers - Extend AI capabilities
- Getting Started - Quick start guide