feat: add GET /api/models endpoint
Returns available Claude models from SDK and the configured default model. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from src.backend.api.dependencies import verify_api_key
|
||||
from src.backend.config import settings
|
||||
from src.backend.db.database import get_db
|
||||
from src.backend.models.api import ok
|
||||
from src.backend.models.api import ok, fail
|
||||
from src.backend.services.worker_client import WorkerClient
|
||||
|
||||
router = APIRouter(dependencies=[Depends(verify_api_key)])
|
||||
@@ -26,3 +27,17 @@ async def health():
|
||||
"database": db_ok,
|
||||
"worker": worker_ok,
|
||||
})
|
||||
|
||||
|
||||
@router.get("/models", summary="List available models", tags=["system"])
|
||||
async def list_models():
|
||||
worker = WorkerClient()
|
||||
result = await worker.models()
|
||||
|
||||
if not result.get("success"):
|
||||
return fail("WORKER_ERROR", result.get("error", "Failed to fetch models"))
|
||||
|
||||
return ok({
|
||||
"default_model": settings.claude_model,
|
||||
"models": result["models"],
|
||||
})
|
||||
|
||||
@@ -38,6 +38,11 @@ class WorkerClient:
|
||||
)
|
||||
return resp.json()
|
||||
|
||||
async def models(self) -> dict:
|
||||
async with httpx.AsyncClient(timeout=30.0) as client:
|
||||
resp = await client.get(f"{self.base_url}/models")
|
||||
return resp.json()
|
||||
|
||||
async def health(self) -> bool:
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=5.0) as client:
|
||||
|
||||
Reference in New Issue
Block a user