Fix AI calls failing in Docker with empty OPENAI_BASE_URL
docker compose passes an empty .env line as OPENAI_BASE_URL="", and with base_url=None the openai SDK fell back to that empty value, so every call failed with "Connection error". Always pass the base URL explicitly. Also disable gunicorn's unused control socket, which logged a permission error because /app is read-only for the app user. Found while deploying to the homelab server. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
dfa4813a42
commit
015a0a5821
+6
-1
@@ -207,9 +207,14 @@ def _check_limits(user):
|
||||
ratelimit.hit(global_key, settings.AI_RATE_LIMIT_GLOBAL_PER_DAY, day)
|
||||
|
||||
|
||||
DEFAULT_BASE_URL = "https://api.openai.com/v1"
|
||||
|
||||
|
||||
def _client():
|
||||
# Always pass base_url explicitly: with base_url=None the SDK falls back to the OPENAI_BASE_URL
|
||||
# environment variable, which docker compose sets to "" when the .env line is left empty.
|
||||
return openai.OpenAI(api_key=settings.OPENAI_API_KEY, timeout=settings.OPENAI_TIMEOUT, max_retries=1,
|
||||
base_url=settings.OPENAI_BASE_URL or None)
|
||||
base_url=settings.OPENAI_BASE_URL or DEFAULT_BASE_URL)
|
||||
|
||||
|
||||
def _create_completion(messages):
|
||||
|
||||
Reference in New Issue
Block a user