---
title: "Select best LLM for your query"
method: POST
path: "/v2/modelRouter/modelSelect"
tags: ["Model Router", "Model Router"]
---

# Select best LLM for your query

`POST /v2/modelRouter/modelSelect`

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

## Query parameters

- `type` string, nullable — Optional format type. Use 'openrouter' to accept and return OpenRouter-format model identifiers

## Request body

- OptimizerBaseRequest — Request model for LLM routing via Not Diamond.
  - `messages` union, required — Array of message objects in OpenAI format (with 'role' and 'content' keys)
    - object[]
    - string
  - `llm_providers` union[], required — List of LLM providers to route between. Specify at least one provider in format {provider, model}
    - union
      - RequestProvider — Model for specifying an LLM provider in API requests.
        - `is_custom` boolean — Whether this is a custom model not in Not Diamond's supported model list
        - `context_length` integer, nullable — Maximum context length for the model (required for custom models)
        - `input_price` number, nullable — Input token price per million tokens in USD (required for custom models)
        - `output_price` number, nullable — Output token price per million tokens in USD (required for custom models)
        - `latency` number, nullable — Average latency in seconds (required for custom models)
        - `provider` string, required — Provider name (e.g., 'openai', 'anthropic', 'google')
        - `model` string, required — Model name (e.g., 'gpt-4o', 'claude-sonnet-4-5-20250929')
      - OpenRouterProvider — Model for specifying an LLM provider using OpenRouter format. Used in model routing requests when you want to specify providers using the OpenRouter naming convention (combined 'provider/model' format). This is an alternative to the standard RequestProvider which uses separate provider and model fields. **When to use:** - When working with OpenRouter-compatible systems - When you prefer the unified 'provider/model' format - For models accessed via OpenRouter proxy
        - `is_custom` boolean — Whether this is a custom model not in Not Diamond's supported model list
        - `context_length` integer, nullable — Maximum context length for the model (required for custom models)
        - `input_price` number, nullable — Input token price per million tokens in USD (required for custom models)
        - `output_price` number, nullable — Output token price per million tokens in USD (required for custom models)
        - `latency` number, nullable — Average latency in seconds (required for custom models)
        - `model` string, required — OpenRouter model identifier in 'provider/model' format (e.g., 'openai/gpt-4o', 'anthropic/claude-sonnet-4-5-20250929')
  - `tools` object[], nullable — OpenAI-format function calling tools
  - `hash_content` boolean — Whether to hash message content for privacy
  - `metric` string — Optimization metric for model selection
  - `max_model_depth` integer, nullable — Maximum number of models to consider for routing. If not specified, considers all provided models
  - `tradeoff` string, nullable — Optimization tradeoff strategy. Use 'cost' to prioritize cost savings or 'latency' to prioritize speed
  - `preference_id` string, nullable — Preference ID for personalized routing. Create one via POST /v2/preferences/userPreferenceCreate
  - `previous_session` string, nullable — Previous session ID to link related requests

## Response `200`

Successfully selected optimal model

- ModelSelectResponse — Response from model selection endpoint.
  - `providers` NotdiamondServerApiOptimizerProviderResponse[], required — List containing the selected provider
    - `provider` string, required — Provider name for the selected model (e.g., 'openai', 'anthropic', 'google')
    - `model` string, required — Model identifier for the selected model (e.g., 'gpt-4o', 'claude-3-opus-20240229')
  - `session_id` string, required — Unique session ID for this routing decision

## Other responses

- `400` — Invalid request (e.g., no providers specified, invalid preference_id)
- `401` — Authentication failed
- `404` — Preference ID not found
- `422` — Validation Error

---

[API](https://skmtc.dev/not-diamond/apis/not-diamond-api.md) · [All operations](https://skmtc.dev/not-diamond/apis/not-diamond-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/not-diamond/not-diamond-api/revisions/ea8fcb544470/schema)
