fix(api): enhance ClaudeModels response to align with api.anthropic.com

This commit is contained in:
Darley
2026-01-24 04:38:13 +03:30
parent 0d6ecb0191
commit 46c6fb1e7a
2 changed files with 18 additions and 3 deletions

View File

@@ -1033,10 +1033,10 @@ func (r *ModelRegistry) convertModelToMap(model *ModelInfo, handlerType string)
"owned_by": model.OwnedBy, "owned_by": model.OwnedBy,
} }
if model.Created > 0 { if model.Created > 0 {
result["created"] = model.Created result["created_at"] = model.Created
} }
if model.Type != "" { if model.Type != "" {
result["type"] = model.Type result["type"] = "model"
} }
if model.DisplayName != "" { if model.DisplayName != "" {
result["display_name"] = model.DisplayName result["display_name"] = model.DisplayName

View File

@@ -128,8 +128,23 @@ func (h *ClaudeCodeAPIHandler) ClaudeCountTokens(c *gin.Context) {
// Parameters: // Parameters:
// - c: The Gin context for the request. // - c: The Gin context for the request.
func (h *ClaudeCodeAPIHandler) ClaudeModels(c *gin.Context) { func (h *ClaudeCodeAPIHandler) ClaudeModels(c *gin.Context) {
models := h.Models()
firstID := ""
lastID := ""
if len(models) > 0 {
if id, ok := models[0]["id"].(string); ok {
firstID = id
}
if id, ok := models[len(models)-1]["id"].(string); ok {
lastID = id
}
}
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"data": h.Models(), "data": models,
"has_more": false,
"first_id": firstID,
"last_id": lastID,
}) })
} }