Skip to content

fix: Update OpenAIProvider to use environment variable for base URL #1117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pydantic_ai_slim/pydantic_ai/providers/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(
client to use. If provided, `base_url`, `api_key`, and `http_client` must be `None`.
http_client: An existing `httpx.AsyncClient` to use for making HTTP requests.
"""
self._base_url = base_url or 'https://api.openai.com/v1'
self._base_url = base_url or os.getenv('OPENAI_BASE_URL', 'https://api.openai.com/v1')
# 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, but a placeholder (non-empty) key is required.
if api_key is None and 'OPENAI_API_KEY' not in os.environ and openai_client is None:
Expand Down