Model Router
Model Router

Select best LLM for your query

Changed on

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

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

Request

  • Base URL
    https://api.notdiamond.ai
  • URL
    https://api.notdiamond.ai/v2/modelRouter/modelSelect
  • Auth
    HTTP bearer

Query parameters

typestring nullable

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

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. Mutually exclusive with cost_quality_tradeoff.

cost_quality_tradeoffinteger nullable

Continuous cost/quality blend on a 0–10 integer scale. 0 is equivalent to default (pure quality) routing; 10 selects the cheapest candidate model; intermediate values blend the two signals. Mutually exclusive with tradeoff. Only supported on the default (pre-trained) router — requests using a trained custom router that set this field are rejected with HTTP 422.

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"
}

Changes

    • warning

      removed the optional property // from the response with the status

    • warning

      removed the optional property // from the response with the status

    • info

      added the optional property // to the response with the status

    • info

      added the optional property // to the response with the status