Skip to main content
API Reference

Routing API Reference

SwarmSync exposes an OpenAI-compatible API that automatically routes every request to the best available model based on task complexity, capability matching, and tier constraints.

Quick Start

The routing layer is a drop-in replacement for the OpenAI API. Set baseURL to the SwarmSync endpoint and authenticate with your sk-ss-... key.

import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.swarmsync.ai/v1',
  apiKey: process.env.SWARMSYNC_ROUTING_KEY, // sk-ss-...
});

const response = await client.chat.completions.create({
  model: 'auto',          // auto-routes to best model
  // model: 'economy',    // → economy tier (same as swarmsync/budget)
  // model: 'premium',    // → premium tier (same as swarmsync/performance)
  messages: [{ role: 'user', content: 'Your prompt here' }],
});

// Every response includes routing metadata
const meta = response.swarmsync;
console.log(meta.routed_model);     // e.g. "claude-sonnet-4-6"
console.log(meta.tier);             // "economy" | "mid" | "premium"
console.log(meta.complexity_score); // 0.0 – 1.0
console.log(meta.estimated_cost);   // USD including 8% platform fee

Authentication

All routing endpoints require a routing API key passed in the Authorization header.

Authorization: Bearer sk-ss-​​​<your-key>

Manage your keys at /console/settings/routing-keys. Keys are scoped per user account and track usage independently.

Endpoints

Base URL: https://api.swarmsync.ai

POST
/v1/chat/completions

OpenAI-compatible chat completions with auto-routing. Pass model: "auto" for intelligent routing or any virtual alias.

auth required
GET
/v1/models

List all available models with tier, pricing, capability scores, and provider information.

auth required
POST
/v1/route

Preview which model would be selected for a given prompt. Performs scoring only — no LLM call is made.

auth required
GET
/v1/keys

List routing API keys for your account. Authenticated with your sk-ss- routing key. The legacy path /v1/auth/keys also works but requires a JWT.

auth required
GET
/v1/usage

Usage stats and cost summary for the authenticated API key.

auth required

The POST /v1/route endpoint accepts the same body as POST /v1/chat/completions but performs only scoring and model selection — no LLM call is made and no tokens are consumed.

// Dry-run: see which model would be chosen without spending tokens
const res = await fetch('https://api.swarmsync.ai/v1/route', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer sk-ss-...',
  },
  body: JSON.stringify({
    model: 'auto',
    messages: [{ role: 'user', content: 'Refactor this TypeScript class...' }],
  }),
});
const { model, tier, complexity_score } = await res.json();

Virtual Model Aliases

Pass one of these strings as the model field instead of a specific model ID to use the routing system. You can also pin a specific model (e.g. "claude-sonnet-4-6") to bypass routing entirely.

"auto"

Full two-stage routing: complexity score determines tier, then capability matching picks the best model within that tier. Recommended default.

"economy"

Forces routing to the economy tier (score 0.0-0.3). Ideal for high-volume tasks: summaries, extraction, simple Q&A. Short alias for swarmsync/budget.

"budget"

Forces routing to the economy tier. Equivalent to economy.

"swarmsync/budget"

Canonical economy-tier alias. Equivalent to economy and budget.

"premium"

Forces routing to the premium tier (score 0.7-1.0). Selects frontier models for complex reasoning, agentic workflows, and long-context tasks. Short alias for swarmsync/performance.

"performance"

Forces routing to the premium tier. Equivalent to premium.

"swarmsync/performance"

Canonical premium-tier alias. Equivalent to premium and performance.

"balanced"

Forces routing to the mid tier (score 0.3-0.7). Short alias for swarmsync/balanced.

"swarmsync/balanced"

Canonical mid-tier alias. Complexity-based routing that caps selection to the mid tier. Equivalent to balanced.

Routing Response Metadata

Every response from /v1/chat/completions includes a swarmsync object alongside the standard OpenAI fields. Use this to audit routing decisions, track cost savings, and tune your model strategy.

FieldTypeDescription
routed_modelstringThe canonical model ID that was selected and called (e.g. "claude-sonnet-4-6").
routing_reasonstringHuman-readable explanation of why this model was chosen, including tier, dominant signals, and top task dimension (e.g. "mid_complexity_code_presence+reasoning_keywords_task:coding").
complexity_scorenumberRaw complexity score from 0.0 to 1.0. Below 0.3 = economy, 0.3–0.7 = mid, above 0.7 = premium.
estimated_costnumberEstimated USD cost of this request based on token counts and the selected model's pricing, inclusive of the 8% platform fee.
tierstringThe routing tier used: "economy", "mid", or "premium".
savings_vs_premiumnumberEstimated USD saved compared to routing the same request to the most expensive available model.

Parameters

All standard OpenAI chat completion parameters are supported and forwarded to the selected provider. The routing layer adds the model alias resolution on top.

ParameterRequiredDescription
modelrequiredAny virtual alias (auto, economy, budget, balanced, premium, swarmsync/budget, swarmsync/balanced, swarmsync/performance) or a pinned model ID.
messagesrequiredOpenAI-format message array: [{ role: "user" | "assistant" | "system", content: string }].
temperatureoptionalFloat in range 0.0–2.0. Values exactly at 0 are normalized to 0.0001 for provider compatibility. Defaults to the model's own default if omitted.
max_tokensoptionalMaximum tokens in the completion. Forwarded as-is to the provider.
top_poptionalNucleus sampling probability. Forwarded to providers that support it.
streamoptionalBoolean. When true, returns a server-sent events stream (text/event-stream). Defaults to false.
toolsoptionalOpenAI-format tools array for function calling. The router automatically selects a tool-capable model when this field is present.
response_formatoptionalOpenAI-format response_format object (e.g. { type: "json_object" }). Triggers structured-output routing.
stopoptionalStop sequence string or array. Forwarded to the provider.

Ready to Route?

Get a routing key from your console and start calling 15 frontier models through a single OpenAI-compatible endpoint.