Inference hooks let organizations attach custom HTTP endpoints that run immediately before and after LLM inference. Pre-hooks can inspect and mutate the request body; post-hooks can inspect and mutate the final response.

How hooks work

The LLM gateway loads hook configuration from the llm_inference_hooks table for the active organization. When configured:
  • Pre-inference hook — Called with the original request body before routing to a provider. A successful hook may return a replacement body. A non-success response can abort the request when abort_on_pre_error is enabled.
  • Post-inference hook — Called with the request body and provider response after inference completes. A successful hook may return a replacement response body.
  • Streaming post-hook — For streaming responses, where the body is not available for mutation, a best-effort hook fires with the request and streaming metadata.

Authentication and authorization

Hook configuration is managed through the LLM gateway admin endpoints, which require a Clerk JWT and organization owner or admin role.

Configure hooks

Endpoints

Get configuration

Response 200 OK

Set configuration

Response 200 OK
If no hook secret exists, one is generated automatically and returned in the response.

Remove configuration

Response 200 OK

Hook payload and signature

Every hook request includes the payload body and an HMAC-SHA256 signature in the X-Allternit-Hook-Signature header.
Verify the signature using the hook_secret:

Post-hook payload

Post-hooks receive a JSON envelope containing the original request and provider response:
For streaming responses, the post-hook payload indicates that the response was streaming:

Hook behavior

Pre-hook outcomes

Post-hook outcomes

Error codes