From 03d2b1c93df48dd4cc12a717d9b549495a93cbbf Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Fri, 24 Oct 2025 13:00:31 +0200 Subject: [PATCH] Adds robust model list response validation Improves models API response handling by adding structural validation Ensures that the API response contains an array of model data before processing Prevents potential runtime errors from unexpected response formats --- api/anthropicClient.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/anthropicClient.ts b/api/anthropicClient.ts index 4abb333..36dcd22 100644 --- a/api/anthropicClient.ts +++ b/api/anthropicClient.ts @@ -79,7 +79,13 @@ export class AnthropicClient { throw new Error(`Models API request failed: ${response.status}\n${response.text}`); } - return response.json as ModelsListResponse; + // Validate basic response structure + const data = response.json as any; + if (!data || !Array.isArray(data.data)) { + throw new Error('Invalid models API response structure'); + } + + return data as ModelsListResponse; } catch (error) { if (error instanceof Error) { throw error;