v2

latestOpenAPI 3.1.02026-07-26103975.6 KB
Model Router
Model Router

Select best LLM for your query

Select the optimal LLM to handle your query based on Not Diamond's routing algorithm.

This endpoint analyzes your messages and returns the best-suited model from your specified models. The router considers factors like query complexity, model capabilities, cost, and latency based on your preferences.

Key Features:

  • Intelligent routing across multiple LLM providers
  • Support for custom routers trained on your evaluation data
  • Optional cost/latency optimization
  • Function calling support for compatible models

Usage:

  1. Pass your messages in OpenAI format (array of objects with 'role' and 'content')
  2. Specify which LLM providers you want to route between
  3. Optionally provide a preference_id to use a custom router that you've trained
  4. Receive a recommended model and session_id
  5. Use the session_id to submit feedback and improve routing for non-hashed sessions

Related Endpoints:

  • POST /v2/preferences/userPreferenceCreate - Create a preference ID for personalized routing
  • POST /v2/pzn/trainCustomRouter - Train a custom router on your evaluation data
post/v2/modelRouter/modelSelect

Query parameters

typestring nullable

Optional format type. Use 'openrouter' to accept and return OpenRouter-format model identifiers

Optional format type. Use 'openrouter' to accept and return OpenRouter-format model identifiers

Request body

toolsobject[] nullable

OpenAI-format function calling tools

hash_contentboolean

Whether to hash message content for privacy. Hashed content is not persisted.

metricstring

Optimization metric for model selection

max_model_depthinteger nullable

Maximum number of models to consider for routing. If not specified, considers all provided models

tradeoffstring nullable

Optimization tradeoff strategy. Use 'cost' to prioritize cost savings or 'latency' to prioritize speed

cost_quality_tradeoffinteger nullable

Blend cost and quality: 0 = pure quality (default), 10 = pure cost. Mutually exclusive with tradeoff. Not supported with custom routers.

preference_idstring nullable

Preference ID for personalized routing. Create one via POST /v2/preferences/userPreferenceCreate

previous_sessionstring nullable

Previous session ID to link related requests

Example request

{
  "llm_providers": [
    {
      "model": "gpt-4o",
      "provider": "openai"
    },
    {
      "model": "claude-sonnet-4-5-20250929",
      "provider": "anthropic"
    },
    {
      "model": "gemini-2.5-flash",
      "provider": "google"
    }
  ],
  "tradeoff": "cost"
}

Response

Successfully selected optimal model

session_idstring required

Unique session ID for this routing decision

Example response

{
  "providers": [
    {
      "model": "gpt-4o",
      "provider": "openai"
    }
  ],
  "session_id": "00000000-0000-0000-0000-000000000000"
}
All 10 operations