fix: skip OpenAI model registration when no API key is configured#1453
Open
pintaste wants to merge 1 commit into
Open
fix: skip OpenAI model registration when no API key is configured#1453pintaste wants to merge 1 commit into
pintaste wants to merge 1 commit into
Conversation
When no OpenAI API key is set (via keys.json or OPENAI_API_KEY env var), register_models and register_embedding_models now return early, keeping the model list clean for users who only use other providers. Fixes simonw#1445
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When no OpenAI API key is set,
llmstill registers ~50 OpenAI models (and several embedding models) at startup. This causes several issues:llm modelsoutput is cluttered with models the user cannot usegpt-4o-minicollide with identically-named models from other plugins (e.g. a LiteLLM proxy)llminvocations fail withNo key foundfor users who don't use OpenAI at allFix
Add a guard at the top of
register_modelsandregister_embedding_modelsin the built-in OpenAI plugin. If no key is available (neither inkeys.jsonnorOPENAI_API_KEYenv var), registration is skipped entirely.Users who later configure a key will see the models appear automatically on the next invocation.
Tests
test_openai_models_not_registered_without_key— verifies OpenAI Chat models are absent fromllm modelswhen no key is settest_openai_models_registered_with_key— verifies OpenAI Chat models appear when a key is presentconftest.pyto set a fakeOPENAI_API_KEYin the globalenv_setupfixture so existing tests that exercise OpenAI model features continue to passtest_cli_openai_models.pyfor explicitnessFixes #1445