API Management Commands
VritraAI supports multiple AI providers (OpenRouter and Google Gemini) and provides comprehensive API management tools. These commands help you configure API keys, switch between providers, and manage API settings.
API Key Management
apikey [subcommand]
Manage API keys for different AI providers. Supports OpenRouter and Google Gemini API keys with secure storage and validation.
Features:
- Set and replace API keys for OpenRouter and Gemini
- Show API key status (masked for security)
- Clear API keys for specific providers or all providers
- Test API key functionality
- Automatic saving and persistence across sessions
- Basic key validation (length checking)
Subcommands:
apikey show- Show current API key status for all providersapikey openrouter <key>- Set/replace OpenRouter API keyapikey gemini <key>- Set/replace Gemini API keyapikey clear <provider>- Clear specific provider key (openrouter/gemini)apikey clear all- Clear all API keysapikey test- Test current API keyapikey test openrouter- Test OpenRouter API keyapikey test gemini- Test Gemini API key
Examples:
# Show API key status
apikey show
# Set OpenRouter API key
apikey openrouter sk-or-v1-your-key-here
# Set Gemini API key
apikey gemini AIzaSy-your-gemini-key-here
# Test API key
apikey test
apikey test openrouter
apikey test gemini
# Clear specific provider key
apikey clear openrouter
apikey clear gemini
# Clear all API keys
apikey clear all
Security Features:
- API keys are masked when displayed (shows first 8 and last 4 characters)
- Keys are automatically saved to configuration file
- Basic validation warns if key seems too short
- Keys persist across sessions
Note: Setting a key will replace any existing key for that provider. Keys are saved immediately and persist across sessions.
API Base Management
api_base [subcommand]
Switch between different AI providers (OpenRouter and Gemini). Manages API base URL, model switching, and provider-specific settings.
Features:
- Switch between OpenRouter and Gemini APIs
- Show current API base and status
- Detailed API status report
- Automatic model switching when changing providers
- Preserves last used model for each provider
- Preserves theme and prompt style settings
Subcommands:
api_base show- Show current API base and statusapi_base openrouter- Switch to OpenRouter APIapi_base gemini- Switch to Google Gemini APIapi_base status- Show detailed API status report
Examples:
# Show current API base
api_base show
# Switch to OpenRouter
api_base openrouter
# Switch to Gemini
api_base gemini
# Get detailed status
api_base status
Switching Behavior:
- When switching to OpenRouter, if current model is Gemini, switches to last used OpenRouter model
- When switching to Gemini, if current model is OpenRouter, switches to last used Gemini model
- Preserves theme and prompt style settings
- Updates AI models list and initializes API client
- Saves configuration automatically
Status Report Includes:
- Active API base (OpenRouter or Gemini)
- Current model
- AI features status (Enabled/Disabled)
- OpenRouter status and available models count
- Gemini status and available models count
- Quick command suggestions
Supported Providers
OpenRouter
OpenRouter provides access to multiple AI models from various providers through a unified API.
Features:
- Access to multiple AI models (GPT-4, Claude, Llama, etc.)
- Unified API interface
- Pay-per-use pricing
- Model selection flexibility
Getting an API Key:
- Visit openrouter.ai
- Sign up for an account
- Navigate to API Keys section
- Create a new API key
- Use
apikey openrouter <your-key>to set it
API Key Format:
OpenRouter API keys typically start with sk-or-v1-
Google Gemini
Google's Gemini AI models provide powerful language understanding and generation capabilities.
Features:
- Google's latest AI models
- Free tier available
- Fast response times
- Built-in HTTP request support
Getting an API Key:
- Visit Google AI Studio
- Sign in with your Google account
- Create a new API key
- Use
apikey gemini <your-key>to set it
API Key Format:
Gemini API keys typically start with AIzaSy
Configuration Storage
API keys and settings are stored in:
- Primary:
~/.config-vritrasecz/vritraai/config.json(via config_manager) - Fallback:
~/.config-vritrasecz/vritraai/config.json(legacy config.py)
Stored Settings:
- API keys (OpenRouter and Gemini)
- Current API base (openrouter/gemini)
- Current model
- Last used model for each provider
- AI enabled status
Best Practices
- Set keys first: Configure API keys before switching providers
- Test after setting: Use
apikey testto verify keys work - Check status: Use
api_base statusfor comprehensive overview - Keep keys secure: Never share API keys or commit them to version control
- Use appropriate provider: Choose based on your needs (cost, model availability, etc.)
- Clear unused keys: Remove keys you're not using for security
💡 Pro Tip: You can configure both OpenRouter and Gemini API keys simultaneously. Switch between them using api_base openrouter or api_base gemini without re-entering keys.