Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 10, 2025

This PR renames the openai_api parameter to openai_api_key across all LLM functions while maintaining full backwards compatibility. The change addresses the issue that openai_api was a non-standard parameter name that was hard to remember.

Key Changes

Parameter Renaming

All LLM functions now accept both openai_api_key (new, preferred) and openai_api (legacy, deprecated) parameters:

  • chat_completion()
  • extract_fields_from_text()
  • match_goals_from_text()
  • classify_text()
  • synthesize_user_responses()

When both parameters are provided, openai_api_key takes precedence.

Enhanced Configuration Support

Added _get_openai_api_key() helper function that checks configuration in priority order:

  1. openai api key: sk-... (highest priority, direct key format)
  2. openai: key: sk-... (standardized nested format)
  3. open ai: key: sk-... (legacy nested format with space)
  4. OPENAI_API_KEY environment variable (lowest priority)

This ensures the openai api key configuration mentioned in the issue becomes the default, highest-priority option.

Documentation Updates

  • Updated all function docstrings to reference openai_api_key as the primary parameter
  • Added deprecation notes for openai_api parameter
  • Updated configuration examples in error messages to use standardized format
  • Updated class docstrings to reference new configuration format

Testing

Added comprehensive test suite (test_llms.py) that validates:

  • Configuration lookup priority order
  • Parameter backwards compatibility
  • Edge cases like non-dict config values

Backwards Compatibility

All existing code continues to work unchanged. Users can:

  • Continue using openai_api parameter without modification
  • Continue using existing configuration formats (open ai: key)
  • Gradually migrate to openai_api_key and standardized config formats

Example Usage

# New preferred way
chat_completion(
    system_message="You are a helpful assistant",
    user_message="Hello",
    openai_api_key="sk-..."  # New parameter name
)

# Legacy way (still works)
chat_completion(
    system_message="You are a helpful assistant", 
    user_message="Hello",
    openai_api="sk-..."  # Old parameter name
)

Configuration Examples

# New highest priority format
openai api key: sk-...

# New standardized nested format  
openai:
  key: sk-...
  
# Legacy format (still supported)
open ai:
  key: sk-...

Fixes #278.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Rename openai_api to openai_api_key Rename openai_api parameter to openai_api_key with backwards compatibility Sep 10, 2025
@Copilot Copilot AI requested a review from nonprofittechy September 10, 2025 20:35
Copilot finished work on behalf of nonprofittechy September 10, 2025 20:35
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.

Rename openai_api to openai_api_key
2 participants