add support for custom AI api base url and Agent Router integrations

This commit is contained in:
rarebuffalo
2026-06-15 01:30:24 +05:30
parent eb657ac30a
commit 6f83412d6f
7 changed files with 92 additions and 2 deletions

View File

@@ -55,6 +55,9 @@ class Settings(BaseSettings):
# Leave blank for Ollama (local, no key needed).
ai_api_key: str | None = None
# AI_API_BASE: Custom API base URL (e.g. for Agent Router or custom OpenAI-compatible proxies)
ai_api_base: str | None = None
# -------------------------------------------------------------------------
# Legacy Gemini key — kept for backward compatibility.
# If AI_API_KEY is not set but GEMINI_API_KEY is, we use that automatically.

View File

@@ -74,6 +74,9 @@ async def call_ai(
"api_key": api_key,
}
if settings.ai_api_base:
kwargs["api_base"] = settings.ai_api_base
# JSON mode: supported natively by OpenAI and LiteLLM proxied Gemini.
# For providers that don't support it, LiteLLM silently ignores the flag.
if json_mode: