mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 06:41:22 +00:00
fix: include provider and model name in billing error message (#20510)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 40dbdf62e8
Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
@@ -4,10 +4,13 @@ import { formatSandboxToolPolicyBlockedMessage } from "../sandbox.js";
|
||||
import { stableStringify } from "../stable-stringify.js";
|
||||
import type { FailoverReason } from "./types.js";
|
||||
|
||||
export function formatBillingErrorMessage(provider?: string): string {
|
||||
export function formatBillingErrorMessage(provider?: string, model?: string): string {
|
||||
const providerName = provider?.trim();
|
||||
if (providerName) {
|
||||
return `⚠️ ${providerName} returned a billing error — your API key has run out of credits or has an insufficient balance. Check your ${providerName} billing dashboard and top up or switch to a different API key.`;
|
||||
const modelName = model?.trim();
|
||||
const providerLabel =
|
||||
providerName && modelName ? `${providerName} (${modelName})` : providerName || undefined;
|
||||
if (providerLabel) {
|
||||
return `⚠️ ${providerLabel} returned a billing error — your API key has run out of credits or has an insufficient balance. Check your ${providerName} billing dashboard and top up or switch to a different API key.`;
|
||||
}
|
||||
return "⚠️ API provider returned a billing error — your API key has run out of credits or has an insufficient balance. Check your provider's billing dashboard and top up or switch to a different API key.";
|
||||
}
|
||||
@@ -420,7 +423,7 @@ export function formatRawAssistantErrorForUi(raw?: string): string {
|
||||
|
||||
export function formatAssistantErrorText(
|
||||
msg: AssistantMessage,
|
||||
opts?: { cfg?: OpenClawConfig; sessionKey?: string; provider?: string },
|
||||
opts?: { cfg?: OpenClawConfig; sessionKey?: string; provider?: string; model?: string },
|
||||
): string | undefined {
|
||||
// Also format errors if errorMessage is present, even if stopReason isn't "error"
|
||||
const raw = (msg.errorMessage ?? "").trim();
|
||||
@@ -487,7 +490,7 @@ export function formatAssistantErrorText(
|
||||
}
|
||||
|
||||
if (isBillingErrorMessage(raw)) {
|
||||
return formatBillingErrorMessage(opts?.provider);
|
||||
return formatBillingErrorMessage(opts?.provider, opts?.model ?? msg.model);
|
||||
}
|
||||
|
||||
if (isLikelyHttpErrorText(raw) || isRawApiErrorPayload(raw)) {
|
||||
|
||||
Reference in New Issue
Block a user