Merge pull request #90 from tiagonrodrigues/fix/fallback-on-5xx-errors

feat: fallback to alternate model when max retries exceeded with 5xx errors
This commit is contained in:
Badri Narayanan S
2026-01-10 20:23:42 +05:30
committed by GitHub
2 changed files with 21 additions and 0 deletions

View File

@@ -218,5 +218,15 @@ export async function sendMessage(anthropicRequest, accountManager, fallbackEnab
}
}
// All retries exhausted - try fallback model if enabled
if (fallbackEnabled) {
const fallbackModel = getFallbackModel(model);
if (fallbackModel) {
logger.warn(`[CloudCode] All retries exhausted for ${model}. Attempting fallback to ${fallbackModel}`);
const fallbackRequest = { ...anthropicRequest, model: fallbackModel };
return await sendMessage(fallbackRequest, accountManager, false); // Disable fallback for recursive call
}
}
throw new Error('Max retries exceeded');
}

View File

@@ -285,6 +285,17 @@ export async function* sendMessageStream(anthropicRequest, accountManager, fallb
}
}
// All retries exhausted - try fallback model if enabled
if (fallbackEnabled) {
const fallbackModel = getFallbackModel(model);
if (fallbackModel) {
logger.warn(`[CloudCode] All retries exhausted for ${model}. Attempting fallback to ${fallbackModel} (streaming)`);
const fallbackRequest = { ...anthropicRequest, model: fallbackModel };
yield* sendMessageStream(fallbackRequest, accountManager, false); // Disable fallback for recursive call
return;
}
}
throw new Error('Max retries exceeded');
}