aider/How To/Use mise and op run to load API Keys
Properties
- tags
- Diataxis/How To
How to use mise and 1Password/Dev/op/run to inject API/Key into aider
Overview
- This guide shows you how to securely inject API keys from 1Password into aider using mise's environment management and
op run - For developers who want to use aider with their OpenAI API key stored in 1Password
- We'll set this up to work with both global defaults and project-specific configurations
- The approach uses mise's environment variables with 1Password secret references, ensuring no secrets are stored on disk
- This guide shows you how to securely inject API keys from 1Password into aider using mise's environment management and
Prerequisites
Steps
1. Configure Global Default
- Edit
~/.config/mise/config.tomlto set your default API keys:- toml
# Global environment variables [env] # Default API keys using 1Password references # These match aider's supported environment variables: # https://aider.chat/docs/config/api-keys.html OPENAI_API_KEY = "op://your-vault/default-openai-api-key/credential" ANTHROPIC_API_KEY = "op://your-vault/default-anthropic-api-key/credential" GEMINI_API_KEY = "op://your-vault/default-gemini-api-key/credential" # Simple task that wraps aider with op run [tasks.aider] description = "Run aider with 1Password integration, passing through all arguments" run = "op run -- aider $@" # Pass all arguments directly to aider alias = "ai" dir = "{{cwd}}" # Run in the current directory, not mise's config directory
- Replace
your-vaultwith your actual 1Password vault name - Update the item names to match your 1Password items
- Edit
2. Run aider using mise tasks
3. Project-Specific Configuration
- Create a
.mise.tomlin your project directory to use project-specific API keys:- toml
# Project-specific environment variables [env] # Override API keys for this project # See https://aider.chat/docs/config/api-keys.html for all supported keys # Each project can have its own set of API keys from different vaults OPENAI_API_KEY = "op://project-vault/project-openai-key/credential" ANTHROPIC_API_KEY = "op://project-vault/project-anthropic-key/credential" GEMINI_API_KEY = "op://project-vault/project-gemini-key/credential"
- For project-specific overrides that shouldn't be committed:
- Create a
Troubleshooting
Benefits of this Approach
- No secrets stored on disk - only references in mise configuration
- No separate
.envfiles needed - everything managed by mise - Secrets only available during command execution
- Seamless authentication via 1Password desktop app
- Hierarchical configuration with mise (global → project → local)
- Easy to override API keys per project
- Integrated with mise's task management system
Related