Skip to content

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.


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

Environment variable configurations have higher priority than config file settings. When both are present, environment variables take precedence.


Carry Code automatically detects and configures models from the following environment variables:

ProviderAPI Key VariableBase URL Variable (Optional)Model Variable (Optional)
AnthropicANTHROPIC_AUTH_TOKENANTHROPIC_BASE_URLANTHROPIC_MODEL
OpenAIOPENAI_API_KEYOPENAI_BASE_URLOPENAI_MODEL
Google GeminiGEMINI_API_KEYGOOGLE_GEMINI_BASE_URLGEMINI_MODEL
OpenRouterOPENROUTER_API_KEYOPENROUTER_BASE_URLOPENROUTER_MODEL
VariableDescriptionExample
CARRYCODE_MODELSet the default model to useanthropic-env:claude-opus-4-6 or gpt-4o

Set the API key for your preferred provider:

Terminal window
# Anthropic Claude
export ANTHROPIC_AUTH_TOKEN="your-anthropic-api-key"
# OpenAI
export OPENAI_API_KEY="your-openai-api-key"
# Google Gemini
export GEMINI_API_KEY="your-gemini-api-key"
# OpenRouter
export OPENROUTER_API_KEY="your-openrouter-api-key"

Override the default API endpoint:

Terminal window
# Use a custom Anthropic endpoint
export 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"

Override the default model for a provider:

Terminal window
# Use Claude Opus 4.5
export ANTHROPIC_AUTH_TOKEN="your-key"
export ANTHROPIC_MODEL="claude-opus-4-5-20250514"
# Use GPT-4o mini
export OPENAI_API_KEY="your-key"
export OPENAI_MODEL="gpt-4o-mini"
# Use Gemini 2.5 Pro
export GEMINI_API_KEY="your-key"
export GEMINI_MODEL="gemini-2.5-pro"

Use CARRYCODE_MODEL to specify which model to use by default:

Terminal window
# Use Anthropic model configured via environment variable
export 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"

When models are configured via environment variables, Carry Code creates provider entries with the ID format {provider}-env:

Environment VariableGenerated Provider ID
ANTHROPIC_AUTH_TOKENanthropic-env
OPENAI_API_KEYopenai-env
GEMINI_API_KEYgemini-env
OPENROUTER_API_KEYopenrouter-env

This allows you to reference these models in commands:

Terminal window
# Switch to environment-configured Anthropic model
/model switch anthropic-env
# Set as default
/model default openai-env

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.


Add to ~/.bashrc or ~/.bash_profile:

Terminal window
# Carry Code Model Configuration
export 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:

Terminal window
# Carry Code Model Configuration
export 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:

Terminal window
# Carry Code Model Configuration
set -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"

Pass environment variables when running a container:

Terminal window
docker run -it \
-e ANTHROPIC_AUTH_TOKEN="your-key" \
-e CARRYCODE_MODEL="anthropic-env:claude-opus-4-6" \
carrycode/carrycode:latest

Or use an environment file:

Terminal window
# .env file
ANTHROPIC_AUTH_TOKEN=your-key
OPENAI_API_KEY=your-key
CARRYCODE_MODEL=anthropic-env:claude-opus-4-6
Terminal window
docker run -it --env-file .env carrycode/carrycode:latest

Use ConfigMap or Secret:

apiVersion: v1
kind: Secret
metadata:
name: carrycode-secrets
type: Opaque
stringData:
anthropic-auth-token: "your-key"
openai-api-key: "your-key"
---
apiVersion: v1
kind: Pod
metadata:
name: carrycode
spec:
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"

Use GitHub Secrets for API keys:

name: AI Code Review
on: [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"

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"

Check if your environment variables are set correctly:

Terminal window
# List all Carry Code-related environment variables
env | grep -E "(ANTHROPIC|OPENAI|GEMINI|OPENROUTER|CARRYCODE)"

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.

IssueSolution
Model not appearingEnsure the API key variable is set and non-empty
Wrong model selectedCheck CARRYCODE_MODEL format matches provider-id:model-name
API errorsVerify the API key is valid and has sufficient credits
Custom URL not workingEnsure base URL includes the full API path

  1. Never commit API keys to version control
  2. Use secrets management in CI/CD (GitHub Secrets, GitLab Variables, etc.)
  3. Rotate keys regularly for production environments
  4. Restrict key permissions when possible (e.g., read-only for CI)
  5. Use environment-specific keys for different stages (dev, staging, prod)