Skip to content

feat: add config subcommand to manage API keys with hot-reload#233

Merged
johnlanni merged 1 commit into
higress-group:mainfrom
johnlanni:feature/config-subcommand
Feb 1, 2026
Merged

feat: add config subcommand to manage API keys with hot-reload#233
johnlanni merged 1 commit into
higress-group:mainfrom
johnlanni:feature/config-subcommand

Conversation

@johnlanni
Copy link
Copy Markdown
Contributor

Description

This PR adds a new config subcommand to get-ai-gateway.sh script for managing LLM provider API keys with hot-reload support.

Changes

New Commands

  • config add --provider <provider> --key <api-key> - Add or update an API key
  • config list - List all configured API keys (with masking for security)
  • config remove --provider <provider> - Remove an API key

Features

  • Hot-reload support: Updates take effect immediately without restarting the container
  • Dual update: Both host config file (default.cfg) and container config (ai-proxy.internal.yaml) are updated
  • Provider mapping: Friendly provider names (e.g., qwenDASHSCOPE_API_KEY)
  • API key masking: Secure display of sensitive keys (e.g., sk-ab***cd12)
  • Python-based YAML editing: Reliable modification of ai-proxy configuration
  • Clear error messages: Helpful guidance for users
  • Updated help documentation: Complete usage examples

Implementation Details

The hot-reload mechanism works similar to route command:

  1. Read ai-proxy.internal.yaml from container
  2. Modify API key in the configuration
  3. Copy updated config back to container
  4. Touch the config file to trigger hot-reload

This approach mirrors the configureAutoRouting() pattern and ensures configuration changes take effect immediately without container restart.

Examples

# List all configured API keys
./get-ai-gateway.sh config list

# Add or update an API key (hot-reload, no restart needed)
./get-ai-gateway.sh config add --provider deepseek --key sk-xxx

# Remove an API key (hot-reload, no restart needed)
./get-ai-gateway.sh config remove --provider deepseek

Supported providers

  • dashscope (qwen), deepseek, moonshot (kimi), zhipuai, openai, openrouter
  • claude, gemini, groq, doubao, baichuan, yi, stepfun, minimax
  • cohere, mistral, github, fireworks, togetherai, grok

Benefits

  • Easier management of API keys without manual config file editing
  • Better security with masked display of sensitive keys
  • Hot-reload: No container restart required
  • Improved user experience for updating credentials
  • Consistent with existing route command pattern

Differences from previous implementation

This implementation addresses the issue with the previous PR:

  • Hot-reload: Uses touch mechanism instead of stop/start
  • Follows established patterns: Mirrors configureAutoRouting() and route commands
  • Minimal disruption: Updates are instant without service interruption

Testing

  • Syntax check passed (bash -n)
  • Command parsing works correctly
  • Help documentation updated with examples
  • Follows existing code patterns

Related PR

- Add config add: Add or update API key for a provider
- Add config list: List all configured API keys (with masking)
- Add config remove: Remove API key for a provider
- Support for all LLM providers (dashscope, deepseek, openai, etc.)
- Hot-reload: Updates take effect immediately without restart
- User-friendly provider name mapping
- Both host config file (default.cfg) and container config (ai-proxy.internal.yaml) are updated
- Touch config file to trigger hot-reload
- Updated help documentation with examples
@johnlanni johnlanni requested a review from CH3CHO as a code owner February 1, 2026 09:22
@johnlanni johnlanni merged commit cf3d9f2 into higress-group:main Feb 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant