validateParameters(modelId, params)
│
├─ For each parameter in model config:
│ │
│ ├─ Check if required and missing → ERROR
│ │
│ ├─ If present, validate by type:
│ │ │
│ │ ├─ NUMBER:
│ │ │ ├─ Is it a number?
│ │ │ ├─ Within min/max range?
│ │ │ └─ → Add to errors if invalid
│ │ │
│ │ ├─ SELECT:
│ │ │ ├─ Is it one of the allowed options?
│ │ │ ├─ OR is it a valid apiMapping key? ← NEW
│ │ │ └─ → Add to errors if invalid
│ │ │
│ │ ├─ STRING/TEXTAREA:
│ │ │ ├─ Within maxLength?
│ │ │ └─ → Add to errors if invalid
│ │ │
│ │ └─ BOOLEAN:
│ │ └─ Is it true/false?
│ │
│ └─ Continue to next parameter
│
└─ Return array of error messages (empty if valid)
Transformation Flow
transformParametersForAPI(modelId, params)
│
├─ Get model config
│
├─ For each parameter:
│ │
│ ├─ Is it a SELECT parameter?
│ │ │
│ │ ├─ Does it have apiMapping?
│ │ │ │
│ │ │ ├─ Is current value in mapping?
│ │ │ │ │
│ │ │ │ └─ YES: Replace value with mapped value
│ │ │ │ "medium" → "default" ✓
│ │ │ │
│ │ │ └─ NO: Keep original value
│ │ │
│ │ └─ No apiMapping: Keep original value
│ │
│ └─ Not a SELECT: Keep original value
│
├─ Apply model-specific transformParameters() if exists
│
└─ Return transformed parameters
Error Handling
Before (No Validation):
User selects "medium" reasoning
↓
Sent directly to API
↓
Groq API rejects: "must be 'none' or 'default'"
↓
Error shown to user 😞
After (With Validation & Transformation):
User selects "medium" reasoning
↓
Validated: "medium" is valid (in apiMapping) ✓
↓
Transformed: "medium" → "default"
↓
Sent to API with correct value
↓
API accepts request ✓
↓
User gets response 😊
Key Components
SelectParameter.apiMapping: Maps UI values to API values
validateParameters(): Validates before sending to API
transformParametersForAPI(): Transforms values using mappings