• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
yawnxyz

yawnxyz

chat

Public
Like
chat
Home
Code
7
backend
5
chat
1
chatter
frontend
3
public
deno.json
main.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
/
x
/
yawnxyz
/
chat
/
branch
/
main
/
version
/
119
/
code
/
backend
/
providers
/
PARAMETER-VALIDATION.md
/
backend
/
providers
/
PARAMETER-VALIDATION.md
Code
/
/
x
/
yawnxyz
/
chat
/
branch
/
main
/
version
/
119
/
code
/
backend
/
providers
/
PARAMETER-VALIDATION.md
/
backend
/
providers
/
PARAMETER-VALIDATION.md
Search
…
Viewing readonly version of main branch: v119
View latest version
PARAMETER-VALIDATION.md

Parameter Validation & Transformation System

This system handles the "whack-a-mole" problem where different AI models/providers require different parameter formats.

Problem

Different models have different requirements:

  • Qwen3-32B: reasoning_effort must be 'none' or 'default'
  • OpenAI o1/o3: reasoning_effort can be 'low', 'medium', 'high'
  • Anthropic: Uses extended_thinking budget tokens instead
  • Some models: Don't support certain parameters at all

Solution

1. Parameter Mapping (apiMapping)

In model-configs.ts, SelectParameters can define an apiMapping to translate UI values to API values:

{ key: 'reasoningEffort', label: 'Reasoning Effort', type: 'select', options: [ { value: 'none', label: 'None' }, { value: 'default', label: 'Default' } ], default: 'default', apiMapping: { 'none': 'none', 'default': 'default', // Backwards compatibility 'low': 'none', 'medium': 'default', 'high': 'default' } }

2. Parameter Transformation

The transformParametersForAPI() function automatically applies these mappings:

import { transformParametersForAPI } from "./model-configs.ts"; // Transform before sending to API const transformedParams = transformParametersForAPI(model, { reasoningEffort: 'medium', // UI value webSearch: true, }); // Result: { reasoningEffort: 'default', webSearch: true }

3. Parameter Validation

The validateParameters() function checks if parameters are valid:

import { validateParameters } from "./model-configs.ts"; const errors = validateParameters(modelId, params); if (errors.length > 0) { console.error("Validation errors:", errors); }

Usage in Providers

Groq Provider Example

// In complete() or stream() method: const transformedParams = transformParametersForAPI(model, { reasoningEffort: options?.reasoningEffort, imageDetail: options?.imageDetail, webSearch: options?.webSearch, codeExecution: options?.codeExecution, }); // Only add parameters if model supports them AND they're defined if (transformedParams.reasoningEffort && modelSupportsParameter(model, 'reasoningEffort')) { requestBody.reasoning_effort = transformedParams.reasoningEffort; }

Adding New Models with Custom Parameters

Example: Model with different parameter format

{ id: 'custom-model', name: 'Custom Model', provider: 'custom', parameters: [ { key: 'thinkingLevel', label: 'Thinking Level', type: 'select', options: [ { value: 'fast', label: 'Fast' }, { value: 'balanced', label: 'Balanced' }, { value: 'deep', label: 'Deep' } ], default: 'balanced', // Map to what the API actually expects apiMapping: { 'fast': '1', 'balanced': '2', 'deep': '3' } } ], // Optional: Custom transformation logic transformParameters: (params) => { const transformed = { ...params }; // Custom logic here if (params.special_feature) { transformed.enable_experimental = true; } return transformed; } }

Benefits

  1. Single Source of Truth: Model configs define both UI and API requirements
  2. Backwards Compatibility: Old parameter values can be mapped to new ones
  3. Type Safety: TypeScript ensures parameters are validated at compile time
  4. Easy Debugging: Clear error messages when parameters don't match
  5. Extensible: Add new parameter types and transformations easily

Testing

To test parameter validation:

import { validateParameters, transformParametersForAPI } from "./model-configs.ts"; // Test validation const errors = validateParameters('qwen/qwen3-32b', { reasoningEffort: 'medium', // Valid (will be mapped) temperature: 0.7, }); console.log("Validation errors:", errors); // Should be empty // Test transformation const transformed = transformParametersForAPI('qwen/qwen3-32b', { reasoningEffort: 'medium', }); console.log("Transformed:", transformed); // { reasoningEffort: 'default' }

Migration Guide

For Existing Models

  1. Check your model's API documentation
  2. Find any parameters with specific value requirements
  3. Add apiMapping to those parameters in model-configs.ts
  4. Update provider to use transformParametersForAPI()

For New Providers

  1. Define parameter configs in model-configs.ts
  2. Use transformParametersForAPI() before building request body
  3. Use modelSupportsParameter() to check if parameter is supported
  4. Optionally add validation before making API calls

Common Patterns

Pattern 1: Optional parameter with mapping

const transformed = transformParametersForAPI(model, { reasoningEffort: options?.reasoningEffort, }); if (transformed.reasoningEffort && modelSupportsParameter(model, 'reasoningEffort')) { requestBody.reasoning_effort = transformed.reasoningEffort; }

Pattern 2: Validation before API call

const errors = validateParameters(modelId, params); if (errors.length > 0) { throw new Error(`Invalid parameters: ${errors.join(', ')}`); }

Pattern 3: Default values with mapping

const transformed = transformParametersForAPI(model, { reasoningEffort: options?.reasoningEffort ?? 'medium', // UI default }); // Will automatically map 'medium' to API value
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.