Concepts
Hooks
The pipeline model behind BitRouter — a request flows through ordered stages, and each hook can allow, deny, mutate, or observe it.
A hook is a callback that runs at a specific point as a request flows through the router. BitRouter processes every request as an ordered pipeline of stages; hooks attach to those stages, and depending on the stage a hook can allow, deny, mutate, or observe the request. Plugins bundle hooks and install them.
The language-model pipeline
The main language_model pipeline runs five kinds of hook, in order:
- PreRequest — auth, policy, rate-limit, balance, and guardrail checks. Each returns allow or deny; the first deny stops the pipeline and maps to an HTTP status.
- Route — resolve or rewrite the ordered chain of routing targets for the request.
- Execution — observe each attempt and control fallback on success or failure.
- Stream — intercept streamed response parts to rewrite, drop, or abort them.
- Observe — read-only observation at every stage boundary; it never influences the request, and a failure here can't break it.
Settlement — metering, charging, and receipts — runs against an immutable context once the request is done.
For the trait signatures and a worked example, see Build a plugin.
How is this guide?