From def0cb5a2a4dce3fa957be9946390dee733467d0 Mon Sep 17 00:00:00 2001 From: Mrx Date: Thu, 17 Sep 2026 01:44:07 +0530 Subject: [PATCH] Add GET /v1/models to the llm_local mock Nothing in llm_local answered the OpenAI-compatible /v1/models liveness probe, so pointing a preflight/health-check-aware client at it reported a working sandbox as down before any chat request was sent. llm_remote already exposes this route, so the two sandboxes disagreed on the same probe. Proxies straight to the Ollama backend's model list rather than hardcoding a name, so it stays correct regardless of which model is configured. Reuses the same verify_api_key dependency as chat completions. Fixes #82 --- sandboxes/llm_local/app/mocks/openai.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sandboxes/llm_local/app/mocks/openai.py b/sandboxes/llm_local/app/mocks/openai.py index 9d834c1..b2e7ce8 100644 --- a/sandboxes/llm_local/app/mocks/openai.py +++ b/sandboxes/llm_local/app/mocks/openai.py @@ -70,6 +70,26 @@ class ChatCompletionRequest(BaseModel): ) +@router.get("/v1/models") +def list_models(token: str = Depends(verify_api_key)) -> Any: + """OpenAI-compatible models list endpoint, proxied from the Ollama backend. + + Many OpenAI-compatible clients use GET /v1/models as a preflight liveness + check before sending any chat request. Without this route, such a check + fails and reports a working sandbox as unreachable. + + Returns: + Any: OpenAI-compatible model list response from Ollama. + + Raises: + HTTPException: If the Ollama backend returns an error (status 500). + """ + try: + return client.models.list() + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + + @router.post("/v1/chat/completions") def chat_completions( request: ChatCompletionRequest, token: str = Depends(verify_api_key)