Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/api/providers/fetchers/openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export async function getOpenRouterModels(options?: ApiHandlerOptions): Promise<
const baseURL = options?.openRouterBaseUrl || "https://openrouter.ai/api/v1"

try {
const response = await axios.get<OpenRouterModelsResponse>(`${baseURL}/models`)
const response = await axios.get<OpenRouterModelsResponse>(`${baseURL}/models`, { timeout: 10_000 })
const result = openRouterModelsResponseSchema.safeParse(response.data)
const data = result.success ? result.data.data : response.data.data

Expand Down Expand Up @@ -147,7 +147,9 @@ export async function getOpenRouterModelEndpoints(
const baseURL = options?.openRouterBaseUrl || "https://openrouter.ai/api/v1"

try {
const response = await axios.get<OpenRouterModelEndpointsResponse>(`${baseURL}/models/${modelId}/endpoints`)
const response = await axios.get<OpenRouterModelEndpointsResponse>(`${baseURL}/models/${modelId}/endpoints`, {
timeout: 10_000,
})
const result = openRouterModelEndpointsResponseSchema.safeParse(response.data)
const data = result.success ? result.data.data : response.data.data

Expand Down
2 changes: 1 addition & 1 deletion src/api/providers/fetchers/requesty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function getRequestyModels(baseUrl?: string, apiKey?: string): Prom
const resolvedBaseUrl = toRequestyServiceUrl(baseUrl)
const modelsUrl = new URL("v1/models", resolvedBaseUrl)

const response = await axios.get(modelsUrl.toString(), { headers })
const response = await axios.get(modelsUrl.toString(), { headers, timeout: 10_000 })
const rawModels = response.data.data

for (const rawModel of rawModels) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/providers/fetchers/unbound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function getUnboundModels(apiKey?: string | null): Promise<Record<s
headers["Authorization"] = `Bearer ${apiKey}`
}

const response = await axios.get("https://api.getunbound.ai/models", { headers })
const response = await axios.get("https://api.getunbound.ai/models", { headers, timeout: 10_000 })
const rawModels = response.data?.data ?? response.data

for (const rawModel of rawModels) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/providers/fetchers/vercel-ai-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function getVercelAiGatewayModels(options?: ApiHandlerOptions): Pro
const baseURL = "https://ai-gateway.vercel.sh/v1"

try {
const response = await axios.get<VercelAiGatewayModelsResponse>(`${baseURL}/models`)
const response = await axios.get<VercelAiGatewayModelsResponse>(`${baseURL}/models`, { timeout: 10_000 })
const result = vercelAiGatewayModelsResponseSchema.safeParse(response.data)
const data = result.success ? result.data.data : response.data.data

Expand Down
18 changes: 15 additions & 3 deletions src/core/webview/webviewMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,23 @@ export const webviewMessageHandler = async (
await flushModels(targetCandidate.options, true)
}

// Fetch models incrementally: send each provider's models to the webview
// as soon as they resolve, rather than waiting for all providers to finish.
// This ensures providers with working DNS are available immediately while
// blocked providers fail gracefully in the background (see #11747).
const results = await Promise.allSettled(
modelFetchPromises.map(async ({ key, options }) => {
const models = await safeGetModels(options)
return { key, models } // The key is `ProviderName` here.

// Send this provider's models to the webview immediately.
routerModels[key] = models
provider.postMessageToWebview({
type: "routerModels",
routerModels: { ...routerModels },
values: providerFilter ? { provider: requestedProvider } : undefined,
})

return { key, models }
}),
)

Expand All @@ -968,8 +981,6 @@ export const webviewMessageHandler = async (

if (result.status === "fulfilled") {
routerModels[routerName] = result.value.models

// Ollama and LM Studio settings pages still need these events. They are not fetched here.
} else {
// Handle rejection: Post a specific error message for this provider.
const errorMessage = result.reason instanceof Error ? result.reason.message : String(result.reason)
Expand All @@ -986,6 +997,7 @@ export const webviewMessageHandler = async (
}
})

// Send final aggregated message for backward compatibility.
provider.postMessageToWebview({
type: "routerModels",
routerModels,
Expand Down
Loading