Hokusai SDK
Hokusai is a task routing and outcome-learning SDK for coding harnesses. It provides shared routing, payload, privacy, consent, model-mapping, and outcome-reporting contracts, plus adapters that show how those contracts fit into real harnesses.
This repository currently includes:
@hokusai/router for routing a task from application code — the front door, and where most integrations should start
@hokusai/core for the harness-agnostic SDK contracts and API client
@hokusai/costs for drop-in per-task cost measurement (measureTask / createTaskCostTracker) plus the provider-neutral pricing engine, source adapters, and local ledger underneath — entirely offline, over the @hokusai/core task-cost contract
@hokusai/adapter-claude-code for the installable Claude Code plugin and Claude-specific adapter
@hokusai/adapter-codex for the installable Codex plugin, MCP server, task context, model mapping, and outcome builders
@hokusai/adapter-wavemill for a richer replay-aware reference adapter used by Wavemill-style harnesses
@hokusai/adapter-aider for a vendor-neutral CLI wrapper that routes a task through Hokusai and launches Aider with the recommended model
@hokusai/scan for the Arbiter scanner: the survival labeller and candidate-feature extractor, as a library, the hokusai-scan CLI, and a one-shot GitHub Action
examples/reference-harness for the smallest complete generic integration flow
examples/litellm-integration for a Python-side LiteLLM metadata-only routing prototype
examples/openhands-integration for the Python-side @hokusai/adapter-openhands equivalent — Hokusai-backed RouterLLM plus SDK-metrics contribution rows
Measure task cost — no account needed
Per-task cost measurement is a standalone, local feature: no Hokusai account,
no HOKUSAI_API_KEY, no network calls, no default disk writes. One import,
one wrapper call:
npm install @hokusai/costs
import { measureTask } from '@hokusai/costs';
const { result, cost } = await measureTask({ events: harness }, () =>
harness.run(task),
);
// cost.totalUsd, cost.byModel, cost.byHarness, cost.usage, cost.coverage, cost.diagnostics
It captures usage from supported usage events or Claude Code/Codex session
files (always behind an explicit session boundary), or from your own
tracker.recordUsage(...) calls. Routing and contribution stay entirely
optional. See packages/costs/README.md.
Install Packages
If you are routing tasks from your own application code, start with
@hokusai/router — a thin façade over @hokusai/core that owns the client,
dispatch builder, consent snapshot, and model registry for you:
pnpm add @hokusai/router
npm install @hokusai/router
import { route } from '@hokusai/router';
const { model } = await route({ task, availableModels, maxCostUsd: 1 });
const result = await models[model].run(task);
await route.reportOutcome({
status: 'succeeded',
actualCostUsd: result.costUsd,
});
See packages/router/README.md. Pass maxCostUsd
when routing and actualCostUsd when reporting: the server scores one against
the other, and a contribution missing either is stored as telemetry that trains
nothing and earns nothing.
If a model choice was made outside Hokusai, use the explicit report-only path
instead of fabricating a route. This opens coverage for Qwen, GLM, Gemini, Grok,
DeepSeek, Kimi, Llama, Mistral, and other externally routed runs:
await route.reportExternalOutcome({
task: 'Refactor the auth middleware to use the new policy engine.',
allowedModels: ['qwen-3-coder', 'glm-5.2', 'gemini-2.5-pro'],
model: 'qwen-3-coder',
status: 'succeeded',
budgetUsd: 0.5,
actualCostUsd: 0.12,
harness: 'custom-harness',
});
The server still assigns the authoritative fidelity tier. Route-less
observations improve model coverage, but they are not attributed to a Hokusai
routing decision unless the backend explicitly classifies them that way.
If you are building a harness rather than calling one, start with
@hokusai/core:
pnpm add @hokusai/core
npm install @hokusai/core
Add an adapter package when you are targeting a specific harness:
pnpm add @hokusai/adapter-claude-code
pnpm add @hokusai/adapter-codex
pnpm add @hokusai/adapter-wavemill
pnpm add @hokusai/adapter-aider
npm install @hokusai/adapter-claude-code
npm install @hokusai/adapter-codex
npm install @hokusai/adapter-wavemill
npm install @hokusai/adapter-aider
What The SDK Provides
@hokusai/core owns the shared route/report protocol: