From 8fcf8c93c0fbc0fe757a1e4e5cd664013c33c513 Mon Sep 17 00:00:00 2001 From: Sydney Runkle <54324534+sydney-runkle@users.noreply.github.com> Date: Mon, 17 Feb 2025 08:42:53 -0500 Subject: [PATCH] Add placeholder API key for OpenAI compatible models (#929) Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> --- pydantic_ai_slim/pydantic_ai/models/openai.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydantic_ai_slim/pydantic_ai/models/openai.py b/pydantic_ai_slim/pydantic_ai/models/openai.py index ff148199e..15dc93438 100644 --- a/pydantic_ai_slim/pydantic_ai/models/openai.py +++ b/pydantic_ai_slim/pydantic_ai/models/openai.py @@ -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`'