Skip to content
Closed
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
8 changes: 6 additions & 2 deletions codewiki/src/be/llm_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from openai.types import chat

from pydantic_ai.exceptions import ModelHTTPError
from pydantic_ai.exceptions import ModelHTTPError, UnexpectedModelBehavior
from pydantic_ai.models.openai import OpenAIChatModel, OpenAIChatModelSettings
from pydantic_ai.models.fallback import FallbackModel
from pydantic_ai.providers.openai import OpenAIProvider
Expand Down Expand Up @@ -254,7 +254,11 @@ def create_fallback_models(config: Config) -> FallbackModel:
"""Create fallback models chain from configuration."""
main = create_main_model(config)
fallback = create_fallback_model(config)
return FallbackModel(main, fallback)
# Default fallback_on=(ModelHTTPError,) does NOT cover UnexpectedModelBehavior, which
# is what pydantic-ai raises for a 200 response with a malformed/empty body (seen once
# against OpenRouter: choices/model/object all None). Without this, that failure mode
# skips the fallback model entirely and kills the module outright.
return FallbackModel(main, fallback, fallback_on=(ModelHTTPError, UnexpectedModelBehavior))


def create_openai_client(config: Config) -> OpenAI:
Expand Down
Loading