Skip to content

Commit 21387ca

Browse files
lesebclaude
andcommitted
fix: use direct Header params instead of Depends for SDK detection
The library client's _convert_body tries to construct Depends return types from body params, which fails for non-Pydantic types like SdkType enum. Use direct Header() parameters with None defaults instead - the library client simply skips these optional params and the route falls through to OpenAI default behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Sébastien Han <seb@redhat.com>
1 parent f2e52ba commit 21387ca

1 file changed

Lines changed: 8 additions & 19 deletions

File tree

src/llama_stack_api/models/fastapi_routes.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
from llama_stack_api.messages.models import ANTHROPIC_VERSION
2121
from llama_stack_api.router_utils import create_path_dependency, standard_responses
22-
from llama_stack_api.sdk_detection import SdkType
2322
from llama_stack_api.version import LLAMA_STACK_API_V1
2423

2524
from .api import Models
@@ -35,18 +34,6 @@
3534
get_model_request = create_path_dependency(GetModelRequest)
3635

3736

38-
def _detect_sdk_from_headers(
39-
anthropic_version: Annotated[str | None, Header(alias="anthropic-version")] = None,
40-
x_goog_api_key: Annotated[str | None, Header(alias="x-goog-api-key")] = None,
41-
) -> SdkType:
42-
"""Detect SDK type from request headers via FastAPI dependency injection."""
43-
if anthropic_version:
44-
return SdkType.ANTHROPIC
45-
if x_goog_api_key:
46-
return SdkType.GOOGLE
47-
return SdkType.OPENAI
48-
49-
5037
def create_router(impl: Models) -> APIRouter:
5138
"""Create a FastAPI router for the Models API.
5239
@@ -72,15 +59,16 @@ def create_router(impl: Models) -> APIRouter:
7259
},
7360
)
7461
async def list_models(
75-
sdk: Annotated[SdkType, Depends(_detect_sdk_from_headers)] = SdkType.OPENAI,
62+
anthropic_version: Annotated[str | None, Header(alias="anthropic-version")] = None,
63+
x_goog_api_key: Annotated[str | None, Header(alias="x-goog-api-key")] = None,
7664
) -> OpenAIListModelsResponse | Response:
77-
if sdk == SdkType.ANTHROPIC:
65+
if anthropic_version:
7866
anthropic_result = await impl.anthropic_list_models()
7967
return JSONResponse(
8068
content=anthropic_result.model_dump(exclude_none=True),
8169
headers={"anthropic-version": ANTHROPIC_VERSION},
8270
)
83-
elif sdk == SdkType.GOOGLE:
71+
elif x_goog_api_key:
8472
google_result = await impl.google_list_models()
8573
return JSONResponse(content=google_result.model_dump(exclude_none=True))
8674

@@ -97,11 +85,12 @@ async def list_models(
9785
)
9886
async def get_model(
9987
model_request: Annotated[GetModelRequest, Depends(get_model_request)],
100-
sdk: Annotated[SdkType, Depends(_detect_sdk_from_headers)] = SdkType.OPENAI,
88+
anthropic_version: Annotated[str | None, Header(alias="anthropic-version")] = None,
89+
x_goog_api_key: Annotated[str | None, Header(alias="x-goog-api-key")] = None,
10190
) -> Model | Response:
10291
model = await impl.get_model(model_request)
10392

104-
if sdk == SdkType.ANTHROPIC:
93+
if anthropic_version:
10594
anthropic_model = AnthropicModelInfo(
10695
id=model.identifier,
10796
display_name=model.identifier,
@@ -111,7 +100,7 @@ async def get_model(
111100
content=anthropic_model.model_dump(exclude_none=True),
112101
headers={"anthropic-version": ANTHROPIC_VERSION},
113102
)
114-
elif sdk == SdkType.GOOGLE:
103+
elif x_goog_api_key:
115104
google_model = GoogleModelInfo(
116105
name=f"models/{model.identifier}",
117106
display_name=model.identifier,

0 commit comments

Comments
 (0)