conf.json, and reference them in any config just like the built-in functions. Custom plugins follow the same hook model as the default plugin.
Plugin structure
Each plugin lives in its own subdirectory underplugins/:
Step 1 — Write the manifest
Themanifest.json file declares the plugin identity, any credentials it needs, and the list of functions it exposes.
plugins/my-plugin/manifest.json
Manifest fields
Step 2 — Implement the handler
Create a TypeScript file that exports ahandler function matching the PluginHandler type.
plugins/my-plugin/handler.ts
PluginHandler interface
The full TypeScript signature fromplugins/types.ts:
plugins/types.ts
context contains:
context.request— the raw request body (available inbeforeRequestHook)context.response— the raw response body (available inafterRequestHook)context.requestType—'chatComplete','complete','embed', etc.context.provider— the target provider namecontext.metadata— metadata passed with the request
parameters contains the values the user configured in their guardrail config, plus a credentials key with the values from conf.json.
options provides access to environment variables and a simple key-value cache.
For transformer plugins, set
transformed: true and populate transformedData with the modified request body instead of returning a verdict.Step 3 — Register the plugin
Add your plugin ID to theplugins_enabled array in conf.json at the repository root. If your plugin requires credentials, add them under the credentials key:
conf.json
Step 4 — Build the plugins
Run the build command to compile all enabled plugins into the gateway bundle:Step 5 — Use your plugin in a config
Reference your function as<plugin-id>.<functionId> in any guardrail config:
Step 6 — Write tests
Create a Jest test file alongside your handler. The test command for plugins is:plugins/my-plugin/handler.test.ts
Contributing a plugin to the community
If you’d like to share your plugin with the Portkey community:- Ensure your plugin has test coverage.
- Open an issue with the title
[Feature] Your Plugin Nameon GitHub. - Submit a pull request with the title
[New Plugin] Your Plugin Name.