Dynamic Models
This document describes the new dynamic model configuration system that replaces static enums with flexible, runtime-configurable model definitions.
π― Overview
The dynamic model system enables:
Runtime model discovery from external configuration sources
Automatic fallback to local configurations when external sources fail
Smart model resolution with fuzzy matching and aliases
Capability-based search to find models with specific features
Cost optimization by automatically selecting cheapest models for tasks
ποΈ Architecture
Components
Model Configuration Server (
scripts/modelServer.js)Serves model configurations via REST API
Provides search and filtering capabilities
Can be hosted anywhere (GitHub, CDN, internal server)
Dynamic Model Provider (
src/lib/core/dynamicModels.ts)Loads configurations from multiple sources with fallback
Caches configurations to reduce network requests
Validates configurations using Zod schemas
Provides intelligent model resolution
Model Configuration (
config/models.json)JSON-based model definitions
Includes pricing, capabilities, and metadata
Supports aliases and provider defaults
π Quick Start
1. Environment Setup
Before using the dynamic model system, ensure your provider configurations are set up correctly. See the Provider Configuration Guide for detailed instructions.
2. Start the Model Server
Server runs on http://localhost:3001 by default.
2. Test the System
3. Use in Code
π‘ API Endpoints
Model Server Endpoints
GET /health- Health checkGET /api/v1/models- Get all model configurationsGET /api/v1/models/:provider- Get models for specific providerGET /api/v1/search?capability=X&maxPrice=Y- Search models by criteria
Example API Usage
π§ Configuration Schema
Model Configuration Structure
Key Fields
id: Provider-specific model identifierdisplayName: Human-readable model namecapabilities: Array of model capabilities (functionCalling, vision, etc.)deprecated: Whether the model is deprecatedpricing: Input/output token costs per 1K tokenscontextWindow: Maximum context window sizereleaseDate: Model release date
ποΈ Advanced Usage
Configuration Sources
The system tries multiple sources in order:
process.env.MODEL_CONFIG_URL- Custom URL overridehttp://localhost:3001/api/v1/models- Local development serverhttps://raw.githubusercontent.com/NeurosLink/docs/release/config/models.json- GitHub./config/models.json- Local fallback
Model Resolution Logic
Capability Search Options
π Migration from Static Enums
Before (Static Enums)
After (Dynamic Resolution)
π Production Deployment
Environment Variables
Hosting Configuration
GitHub Pages: Host
models.jsonas static fileCDN: Use CloudFlare/AWS CloudFront for global distribution
Internal API: Integrate with existing infrastructure
File System: Local configurations for air-gapped environments
Cache Strategy
5-minute cache: Balances freshness with performance
Graceful degradation: Falls back to cached data on network failures
Manual refresh:
dynamicModelProvider.refresh()for immediate updates
π§ͺ Testing
The test suite verifies:
β Model provider initialization β Configuration loading from multiple sources β Model resolution (exact, default, fuzzy, alias) β Capability-based search β Best model selection algorithms β Error handling and fallbacks
Run tests with:
π Benefits
π Future-Proof: New models automatically available
π° Cost-Optimized: Runtime selection based on pricing
π‘οΈ Reliable: Multiple fallback sources
β‘ Fast: Cached configurations with smart invalidation
π Type-Safe: Zod schemas ensure runtime safety
π§ Backward Compatible: Existing code continues working
This system transforms static model definitions into a dynamic, self-updating platform that scales with the rapidly evolving AI landscape.
Last updated
Was this helpful?

