Repository navigation
fix(providers): use environment API key when saved key is blank - #541
gezerui888 wants to merge 4 commits into
Conversation
|
@mbektas, could you review the environment-key fallback fix and approve the pending CI workflows? I'm happy to address any changes. |
|
@pjdoland could you review too? |
|
Will do tomorrow. |
|
Thanks for picking this up, @gezerui888, and for the tests that go through the real SDK. I ran them locally and the full suite passes. There's one case my proposal in #439 missed: an OpenAI-compatible endpoint that doesn't need a key at all (an internal gateway, or a local server such as Ollama or vLLM), with the saved key left blank and no I ran both models against main and this branch, pointed at a mocked endpoint:
One way to fix #439 without the regression is to fall back to the environment only when it actually has a key, and otherwise keep passing api_key = self.get_property("api_key").value
if not (api_key and api_key.strip()):
api_key = None if os.environ.get("OPENAI_API_KEY") else ""A test case with Two smaller things:
|
|
I corrected both request paths to preserve keyless requests with OpenAI 2.x while retaining environment-key fallback and explicit-key precedence. Saved null values keep the existing SDK behavior. I also made the key optional in Settings and documented the shared ACP variable and custom-endpoint behavior. The request matrix, full Python suite, Jest, typecheck, and lint pass. |
|
@gezerui888 can you check the failed tests |
|
I reproduced all 16 failures with OpenAI 3.54.0. The tests assumed every supported SDK accepted an empty key. I corrected the expectations and the admin guide. The 34 provider tests pass on both 2.20.0 and 3.54.0. The full Python suite, Jest, typecheck, and lint also pass locally. |
Closes #439
A blank saved API key prevents the OpenAI-compatible provider from using
OPENAI_API_KEY. I use the environment key when it is nonempty and preserve the installed SDK’s behavior when no key is available. Saved null values retain the SDK behavior, and explicit keys take precedence.I also mark the key optional in Settings and explain the shared environment variable and custom-endpoint behavior in the administrator guide.
The 34 provider tests pass with OpenAI 2.20.0 and 3.54.0, including request URLs, authorization and missing credentials. I also ran
pytest tests/ -q(2,533 passed),jlpm tsc --noEmit,jlpm lint:check, andjlpm jest --runInBand(955 passed).cc @mbektas