kcode-intelligence-router 0.2.2

Typed routing for model calls with exact-model and per-user usage accounting
Documentation

kcode-intelligence-router

A small typed boundary for model-backed work. It is an in-process Rust library, not an HTTP service.

The complete application-facing surface is:

  • open(Config) opens configured provider clients and returns the one primary runtime model description used by Kennedy orchestration.
  • Intelligence::for_user(user_id) binds required accounting attribution.
  • UserIntelligence::{start_agent_turn,search,transcribe,annotate} perform model calls with an exact model ID.
  • UserIntelligence::{analyze_audio,transcribe_structured_audio,generate_text} provide unstructured or schema-constrained audio analysis and tool-free text calls needed by background pipelines.
  • UserIntelligence::fetch fetches one public page.
  • Intelligence::extract_document performs local document extraction.
  • Intelligence::cancel stops an operation scope.
  • Intelligence::{receipts,daily_usage} read the plain usage receipt store.

Successful model calls return Accounted<T>, which contains the typed result and the exact canonical receipt written for that call. Provider-call errors carry their receipt when a call was attempted; validation errors do not invent one. Streaming agent turns expose the recorded receipt after their terminal event.

There is no health API, model catalog, provider selector, JSON dispatcher, or Axum dependency.

Usage receipts

Every provider call creates one atomically renamed JSON file in the configured receipt directory. A receipt contains the user, stable operation identity, optional causal parent, operation kind, requested and actual models, available provider identifiers, and either:

  • uncached input, cached input, thinking, and visible output tokens;
  • duration metering; or
  • an explicit unavailable marker.

daily_usage deliberately opens and iterates every receipt. The store has no folders or indexes until measured performance requires them.

Media

Media carries an explicit MediaKind; MIME text does not choose whether bytes are audio or video. Known Ogg audio is canonicalized to audio/ogg, so a misleading video/ogg declaration cannot route an audio object into Gemini's video constructor.