Train a custom LLM router
Changed onTrain a custom router on your evaluation data to optimize routing for your specific use case.
This endpoint allows you to train a domain-specific router that learns which models perform best for different types of queries in your application. The router analyzes your evaluation dataset, clusters similar queries, and learns model performance patterns.
Training Process:
- Upload a CSV file with your evaluation data
- Specify which models to route between
- Define the evaluation metric (score column)
- The system trains asynchronously and returns a preference_id
- Use the preference_id in model_select() calls once training completes
Dataset Requirements:
- Format: CSV file
- Minimum samples: 25 (more is better for accuracy)
- Required columns:
- Prompt column (specified in prompt_column parameter)
- For each model: {provider}/{model}/score and {provider}/{model}/response
Example CSV structure:
prompt,openai/gpt-4o/score,openai/gpt-4o/response,anthropic/claude-sonnet-4-5-20250929/score,anthropic/claude-sonnet-4-5-20250929/response
"Explain quantum computing",0.95,"Quantum computing uses...",0.87,"Quantum computers leverage..."
"Write a Python function",0.82,"def my_function()...",0.91,"Here's a Python function..."
Model Selection:
- Specify standard models: {"provider": "openai", "model": "gpt-4o"}
- Or custom models with pricing: {"provider": "custom", "model": "my-model", "is_custom": true, "input_price": 10.0, "output_price": 30.0, "context_length": 8192, "latency": 1.5}
Training Time:
- Training is asynchronous and typically takes 5-15 minutes
- Larger datasets or more models take longer
- You'll receive a preference_id immediately
- Check training status by attempting to use the preference_id in model_select()
Best Practices:
- Use diverse, representative examples from your production workload
- Include at least 50-100 samples for best results
- Ensure consistent evaluation metrics across all models
- Use the same models you plan to route between in production
Related Documentation: See https://docs.notdiamond.ai/docs/adapting-prompts-to-new-models for detailed guide.
Request
- Base URLhttps://api.notdiamond.ai
- URLhttps://api.notdiamond.ai/v2/pzn/trainCustomRouter
- AuthHTTP bearer
Request body multipart/form-data
Example request
{
"language": "english",
"llm_providers": "[{\"provider\": \"openai\", \"model\": \"gpt-4o\"}, {\"provider\": \"anthropic\", \"model\": \"claude-sonnet-4-5-20250929\"}]",
"prompt_column": "prompt"
}Response
Successfully started training custom router
Example response
{
"preference_id": "550e8400-e29b-41d4-a716-446655440000"
}Changes
- breaking
the
request property contentMediaType changed fromapplication/octet-streamto - breaking
the
request property format changed from no format tobinary - warning
removed the optional property
//from the response with the status - warning
removed the optional property
//from the response with the status
- breaking
- breaking
the
request property contentMediaType changed fromtoapplication/octet-stream - info
the
request property format was generalized frombinaryto no format - info
added the optional property
//to the response with the status - info
added the optional property
//to the response with the status
- breaking