const response = await fetch("https://llmadaptive.uk/api/v1/select-model", {
  method: "POST",
  headers: {
    "X-Stainless-API-Key": "your-adaptive-api-key",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    models: [
      { provider: "openai" },
      { provider: "anthropic" },
      { provider: "google" },
    ],
    prompt: "Hello, how are you today?",
  }),
});

const result = await response.json();
console.log(`Selected: ${result.provider}/${result.model}`);
{
  "provider": "openai",
  "model": "gpt-4o-mini",
  "alternatives": [
    {
      "provider": "openai",
      "model": "gpt-4o"
    }
  ]
}

Model Selection Example

Use Adaptive’s intelligent model selection to get routing decisions without running inference. Perfect for testing strategies, cost planning, and integrating with your own provider accounts.
This example demonstrates the /select-model endpoint which returns optimal model choices based on your prompt and criteria without actually running inference.

Quick Start

The select-model endpoint helps you choose the best model from your available options based on prompt complexity, cost optimization, and task requirements.
const response = await fetch("https://llmadaptive.uk/api/v1/select-model", {
  method: "POST",
  headers: {
    "X-Stainless-API-Key": "your-adaptive-api-key",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    models: [
      { provider: "openai" },
      { provider: "anthropic" },
      { provider: "google" },
    ],
    prompt: "Hello, how are you today?",
  }),
});

const result = await response.json();
console.log(`Selected: ${result.provider}/${result.model}`);
{
  "provider": "openai",
  "model": "gpt-4o-mini",
  "alternatives": [
    {
      "provider": "openai",
      "model": "gpt-4o"
    }
  ]
}

Cost vs Performance Optimization

Control the balance between cost and performance using the cost_bias parameter.
Cost Bias Scale: 0.0 = cheapest models, 1.0 = best performance models
const performanceResponse = await fetch("https://llmadaptive.uk/api/v1/select-model", {
  method: "POST",
  headers: {
    "X-Stainless-API-Key": "your-adaptive-api-key",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    models: [
      { provider: "openai", model_name: "gpt-4o-mini" },
      { provider: "openai", model_name: "gpt-4o" },
      { provider: "anthropic", model_name: "claude-3-5-sonnet-20241022" },
    ],
    prompt: "Write a comprehensive analysis of market trends",
    cost_bias: 0.9, // Prioritize performance
  }),
});
{
  "provider": "anthropic",
  "model": "claude-3-5-sonnet-20241022"
}

Function Calling Support

When tools are provided, Adaptive automatically prioritizes models that support function calling.
const functionResponse = await fetch("https://llmadaptive.uk/api/v1/select-model", {
  method: "POST",
  headers: {
    "X-Stainless-API-Key": "your-adaptive-api-key",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    models: [
      { provider: "openai", model_name: "gpt-4o-mini" },
      { provider: "anthropic", model_name: "claude-3-haiku-20240307" },
      { provider: "google", model_name: "gemini-1.5-flash" },
    ],
    prompt: "What's the current weather in San Francisco?",
    tools: [
      {
        type: "function",
        function: {
          name: "get_weather",
          description: "Get current weather for a location",
          parameters: {
            type: "object",
            properties: {
              location: {
                type: "string",
                description: "The city name to get weather for",
              },
            },
            required: ["location"],
          },
        },
      },
    ],
  }),
});
{
  "provider": "google",
  "model": "gemini-1.5-flash"
}

Custom Models

Mix known cloud models with your custom local or fine-tuned models for hybrid deployments.
const customResponse = await fetch("https://llmadaptive.uk/api/v1/select-model", {
  method: "POST",
  headers: {
    "X-Stainless-API-Key": "your-adaptive-api-key",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    models: [
      { provider: "openai", model_name: "gpt-4o-mini" }, // Known model
      {
        // Custom model specification
        provider: "local",
        model_name: "my-custom-llama-fine-tune",
        cost_per_1m_input_tokens: 0.0, // Free since it's local
        cost_per_1m_output_tokens: 0.0,
        max_context_tokens: 4096,
        supports_tool_calling: false,
        complexity: "medium",
        task_type: "Text Generation",
      },
    ],
    prompt: "Hello, how are you?",
    cost_bias: 0.1, // Prioritize cost savings to select the free local model
  }),
});
{
  "provider": "local",
  "model": "my-custom-llama-fine-tune"
}

Use Cases

Cost Planning

Test different routing strategies to estimate costs before implementation

A/B Testing

Compare model selection across different cost_bias values and prompts

Integration Testing

Validate routing decisions before connecting to your provider accounts

Hybrid Deployments

Mix cloud and on-premise models for optimal cost and latency

Complete Example

Here’s a full example that demonstrates all features:
async function demonstrateModelSelection() {
  const apiKey = process.env.ADAPTIVE_API_KEY;
  const baseURL = "https://llmadaptive.uk/api/v1";

  // Example 1: Basic selection
  const basicResponse = await fetch(`${baseURL}/select-model`, {
    method: "POST",
    headers: {
      "X-Stainless-API-Key": apiKey,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      models: [
        { provider: "openai" },
        { provider: "anthropic" },
        { provider: "google" },
      ],
      prompt: "Hello, how are you today?",
    }),
  });

  const basicResult = await basicResponse.json();
  console.log(`Basic: ${basicResult.provider}/${basicResult.model}`);

  // Example 2: Performance-focused
  const performanceResponse = await fetch(`${baseURL}/select-model`, {
    method: "POST",
    headers: {
      "X-Stainless-API-Key": apiKey,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      models: [
        { provider: "openai", model_name: "gpt-4o-mini" },
        { provider: "anthropic", model_name: "claude-3-5-sonnet-20241022" },
      ],
      prompt: "Write a comprehensive analysis",
      cost_bias: 0.9,
    }),
  });

  const performanceResult = await performanceResponse.json();
  console.log(`Performance: ${performanceResult.provider}/${performanceResult.model}`);

  // Example 3: Cost-focused
  const costResponse = await fetch(`${baseURL}/select-model`, {
    method: "POST",
    headers: {
      "X-Stainless-API-Key": apiKey,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      models: [
        { provider: "openai", model_name: "gpt-4o-mini" },
        { provider: "anthropic", model_name: "claude-3-5-sonnet-20241022" },
      ],
      prompt: "Hello",
      cost_bias: 0.1,
    }),
  });

  const costResult = await costResponse.json();
  console.log(`Cost-focused: ${costResult.provider}/${costResult.model}`);
}

demonstrateModelSelection();
Basic: openai/gpt-4o-mini
Performance: anthropic/claude-3-5-sonnet-20241022
Cost-focused: openai/gpt-4o-mini

Key Benefits

No Inference Costs - Get routing decisions without running actual completions
Fast Decisions - Sub-second response times for model selection
Cost Optimization - Balance performance and cost with the cost_bias parameter
Function Calling Aware - Automatically prioritizes compatible models when tools are provided
Hybrid Support - Mix cloud and custom models seamlessly

Next Steps