diff --git a/internal/gateway/chat.go b/internal/gateway/chat.go index 2e3af12..5a70914 100644 --- a/internal/gateway/chat.go +++ b/internal/gateway/chat.go @@ -452,6 +452,19 @@ func (g *Gateway) handleChat(w http.ResponseWriter, r *http.Request) { return } } + // A key whose model scope does not include AUTO cannot use AUTO at all, + // even when it has its own AUTO chain configured. That combination is + // easy to set up by accident and produced a misleading error: the request + // fell through to the generic "model %q is not configured" below, which + // claims AUTO does not exist — it does, this key just may not use it. Name + // the actual reason so the admin can fix the scope. + if isAuto(model) { + if allow := g.allowedModels(r.Context()); allow != nil && !g.hasScopeModel(allow, model) { + writeError(w, http.StatusForbidden, "model_not_allowed", + fmt.Sprintf("model %q is not in this key's model scope, so it cannot use AUTO; add %q to the key's models or remove the scope restriction", model, model)) + return + } + } cands, effective := g.resolveCands(r.Context(), &req) if len(cands) == 0 { writeError(w, http.StatusNotFound, "model_not_found", fmt.Sprintf("model %q is not configured", model)) diff --git a/internal/gateway/ui/index.html b/internal/gateway/ui/index.html index 42328f1..f35a998 100644 --- a/internal/gateway/ui/index.html +++ b/internal/gateway/ui/index.html @@ -517,7 +517,20 @@ #toast{left:12px;right:12px;bottom:12px;text-align:center} th,td{padding:8px 10px} } - + + /* Shown when a key's model scope blocks AUTO: the chain editor can look + fine while every request 403s, so the conflict must be visible here. */ + .warn-box { + margin: 0 0 10px; + padding: 8px 10px; + border-radius: 8px; + border: 1px solid rgba(224, 108, 51, 0.45); + background: rgba(224, 108, 51, 0.1); + color: #b45309; + font-size: 12.5px; + line-height: 1.5; + } +