Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

app: clarify cloud payment errors

Willie Tran8fe8737ea891
diff --git a/app/ui/app/src/components/Chat.tsx b/app/ui/app/src/components/Chat.tsx
index e0fcb4ff3..a61d0423c 100644
--- a/app/ui/app/src/components/Chat.tsx
+++ b/app/ui/app/src/components/Chat.tsx
@@ -1,7 +1,6 @@
import MessageList from "./MessageList";
import ChatForm from "./ChatForm";
import { FileUpload } from "./FileUpload";
-import { DisplayUpgrade } from "./DisplayUpgrade";
import { DisplayStale } from "./DisplayStale";
import { DisplayLogin } from "./DisplayLogin";
import {
@@ -26,7 +25,6 @@ import {
import { useQueryClient } from "@tanstack/react-query";
import { useNavigate } from "@tanstack/react-router";
import { useSelectedModel } from "@/hooks/useSelectedModel";
-import { useUser } from "@/hooks/useUser";
import { useHasVisionCapability } from "@/hooks/useModelCapabilities";
import { Message } from "@/gotypes";
@@ -36,7 +34,6 @@ export default function Chat({ chatId }: { chatId: string }) {
const chatQuery = useChat(chatId === "new" ? "" : chatId);
const chatErrorQuery = useChatError(chatId === "new" ? "" : chatId);
const { selectedModel } = useSelectedModel(chatId);
- const { user } = useUser();
const hasVisionCapability = useHasVisionCapability(selectedModel?.model);
const shouldShowStaleDisplay = useShouldShowStaleDisplay(selectedModel);
const dismissStaleModel = useDismissStaleModel();
@@ -259,19 +256,6 @@ export default function Chat({ chatId }: { chatId: string }) {
/>
</div>
)}
- {chatError && chatError.code === "usage_limit_upgrade" && (
- <div className="pb-2">
- <DisplayUpgrade
- error={chatError}
- onDismiss={clearChatError}
- href={
- user?.plan === "pro"
- ? "https://ollama.com/settings/billing"
- : "https://ollama.com/upgrade"
- }
- />
- </div>
- )}
{chatError && chatError.code === "cloud_unauthorized" && (
<div className="pb-2">
<DisplayLogin error={chatError} />
diff --git a/app/ui/app/src/components/DisplayUpgrade.tsx b/app/ui/app/src/components/DisplayUpgrade.tsx
deleted file mode 100644
index 4f500f355..000000000
--- a/app/ui/app/src/components/DisplayUpgrade.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-import type { ErrorEvent } from "@/gotypes";
-import { Display, type DisplayAction } from "@/components/ui/display";
-
-interface DisplayUpgradeProps {
- error: ErrorEvent | null;
- onDismiss: () => void;
- className?: string;
- message?: string;
- label?: string;
- href?: string;
-}
-
-export const DisplayUpgrade = ({
- error,
- onDismiss,
- className,
- message,
- label = "Upgrade",
- href = "https://ollama.com/upgrade",
-}: DisplayUpgradeProps) => {
- if (!error || error.code !== "usage_limit_upgrade") return null;
-
- const isUsageLimit = error.code === "usage_limit_upgrade";
-
- const action: DisplayAction | undefined = isUsageLimit
- ? {
- label,
- href,
- gradientColors: "from-cyan-500/20 via-purple-500/20 to-green-500/20",
- }
- : undefined;
-
- const variant = isUsageLimit ? "neutral" : "red";
-
- return (
- <Display
- message={message || error.error || "An error occurred"}
- variant={variant}
- onDismiss={onDismiss}
- action={action}
- className={className}
- />
- );
-};
diff --git a/app/ui/app/src/components/MessageList.tsx b/app/ui/app/src/components/MessageList.tsx
index 63c87b5d0..7e45c365a 100644
--- a/app/ui/app/src/components/MessageList.tsx
+++ b/app/ui/app/src/components/MessageList.tsx
@@ -107,9 +107,9 @@ export default function MessageList({
})}
{/* Inline error message */}
- {error &&
- error.code !== "usage_limit_upgrade" &&
- error.code !== "cloud_unauthorized" && <ErrorMessage error={error} />}
+ {error && error.code !== "cloud_unauthorized" && (
+ <ErrorMessage error={error} />
+ )}
{/* Indeterminate loading indicator */}
{showDots && (
diff --git a/app/ui/ui.go b/app/ui/ui.go
index a88c5fb2f..2ae6885d8 100644
--- a/app/ui/ui.go
+++ b/app/ui/ui.go
@@ -629,15 +629,17 @@ func (s *Server) getError(err error) responses.ErrorEvent {
}
}
- errStr := err.Error()
-
- switch {
- case strings.Contains(errStr, "402"):
+ var statusErr api.StatusError
+ if errors.As(err, &statusErr) && statusErr.StatusCode == http.StatusPaymentRequired && strings.HasPrefix(statusErr.ErrorMessage, "this model is not included in your free usage") {
return responses.ErrorEvent{
EventName: "error",
- Error: "You've reached your usage limit, please upgrade to continue",
- Code: "usage_limit_upgrade",
+ Error: "This model is not included in your free usage. Upgrade your plan: https://ollama.com/upgrade or add usage credits to pay as you go: https://ollama.com/settings",
}
+ }
+
+ errStr := err.Error()
+
+ switch {
case strings.HasPrefix(errStr, "pull model manifest") && isNetworkError(errStr):
return responses.ErrorEvent{
EventName: "error",
diff --git a/app/ui/ui_test.go b/app/ui/ui_test.go
index 29736f11b..259a9a28d 100644
--- a/app/ui/ui_test.go
+++ b/app/ui/ui_test.go
@@ -475,6 +475,94 @@ func TestAuthenticationMiddleware(t *testing.T) {
}
}
+func TestGetErrorServerResponse(t *testing.T) {
+ tests := []struct {
+ name string
+ status int
+ message string
+ wantError string
+ wantCode string
+ }{
+ {
+ name: "model not included in free usage",
+ status: http.StatusPaymentRequired,
+ message: "this model is not included in your free usage, add usage credits to pay as you go: https://ollama.com/settings or upgrade for included usage: https://ollama.com/upgrade",
+ wantError: "This model is not included in your free usage. Upgrade your plan: https://ollama.com/upgrade or add usage credits to pay as you go: https://ollama.com/settings",
+ },
+ {
+ name: "model not included in free usage with reference",
+ status: http.StatusPaymentRequired,
+ message: "this model is not included in your free usage, add usage credits to pay as you go: https://ollama.com/settings or upgrade for included usage: https://ollama.com/upgrade (ref: test-request)",
+ wantError: "This model is not included in your free usage. Upgrade your plan: https://ollama.com/upgrade or add usage credits to pay as you go: https://ollama.com/settings",
+ },
+ {
+ name: "free usage text in an unrelated error",
+ status: http.StatusBadRequest,
+ message: "this model is not included in your free usage",
+ },
+ {
+ name: "empty usage credit balance",
+ status: http.StatusPaymentRequired,
+ message: "this model uses usage credits only (not included plan usage) and your usage credit balance is empty, add usage credits or turn on auto reload at https://ollama.com/settings",
+ },
+ {
+ name: "credit auto reload payment failed",
+ status: http.StatusPaymentRequired,
+ message: "usage credits auto reload payment failed, update your payment method or add usage credits at https://ollama.com/settings",
+ },
+ {
+ name: "usage limit",
+ status: http.StatusTooManyRequests,
+ message: "you've reached your session usage limit, please wait or upgrade to continue",
+ },
+ {
+ name: "unrelated error containing 402",
+ status: http.StatusBadRequest,
+ message: "invalid request (ref: request-402)",
+ },
+ {
+ name: "sign in required",
+ status: http.StatusUnauthorized,
+ message: "unauthorized",
+ wantError: "Could not verify you are signed in. Please sign in and try again.",
+ wantCode: "cloud_unauthorized",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(tt.status)
+ json.NewEncoder(w).Encode(map[string]string{"error": tt.message})
+ }))
+ defer ts.Close()
+ t.Setenv("OLLAMA_HOST", ts.URL)
+
+ server := &Server{}
+ client := server.inferenceClient()
+ err := client.Chat(context.Background(), &api.ChatRequest{Model: "test"}, func(api.ChatResponse) error {
+ return nil
+ })
+ if err == nil {
+ t.Fatal("chat request succeeded, want an error")
+ }
+
+ want := responses.ErrorEvent{
+ EventName: "error",
+ Error: err.Error(),
+ Code: tt.wantCode,
+ }
+ if tt.wantError != "" {
+ want.Error = tt.wantError
+ }
+ if got := server.getError(err); got != want {
+ t.Errorf("getError() = %+v, want %+v", got, want)
+ }
+ })
+ }
+}
+
func TestUserAgent(t *testing.T) {
ua := userAgent()