FreeLLMAPI Routing Strategies: 6 Built-In Methods for Model Selection

FreeLLMAPI provides six routing strategies—priority, balanced, smartest, fastest, reliable, and custom—that let you control how the system selects between model providers using preset or custom weight vectors.

FreeLLMAPI routes every inference request through a pluggable router that decides which model-provider key handles the call. The router's behavior is driven by a routing strategy, a preset weight vector that tells the engine how much to value speed, reliability, intelligence, and other factors. This article explains how each strategy works and how to configure them in your deployment.

What Are FreeLLMAPI Routing Strategies?

The routing strategies in FreeLLMAPI are defined in the core scoring module at [server/src/services/scoring.ts](https://github.com/tashfeenahmed/freellmapi/blob/main/server/src/services/scoring.ts#L34). Each strategy corresponds to a specific weight vector applied to the scoring algorithm that ranks candidate models.

When a request arrives, the router:

  1. Evaluates each candidate model/key
  2. Computes a score based on the active strategy's weights
  3. Selects the highest-scoring entry that satisfies quota and health checks

The strategy can be changed at runtime via the router API or programmatically within the server code.

The 6 FreeLLMAPI Routing Strategies Explained

Priority: Manual Admin-Controlled Ordering

The priority strategy follows the explicit chain order defined by the administrator. This is the legacy behavior that provides deterministic routing.

Balanced: Neutral, General-Purpose Routing

The balanced strategy provides equal consideration for speed, reliability, and intelligence.

  • Weight vector: BANDIT_PRESETS.balanced (~0.33 each)
  • Use case: Default general-purpose workloads where no single factor should dominate

Smartest: Intelligence-First Selection

The smartest strategy prioritizes the most capable model even if it responds more slowly.

  • Weight vector: BANDIT_PRESETS.smartest (intelligence ~0.55, speed ~0.10)
  • Use case: Creative writing, complex problem-solving, code generation, or any task where output quality matters more than latency

Fastest: Low-Latency Priority

The fastest strategy emphasizes quick response times, tolerating lower reliability if necessary.

  • Weight vector: BANDIT_PRESETS.fastest (speed ~0.55, intelligence ~0.10)
  • Use case: Real-time chat assistants, UI-responsive bots, or latency-sensitive applications

Reliable: Success-Rate Optimization

The reliable strategy prefers models with strong success rates and low error rates.

  • Weight vector: BANDIT_PRESETS.reliable (reliability ~0.55)
  • Use case: Mission-critical workloads where failures are costly

Custom: User-Defined Weight Vectors

The custom strategy lets advanced users supply their own weight vector.

How to Configure FreeLLMAPI Routing Strategies

Runtime API Configuration

Change the strategy via the MCP route endpoint:

// POST /v1/mcp/routing/strategy
// Implementation in src/routes/mcp.ts
import fetch from 'node-fetch';

const resp = await fetch('https://api.freellmapi.com/v1/mcp/routing/strategy', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ strategy: 'smartest' }),
});

const data = await resp.json();
console.log('Strategy set to:', data.strategy);

This endpoint calls setRoutingStrategy internally.

Server-Side Programmatic Configuration

Use the router service directly in your server code:

import { setRoutingStrategy, getRoutingStrategy } from '../services/router.js';

// Switch to the "fastest" preset
setRoutingStrategy('fastest');

console.log('Current strategy →', getRoutingStrategy()); // → 'fastest'

Client-Side Type-Safe Configuration

The client library provides the same type definitions in [client/src/lib/routing.ts](https://github.com/tashfeenahmed/freellmapi/blob/main/client/src/lib/routing.ts#L59):

import { setRoutingStrategy, type RoutingStrategy } from '@freellmapi/client';

const chosen: RoutingStrategy = 'balanced';
setRoutingStrategy(chosen);

Key Source Files for FreeLLMAPI Routing

File Role
server/src/services/scoring.ts Defines RoutingStrategy type and preset weight vectors (BANDIT_PRESETS)
server/src/services/router.ts Core routing engine; implements scoring algorithm and strategy getters/setters
server/src/routes/mcp.ts HTTP endpoint for runtime strategy changes
client/src/lib/routing.ts Client-side type exports and API wrapper
server/src/services/declarative-config.ts Persistence for custom weight vectors

Summary

FreeLLMAPI routing strategies give you precise control over model selection:

  • priority — Deterministic admin-ordered routing with no weighting
  • balanced — Equal weight to speed, reliability, and intelligence
  • smartest — Favors capable models, accepts slower responses
  • fastest — Optimizes for low latency
  • reliable — Prioritizes proven success rates
  • custom — User-defined weight vector for specialized needs

Configure via HTTP API, server code, or client library. All strategies are implemented in the open-source tashfeenahmed/freellmapi repository.

Frequently Asked Questions

How do I switch routing strategies without restarting the server?

Send a POST request to /v1/mcp/routing/strategy with your desired strategy in the request body, or call setRoutingStrategy() programmatically. The change takes effect immediately for subsequent requests.

What happens if I specify an invalid strategy name?

The router validates strategy names against the RoutingStrategy type defined in scoring.ts. Invalid values will be rejected with a type error or API validation failure before affecting the routing engine.

Can I combine multiple strategies or create hybrid weights?

Yes—use the custom strategy and define your own RoutingWeights record. This is persisted via declarative-config.ts and applies your specific balance across speed, reliability, intelligence, and headroom factors.

Does the priority strategy ignore all performance metrics entirely?

Correct. The priority strategy sets weights: null and skips the scoring algorithm, following only the explicit chain order defined in your configuration. No latency, success rate, or capability data influences the selection.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →