Code Examples
This page collects concrete examples for the surrounding guide area.
Dynamic Header Injection
Use an LLM request intercept when a plugin needs to inject tenant or routing metadata into every provider request.
LLM request intercepts receive three arguments: name, request, and annotated. The request object is immutable, however it is possible to return a new instance of the request with edits, the exception to this is when the intercept is written in Rust.
Python
Node.js
This pattern is useful for:
- Tenant identity
- Trace correlation
- Region or deployment routing
OpenInference Export
Use a subscriber-oriented plugin when the component should watch the full lifecycle rather than rewrite requests.
Python
Node.js
This is the right pattern when the component:
- Exports traces or metrics
- Aggregates events across tools and LLMs
- Should not change execution behavior
Multi-Surface Policy Bundle
A plugin can register more than one runtime surface when one configuration document controls a related behavior bundle.
For example, a policy bundle can install:
- A telemetry subscriber
- LLM request intercepts for request metadata
- Tool guardrails for policy enforcement
- Sanitize guardrails for exported payloads
- Shared component-local state used by those hooks
Use this pattern when the configured behavior is easier to reason about as one component than as several unrelated plugin components. Keep each registered surface small and make the component config explicit about which surfaces are enabled.
Framework-Facing Plugins
Plugins can stay framework-agnostic if they operate on the normalized runtime data rather than framework-specific objects.
Good examples:
- Rewrite provider headers
- Emit tracing data
- Attach scheduling hints
- Apply cross-framework safety policies