/WRITING · AI ENGINEERING
Open weights at trillion scale: when to self-host and when to call an API
Moonshot AI's Kimi K2.6, a trillion-parameter open-weight model, competes with frontier APIs on coding and agent tasks. That makes 'run it ourselves' a real option. Here is how I decide between self-hosting and hosted APIs, the hardware arithmetic, and a TypeScript router that keeps the choice reversible.
A few years ago the answer to "should we run our own model?" was almost always no: open models were clearly behind the best hosted ones. In 2026 that gap has narrowed sharply. Moonshot AI released Kimi K2.6 on 20 April 2026 as open weights: a mixture-of-experts model with about one trillion total parameters and 32 billion active per token, published on Hugging Face under a modified MIT licence. Reviews compared it favourably with leading closed models on coding and agent benchmarks.
So the question is live again, and it deserves an engineering answer rather than a slogan.
The problem: the choice looks permanent, and it should not be
Teams tend to treat model choice as an architecture decision made once: either we use a provider's API or we run our own stack. In practice the right answer changes as prices fall, models improve and your traffic grows. A product that hard-codes one provider's SDK in fifty places cannot move when the economics change.
There is also a real cost asymmetry. Hosted APIs are cheap to start and grow linearly with usage. Self-hosting has a high fixed cost, the GPUs, whether or not anyone is using them, and becomes cheaper per token only at sustained volume.
The insight: make the model a configuration choice
The durable design is a thin interface in your code, a router that picks a backend per task according to policy, and an evaluation harness that measures every candidate on your own tasks. Then "self-host or API" stops being a bet and becomes a dial you can turn per feature.
Two facts make this practical. Popular serving engines such as vLLM expose an OpenAI-compatible HTTP API, so the same client code can talk to a hosted provider or your own server. And mixture-of-experts models activate only a fraction of their parameters per token, which keeps inference compute manageable even when total size is enormous.
Implementation walkthrough
Step 1: one typed interface for the whole app
TAIWO EMMANUEL / CODE NOTEexport type Task = "chat" | "code" | "summarise-sensitive" | "extract";
export type CompletionRequest = { task: Task; system?: string; input: string; maxTokens?: number };
export type CompletionResult = { text: string; provider: string; model: string; ms: number };
export interface ModelBackend {
name: string;
complete(req: CompletionRequest, signal: AbortSignal): Promise<CompletionResult>;
}Step 2: one client for hosted and self-hosted backends
Because both speak the OpenAI-compatible chat completions API, a single factory covers a hosted provider and a vLLM server you run yourself. Only the base URL, key and model name change.
TAIWO EMMANUEL / CODE NOTEimport OpenAI from "openai";
import type { CompletionRequest, CompletionResult, ModelBackend } from "./model";
export function openAICompatible(name: string, opts: { baseURL: string; apiKey: string; model: string }): ModelBackend {
const client = new OpenAI({ baseURL: opts.baseURL, apiKey: opts.apiKey });
return {
name,
async complete(req: CompletionRequest, signal: AbortSignal): Promise<CompletionResult> {
const started = performance.now();
const res = await client.chat.completions.create(
{
model: opts.model,
max_tokens: req.maxTokens ?? 1024,
messages: [
...(req.system ? [{ role: "system" as const, content: req.system }] : []),
{ role: "user" as const, content: req.input },
],
},
{ signal },
);
return { text: res.choices[0]?.message?.content ?? "", provider: name, model: opts.model, ms: performance.now() - started };
},
};
}
// Example wiring: the same code talks to a provider and to your own vLLM server.
export const hosted = openAICompatible("hosted", { baseURL: process.env.HOSTED_BASE_URL!, apiKey: process.env.HOSTED_API_KEY!, model: process.env.HOSTED_MODEL! });
export const selfHosted = openAICompatible("self-hosted", { baseURL: "http://inference.internal:8000/v1", apiKey: process.env.VLLM_API_KEY ?? "none", model: "moonshotai/Kimi-K2.6" });Step 3: a router with policy and fallback
The router encodes your rules in one place: sensitive data never leaves your infrastructure, everything else prefers the cheapest backend that meets quality, and transient failures fall back. Note the asymmetry: sensitive tasks fail closed rather than falling back to an external provider.
TAIWO EMMANUEL / CODE NOTEimport type { CompletionRequest, CompletionResult, ModelBackend } from "./model";
type Route = { primary: ModelBackend; fallback?: ModelBackend; timeoutMs: number };
export function createRouter(routes: Record<CompletionRequest["task"], Route>) {
return async function complete(req: CompletionRequest): Promise<CompletionResult> {
const route = routes[req.task];
try {
return await withTimeout(route.primary, req, route.timeoutMs);
} catch (error) {
if (!route.fallback) throw error; // e.g. sensitive tasks: fail closed, never send data elsewhere
return withTimeout(route.fallback, req, route.timeoutMs);
}
};
}
async function withTimeout(backend: ModelBackend, req: CompletionRequest, ms: number) {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), ms);
try { return await backend.complete(req, controller.signal); } finally { clearTimeout(timer); }
}
// Usage
// const complete = createRouter({
// "summarise-sensitive": { primary: selfHosted, timeoutMs: 30_000 }, // no fallback
// code: { primary: selfHosted, fallback: hosted, timeoutMs: 60_000 },
// chat: { primary: hosted, fallback: selfHosted, timeoutMs: 20_000 },
// extract: { primary: hosted, timeoutMs: 15_000 },
// });Step 4: decide with your own evaluations
Public benchmarks tell you which models are worth testing, not which one is right for your product. Keep a small, versioned set of real tasks with expected properties (correct JSON, required facts, banned content) and run every candidate backend against it before changing a route. Then cost, latency and quality are numbers you measured, not numbers someone else published.
Licences matter too. Read the actual model card and licence file before shipping: "open weights" licences vary between labs and even between versions from the same lab, and hosted distributions can add their own terms on top.
Takeaway
- Open-weight models such as Kimi K2.6 (about 1T parameters, 32B active, modified MIT) make self-hosting a serious option in 2026.
- Self-hosting wins on data control, customisation and cost at sustained volume; hosted APIs win on speed, elasticity and zero operations.
- Put one interface, one router and your own evaluations between your product and every model, so the choice stays reversible.
- Do the hardware arithmetic and read the licence before you buy GPUs.
References
- 1. moonshotai/Kimi-K2.6 — Hugging Face
- 2. Kimi K2.6 has arrived: an open-weight powerhouse for agentic work — Kilo Code blog, April 2026
- 3. moonshotai / kimi-k2.6 API reference — NVIDIA NIM docs
- 4. OpenAI-compatible server — vLLM docs
- 5. openai-node (official OpenAI TypeScript library) — OpenAI on GitHub