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:
Adriano Dal Pastro
2026-05-25 21:07:12 +00:00
parent e54f828722
commit df068bc0f8
3 changed files with 35 additions and 1 deletions
+16 -1
View File
@@ -1,8 +1,9 @@
from fastapi import APIRouter, Depends from fastapi import APIRouter, Depends
from src.backend.api.dependencies import verify_api_key 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.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 from src.backend.services.worker_client import WorkerClient
router = APIRouter(dependencies=[Depends(verify_api_key)]) router = APIRouter(dependencies=[Depends(verify_api_key)])
@@ -26,3 +27,17 @@ async def health():
"database": db_ok, "database": db_ok,
"worker": worker_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"],
})
+5
View File
@@ -38,6 +38,11 @@ class WorkerClient:
) )
return resp.json() 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: async def health(self) -> bool:
try: try:
async with httpx.AsyncClient(timeout=5.0) as client: async with httpx.AsyncClient(timeout=5.0) as client:
+14
View File
@@ -11,6 +11,20 @@ app.get("/health", (_req, res) => {
res.json({ status: "ok" }); res.json({ status: "ok" });
}); });
app.get("/models", async (_req, res) => {
try {
const conv = query({
prompt: ".",
options: { model: "claude-sonnet-4-6", allowedTools: [] },
});
const models = await conv.supportedModels();
await conv.return();
res.json({ success: true, models });
} catch (error) {
res.json({ success: false, error: error.message });
}
});
app.post("/process", async (req, res) => { app.post("/process", async (req, res) => {
const { prompt, system_prompt, model, session_id } = req.body; const { prompt, system_prompt, model, session_id } = req.body;