feat: validate model IDs before processing requests

Add model validation cache with 5-minute TTL to reject invalid model IDs
upfront instead of sending them to the API. This provides better error
messages and avoids unnecessary API calls.

- Add MODEL_VALIDATION_CACHE_TTL_MS constant (5 min)
- Add isValidModel() with lazy cache population
- Warm cache when listModels() is called
- Validate model ID in /v1/messages before processing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Badri Narayanan S
2026-02-01 19:07:23 +05:30
parent 2ab0c7943d
commit 90b38bbb56
4 changed files with 102 additions and 5 deletions

View File

@@ -156,6 +156,9 @@ export const GEMINI_SKIP_SIGNATURE = 'skip_thought_signature_validator';
// Cache TTL for Gemini thoughtSignatures (2 hours)
export const GEMINI_SIGNATURE_CACHE_TTL_MS = 2 * 60 * 60 * 1000;
// Cache TTL for model validation (5 minutes)
export const MODEL_VALIDATION_CACHE_TTL_MS = 5 * 60 * 1000;
/**
* Get the model family from model name (dynamic detection, no hardcoded list).
* @param {string} modelName - The model name from the request
@@ -295,6 +298,7 @@ export default {
GEMINI_MAX_OUTPUT_TOKENS,
GEMINI_SKIP_SIGNATURE,
GEMINI_SIGNATURE_CACHE_TTL_MS,
MODEL_VALIDATION_CACHE_TTL_MS,
getModelFamily,
isThinkingModel,
OAUTH_CONFIG,