feat(ai): add OpenRouter provider order and fallback controls

This commit is contained in:
dwindown
2026-04-30 15:29:54 +07:00
parent 12d2d9458f
commit 4600cfe493
2 changed files with 25 additions and 1 deletions

View File

@@ -325,7 +325,7 @@ async def call_openrouter_api(
"X-Title": "IRT Bank Soal",
}
payload = {
payload: dict[str, Any] = {
"model": model,
"messages": [
{
@@ -336,6 +336,14 @@ async def call_openrouter_api(
"max_tokens": 2000,
"temperature": 0.7,
}
provider_order = [
provider for provider in settings.OPENROUTER_PROVIDER_ORDER if provider.strip()
]
if provider_order:
payload["provider"] = {
"order": provider_order,
"allow_fallbacks": settings.OPENROUTER_ALLOW_PROVIDER_FALLBACKS,
}
timeout = httpx.Timeout(settings.OPENROUTER_TIMEOUT)