@fudrouter/fsrouter 0.6.114 → 0.6.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -112,7 +112,7 @@ export async function POST_handler(req, res) {
|
|
|
112
112
|
normalizedBase = normalizedBase.slice(0, -9);
|
|
113
113
|
}
|
|
114
114
|
const modelsUrl = `${normalizedBase}/models`;
|
|
115
|
-
const
|
|
115
|
+
const probeRes = await fetchWithTimeout(modelsUrl, {
|
|
116
116
|
method: "GET",
|
|
117
117
|
headers: {
|
|
118
118
|
"x-api-key": apiKey,
|
|
@@ -120,11 +120,11 @@ export async function POST_handler(req, res) {
|
|
|
120
120
|
"Authorization": `Bearer ${apiKey}`
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
|
-
if (
|
|
124
|
-
return
|
|
123
|
+
if (probeRes.ok)
|
|
124
|
+
return probeRes.json({ valid: true });
|
|
125
125
|
// Auth errors - no point trying chat fallback
|
|
126
|
-
if (
|
|
127
|
-
return
|
|
126
|
+
if (probeRes.status === 401 || probeRes.status === 403) {
|
|
127
|
+
return probeRes.json({ valid: false, error: "API key unauthorized" });
|
|
128
128
|
}
|
|
129
129
|
// Fallback: try chat/completions if modelId provided
|
|
130
130
|
if (modelId) {
|
|
@@ -143,26 +143,26 @@ export async function POST_handler(req, res) {
|
|
|
143
143
|
})
|
|
144
144
|
});
|
|
145
145
|
if (chatRes.ok) {
|
|
146
|
-
return
|
|
146
|
+
return probeRes.json({ valid: true, method: "chat" });
|
|
147
147
|
}
|
|
148
|
-
return
|
|
148
|
+
return probeRes.json({
|
|
149
149
|
valid: false,
|
|
150
150
|
error: getChatErrorMessage(chatRes.status),
|
|
151
151
|
method: "chat"
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
|
-
return
|
|
154
|
+
return probeRes.json({ valid: false, error: getModelsErrorMessage(probeRes.status) });
|
|
155
155
|
}
|
|
156
156
|
// OpenAI Compatible Validation (Default)
|
|
157
157
|
const modelsUrl = `${baseUrl.replace(/\/$/, "")}/models`;
|
|
158
|
-
const
|
|
158
|
+
const probeRes = await fetchWithTimeout(modelsUrl, {
|
|
159
159
|
headers: { "Authorization": `Bearer ${apiKey}` },
|
|
160
160
|
});
|
|
161
|
-
if (
|
|
162
|
-
return
|
|
161
|
+
if (probeRes.ok)
|
|
162
|
+
return probeRes.json({ valid: true });
|
|
163
163
|
// Auth errors - no point trying chat fallback
|
|
164
|
-
if (
|
|
165
|
-
return
|
|
164
|
+
if (probeRes.status === 401 || probeRes.status === 403) {
|
|
165
|
+
return probeRes.json({ valid: false, error: "API key unauthorized" });
|
|
166
166
|
}
|
|
167
167
|
// Fallback: try chat/completions if modelId provided
|
|
168
168
|
if (modelId) {
|
|
@@ -179,7 +179,7 @@ export async function POST_handler(req, res) {
|
|
|
179
179
|
})
|
|
180
180
|
});
|
|
181
181
|
if (chatRes.ok) {
|
|
182
|
-
return
|
|
182
|
+
return probeRes.json({ valid: true, method: "chat" });
|
|
183
183
|
}
|
|
184
184
|
return res.json({
|
|
185
185
|
valid: false,
|