Skip to content

Conversation

@Winston-503
Copy link

@Winston-503 Winston-503 commented Dec 9, 2025

Summary

This PR adds support for specifying API keys via environment variable references in configuration files using the ${VARIABLE} syntax.

Motivation

Previously, users could either hardcode API keys directly in config files (security risk) or rely on the implicit OPENAI_API_KEY fallback. This change allows explicit control over which environment variable to use, enabling:

  • Different API keys for different models/providers
  • Clear documentation of required environment variables in config
  • Avoiding accidental key exposure in version-controlled config files

@CLAassistant
Copy link

CLAassistant commented Dec 9, 2025

CLA assistant check
All committers have signed the CLA.

@codelion
Copy link
Member

codelion commented Dec 9, 2025

Thanks for the PR! You're right that we need a way to reference environment variables in config files.

However, I'd prefer to use the more standard ${VAR} or $VAR substitution syntax that's common in config files (similar to Docker Compose, shell scripts, etc.). This would be more intuitive for users and follow existing conventions.

For example:

llm:
  api_key: ${OPENAI_API_KEY}
  models:
    - name: claude-sonnet-4-20250514
      api_key: ${ANTHROPIC_API_KEY}

This could be implemented by processing the loaded YAML dict and expanding any ${VAR} patterns using os.environ.get(). Would you be open to taking this approach instead?

@Winston-503
Copy link
Author

I've updated the implementation to use the standard ${VAR} syntax as suggested. It's currently used for api_key only for simplicity. Recursive expansion for all config values (like api_base, etc.) could be added in the future if there's demand for it.

@Winston-503 Winston-503 changed the title feat: from_env for API key configuration feat: ${VAR} for API key configuration Dec 10, 2025
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.

3 participants