""" GET /auth/status — returns connectivity status for configured model backends. """ import logging from fastapi import APIRouter logger = logging.getLogger(__name__) router = APIRouter(prefix="/auth") async def _local_status(username: str = "scott") -> dict: """Check reachability of the user's configured local model host.""" import model_registry cfg = model_registry.get_best_local_model(username) if not cfg: return {"configured": False} api_url = cfg.get("api_url", "") if not api_url: return {"configured": False} try: import httpx url = api_url.rstrip("/") + "/api/models" headers = {} api_key = cfg.get("api_key", "") if api_key: headers["Authorization"] = f"Bearer {api_key}" async with httpx.AsyncClient(timeout=5) as client: resp = await client.get(url, headers=headers) reachable = resp.status_code < 400 return { "configured": True, "reachable": reachable, "model": cfg.get("model_name", ""), "label": cfg.get("label", ""), } except Exception as e: return {"configured": True, "reachable": False, "error": str(e), "model": cfg.get("model_name", "")} @router.get("/status") async def auth_status() -> dict: return { "local": await _local_status(), }