yera.cli.setup_handlers.openai
OpenAI provider setup handler.
Symbols
OpenAISetup
BaseProviderSetupHandler for configuring OpenAI provider connections.
This class implements the logic required to discover, prompt for, and validate the environment variables used to authenticate with OpenAI's API.
Methods
OpenAISetup.detect_config
detect_config() → OpenAIConnection | NoneAttempts to automatically detect an OpenAI API key from the environment.
Checks for the presence of the default OpenAI environment variable. If found, it returns a connection configuration pointing to that variable.
Returns
An OpenAIConnection instance if the default environment variable is detected; otherwise, None.
OpenAISetup.ask_for_config
ask_for_config() → OpenAIConnection | NoneInteractively prompts the user to configure an OpenAI connection.
First asks the user for confirmation to proceed, then prompts for the name of the environment variable that holds the API key.
Returns
An OpenAIConnection instance containing the user-specified environment variable name, or None if the user declines the setup.
OpenAISetup.validate
validate(
config: OpenAIConnection,
) → NoneValidates the provided OpenAI connection configuration.
This method ensures that the specified environment variable is actually set and that its value matches the expected format of an OpenAI API key (starting with 'sk-' and meeting minimum length requirements).
Parameters
The OpenAI connection configuration to validate.
Raises
If the environment variable is not set or if the API key format is invalid.