Spaces:
Running
Running
Clearer OpenRouter errors: a spending-limit 403 no longer says the key is wrong
Browse files
engine.js
CHANGED
|
@@ -106,9 +106,12 @@ const Lite = {
|
|
| 106 |
} catch (e) {
|
| 107 |
return '<div class="keystat meh">⚠️ Could not reach OpenRouter to check the key. Try a run anyway.</div>';
|
| 108 |
}
|
| 109 |
-
if (r.status === 401
|
| 110 |
return '<div class="keystat bad">❌ OpenRouter did not accept this key. It may be mistyped, deleted, or expired. Make a new one at openrouter.ai, under Keys.</div>';
|
| 111 |
}
|
|
|
|
|
|
|
|
|
|
| 112 |
if (!r.ok) return `<div class="keystat meh">⚠️ Could not check the key right now (OpenRouter said ${r.status}). Try a run anyway.</div>`;
|
| 113 |
const d = ((await r.json()) || {}).data || {};
|
| 114 |
const parts = ["✅ <b>Key works.</b>"];
|
|
@@ -129,12 +132,17 @@ const Lite = {
|
|
| 129 |
},
|
| 130 |
|
| 131 |
friendly(status, data) {
|
| 132 |
-
const m = (data && data.error && (data.error.message || data.error)) || "";
|
| 133 |
if (status === 429) return "This free model is busy, or you hit the free limit (about 20 requests a minute). Wait a minute, or pick another model at the top.";
|
| 134 |
-
if (status === 401
|
| 135 |
-
if (status === 402) return "This key has no credit for that model.
|
| 136 |
-
if (status ===
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
},
|
| 139 |
|
| 140 |
/* One model call, retried once on a free-tier rate limit. Returns {message, usage, secs, model, where}. */
|
|
|
|
| 106 |
} catch (e) {
|
| 107 |
return '<div class="keystat meh">⚠️ Could not reach OpenRouter to check the key. Try a run anyway.</div>';
|
| 108 |
}
|
| 109 |
+
if (r.status === 401) {
|
| 110 |
return '<div class="keystat bad">❌ OpenRouter did not accept this key. It may be mistyped, deleted, or expired. Make a new one at openrouter.ai, under Keys.</div>';
|
| 111 |
}
|
| 112 |
+
if (r.status === 403) {
|
| 113 |
+
return '<div class="keystat meh">⚠️ OpenRouter refused to check this key (403). That usually means a spending limit or budget was reached, not a bad key. Try a free model (its name ends in :free).</div>';
|
| 114 |
+
}
|
| 115 |
if (!r.ok) return `<div class="keystat meh">⚠️ Could not check the key right now (OpenRouter said ${r.status}). Try a run anyway.</div>`;
|
| 116 |
const d = ((await r.json()) || {}).data || {};
|
| 117 |
const parts = ["✅ <b>Key works.</b>"];
|
|
|
|
| 132 |
},
|
| 133 |
|
| 134 |
friendly(status, data) {
|
| 135 |
+
const m = String((data && data.error && (data.error.message || data.error)) || "").replace(/\s+/g, " ").trim();
|
| 136 |
if (status === 429) return "This free model is busy, or you hit the free limit (about 20 requests a minute). Wait a minute, or pick another model at the top.";
|
| 137 |
+
if (status === 401) return "The key was not accepted. Check that you pasted the whole OpenRouter key.";
|
| 138 |
+
if (status === 402) return "This key has no credit left for that model. Add credit at openrouter.ai, or pick a free model (its name ends in :free).";
|
| 139 |
+
if (status === 403) {
|
| 140 |
+
if (/budget|limit|spend|credit/i.test(m)) return `Your key is fine, but it has reached a spending limit, so OpenRouter refused this paid model. Pick a free model (its name ends in :free), or raise the limit at openrouter.ai under Settings. OpenRouter said: ${m.slice(0, 160)}`;
|
| 141 |
+
if (/moderat|flag/i.test(m)) return `OpenRouter's safety filter blocked this request. OpenRouter said: ${m.slice(0, 160)}`;
|
| 142 |
+
return `OpenRouter refused this request (403). Your key may still be fine: try a free model (its name ends in :free). OpenRouter said: ${m.slice(0, 160)}`;
|
| 143 |
+
}
|
| 144 |
+
if (status === 404) return /tool/i.test(m) ? "That model cannot use tools right now. Pick another one at the top." : "That model is not available right now. Pick another one at the top.";
|
| 145 |
+
return `The model service returned an error (${status}): ${m.slice(0, 200)}`;
|
| 146 |
},
|
| 147 |
|
| 148 |
/* One model call, retried once on a free-tier rate limit. Returns {message, usage, secs, model, where}. */
|