Skip to content

Commit

Permalink
Add placeholder API key for OpenAI compatible models (#929)
Browse files Browse the repository at this point in the history
Co-authored-by: David Montague <[email protected]>
  • Loading branch information
sydney-runkle and dmontagu authored Feb 17, 2025
1 parent df68932 commit 8fcf8c9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pydantic_ai_slim/pydantic_ai/models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ def __init__(
"""
self._model_name = model_name
# This is a workaround for the OpenAI client requiring an API key, whilst locally served,
# openai compatible models do not always need an API key.
# openai compatible models do not always need an API key, but a placeholder (non-empty) key is required.
if api_key is None and 'OPENAI_API_KEY' not in os.environ and base_url is not None and openai_client is None:
api_key = ''
api_key = 'api-key-not-set'

if openai_client is not None:
assert http_client is None, 'Cannot provide both `openai_client` and `http_client`'
Expand Down

0 comments on commit 8fcf8c9

Please sign in to comment.