Prerequisites
- Install and configure the TypeScript SDK.
- Set
AI_GATEWAY_API_KEYfor your Vercel AI Gateway account, or use Vercel’s supported deployment authentication. - Set
SILMARIL_API_KEYandSILMARIL_API_URLto your provisioned Silmaril classify credentials.
Install the AI SDK
Wrap the gateway model
Verify and enforce
Confirm both input and output classifications appear in Silmaril. The middleware checks input, and the explicitclassify call checks generated text before it is returned.
When ready to enforce, set shadowMode to false and handle FirewallBlockedException before returning a response to the caller. See TypeScript error handling. Handle gateway authentication, model, and network errors separately. A failed request is not a benign verdict.
Coverage
With AI SDK 6, use the explicit output check above instead of relying on the middleware’sscanOutput option. This example protects generated text. Classify tool-call arguments before executing a tool, and buffer streaming output until classification finishes when blocking before delivery is required.
Every protected call must use the wrapped model and the output check. Configuring middleware in one application does not enable a gateway-wide guardrail for other applications or unwrapped calls.