feat: allow an empty API key for unauthenticated endpoints

The OpenAI SDK rejects api_key=None, so all three client sites now
fall back to a PLACEHOLDER_API_KEY ("not-required") when the entry has
no key, letting an unauthenticated LiteLLM/proxy endpoint be configured
with the API key field left blank.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01739Seac5eMAfNwFeiwV5r4
This commit is contained in:
Adam SmithandClaude Sonnet 5 committed 2026-09-17 17:54:03 -04:00
1 parent 914c89dc6b
commit df44abf158
4 files changed
+26 -4

No files matched your search

+19
View File
@@ -25,3 +25,22 @@ async def test_client_built_with_base_url(hass: HomeAssistant) -> None:
await hass.async_block_till_done()
assert mock_client.call_args.kwargs["base_url"] == "http://192.0.2.10:4000/v1"
async def test_api_key_optional(hass: HomeAssistant) -> None:
"""An endpoint needing no auth should still set up."""
entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_BASE_URL: "http://192.0.2.10:4000/v1"},
)
entry.add_to_hass(hass)
with patch(
"custom_components.openai_compatible.openai.AsyncOpenAI"
) as mock_client:
mock_client.return_value.platform_headers = lambda: {}
mock_client.return_value.with_options.return_value.models.list = AsyncMock()
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert mock_client.call_args.kwargs["api_key"] == "not-required"