feat: Add clear error message when API key is missing

Improve user experience by providing specific guidance when no API key is
available, showing both provider data header and config options with
the correct field name for each provider.

Also adds comprehensive test coverage for API key resolution scenarios.
This commit is contained in:
Matthew Farrellee 2025-07-31 12:06:21 -05:00
parent 5c33bc1353
commit cef616732c
2 changed files with 118 additions and 0 deletions

View file

@ -254,6 +254,12 @@ class LiteLLMOpenAIMixin(
api_key = getattr(provider_data, key_field)
else:
api_key = self.api_key_from_config
if not api_key:
raise ValueError(
"API key is not set. Please provide a valid API key in the "
"provider data header, e.g. x-llamastack-provider-data: "
f'{{"{key_field}": "<API_KEY>"}}, or in the provider config.'
)
return api_key
async def embeddings(