Before you start, fork and clone the gateway repository and confirm that
npm install completes successfully.Overview
Every plugin consists of two required files:manifest.json— declares the plugin’s identity, credentials, and available functions.<functionId>.ts— implements each function declared in the manifest.
*.test.ts file is strongly recommended.
Step-by-step guide
Create the plugin directory
Create a directory under Your plugin directory will look like this when complete:
plugins/ using your plugin’s identifier as the folder name. The name must be lowercase and contain no spaces.Create manifest.json
The manifest describes your plugin and every function it exposes. Create The
plugins/my-guardrail/manifest.json:plugins/my-guardrail/manifest.json
id at the top level must match the directory name and must be unique across all plugins. The id on each function entry is used as both the TypeScript file name and the key in the generated plugins/index.ts.Implement the handler
Create Key points about the handler:
plugins/my-guardrail/blockPhrases.ts. The file name must match the function id in the manifest.plugins/my-guardrail/blockPhrases.ts
- Always initialize
error,verdict, anddatabefore thetryblock. - Use
getText(context, eventType)from../utilsto extract the relevant text — it works across all request types. - Wrap logic in a
try/catchand populateerrorif something goes wrong; never throw from a handler. - Return exactly
{ error, verdict, data }. Transformer plugins also return{ transformedData, transformed }.
Register the plugin in conf.json
Open If your plugin requires credentials (API keys, secrets), add them under the Credentials are injected into
conf.json at the repository root and add your plugin ID to plugins_enabled:conf.json
credentials key:conf.json
parameters.credentials at runtime and are never logged.Build the plugins
Run the build command from the repository root:This command reads
conf.json, imports each enabled plugin’s manifest.json, and regenerates plugins/index.ts with the correct import and export statements for your new handler.Write tests
Create Run the plugin tests:
plugins/my-guardrail/blockPhrases.test.ts:plugins/my-guardrail/blockPhrases.test.ts
Reference: PluginHandler type
Your handler must satisfy thePluginHandler signature from plugins/types.ts:
options argument gives handlers access to environment variables (options.env) and a simple key-value cache (getFromCacheByKey / putInCacheWithValue), which is useful for caching remote API responses such as JWKS keys.
Real-world example: contains.ts
The built-incontains guardrail in plugins/default/contains.ts is a good reference for the complete handler pattern:
plugins/default/contains.ts
Transformer plugins
If your plugin needs to modify the request or response rather than just evaluating it, set"type": "transformer" in the manifest and return transformedData from the handler.
Use the setCurrentContentPart utility from plugins/utils.ts to write modified text back into the payload in a way that correctly handles all request types:
Contributing your plugin
To share your plugin with the community:- Follow the structure above and ensure all tests pass with
npm run test:plugins. - Create a GitHub issue with the title format
[Feature] Your Plugin Namedescribing the plugin’s purpose. - Open a pull request with the title
[New Plugin] Your Plugin Namereferencing your issue.