Skip to main content

Policy Hub overview

The Policy Hub is the official, curated collection of gateway policies for the WSO2 API Platform. It gives you a growing library of production-ready, versioned policy implementations that you can apply to any API or MCP server without writing custom code.

Policies are self-contained units of behavior that plug into the gateway's request and response pipeline. You compose them, like stacking authentication on top of rate limiting on top of a guardrail, as opposed to building each concern from scratch. If your requisites exceed what the hub provides, you can author and ship your own policies alongside hub ones.

The Policy Hub is powered by an open source repository on GitHub. Every policy is versioned independently, the full source and documentation live in the repo, and contributions are welcome. For more information about contributing policies, see Policy Development Guide.

How Policies Work​

A policy attaches to an API, covering all operations, or to a specific operation, and runs on the request phase, the response phase, or both. Multiple policies chain together on the same API, each one processing the message in sequence before it reaches the next. The gateway evaluates the chain at runtime.

For more information, see API Platform Policies overview.

Policy categories​

Security​

Authenticate incoming requests and secure outbound calls to your backend, using mechanisms such as API keys, OAuth 2.0 (OAuth2), and mutual TLS (mTLS).

PolicyWhat it does
API Key AuthProtects APIs with pre-shared API keys
Basic AuthEnforces HTTP Basic Authentication
JWT AuthValidates JWT access tokens against one or more JWKS providers
Mutual TLS AuthAuthenticates callers by the client certificate they present over mutual TLS, against accepted client certificate authorities
OAuth2 GeneratorGenerates an OAuth 2.0 or static bearer credential and injects it into a configurable request header before forwarding to the backend
OAuth2 Token ExchangeExchanges the caller's credential for a backend-specific token from an external OAuth2 authorization server
CORSHandles preflight requests and injects CORS response headers
Subscription ValidationConfirms the caller holds an active subscription for the target API
Rate Limit - BasicCaps requests per time window
Rate Limit - AdvancedMulti-dimensional quotas with GCRA or fixed-window algorithms, Redis backend support, and weighted limiting

Guardrails​

Control what goes into and out of AI models. Guardrail policies block unsafe prompts in the request pipeline before they reach a model. In the response pipeline, they filter unsafe or non-compliant output before it reaches the caller.

PolicyWhat it does
AWS Bedrock GuardrailValidates content against AWS Bedrock Guardrails
Azure Content SafetyScreens content against Azure Content Safety API
TypeSafe Jev Content SafetyScreens request or response content using TypeSafe AI's Jev System One model
Semantic Prompt GuardBlocks or allows prompts based on semantic similarity to configured allow/deny phrases
Semantic Tool FilteringFilters MCP tools to only those semantically relevant to the user query
TypeSafe Jev Tool FilteringNarrows the tools sent to an LLM to those relevant to the user prompt, using TypeSafe AI's Jev System One model
PII MaskingMasks or redacts PII from request/response bodies using configurable regex patterns
JSON Schema GuardrailEnforces a JSON Schema on request or response payloads
Regex GuardrailValidates content against a regular expression
URL GuardrailValidates URLs found in request or response bodies
Content Length GuardrailEnforces byte-length limits on payloads
Word Count GuardrailEnforces word-count limits on payloads
Sentence Count GuardrailEnforces sentence-count limits on payloads

AI and LLM​

Policies designed specifically for the characteristics of AI APIs — cost, tokens, latency, and prompt structure.

PolicyWhat it does
LLM CostCalculates the monetary cost of each LLM call and stores it for downstream policies
LLM Cost-Based Rate LimitEnforces monetary budget quotas on LLM usage
Token-Based Rate LimitCaps usage by token count rather than request count
Semantic CacheCaches LLM responses using vector similarity, returning cached results for semantically equivalent prompts
Prompt DecoratorInjects system instructions or context into prompts at the gateway layer
Prompt TemplateApplies configurable templates to transform prompts before they reach the model
Prompt CompressorCompresses prompt text to reduce token usage before upstream calls
Model Round RobinDistributes requests evenly across a pool of AI model endpoints
Model Weighted Round RobinDistributes requests across model endpoints according to configured weights
TypeSafe Jev Model RoutingRoutes AI/LLM requests to different models using TypeSafe AI's Jev System One model
RespondReturns an immediate response without forwarding to the upstream backend

MCP (Model Context Protocol)​

A dedicated policy tier for securing and controlling MCP servers — the emerging standard for exposing tools, resources, and prompts to AI agents.

PolicyWhat it does
MCP AuthenticationSecures MCP server traffic per the MCP specification authorization profile
MCP AuthorizationValidates access to MCP tools, resources, and prompts using JWT claims or OAuth scopes
MCP Access ControlControls which tools, resources, and prompts a caller can reach using allow/deny lists
MCP RewriteDefines user-facing tool names and maps them to backend capability names
TypeSafe Jev MCP Tool Intent VerificationScreens MCP tool calls using TypeSafe AI's Jev System One model
TypeSafe Jev MCP Tool Result ScreeningScreens MCP tool results using TypeSafe AI's Jev System One model before the agent reads them

Transformation​

Modify requests and responses in flight.

PolicyWhat it does
Request RewriteRewrites path, query parameters, and HTTP method before forwarding upstream
Host RewriteOverrides the Host/:authority header sent to the upstream
Dynamic EndpointRoutes a request to a named upstream at runtime
Set HeadersAdds or overwrites headers on requests or responses
Remove HeadersStrips specified headers from requests or responses
JSON/XML MediatorConverts payloads between JSON and XML formats
Interceptor ServiceCalls a user-defined HTTP service during the request and/or response phase

Logging, Analytics, and Monitoring​

PolicyWhat it does
Log MessageLogs request/response payload and headers
Analytics Header FilterControls which headers appear in analytics data using allow or deny mode

Common Use Cases​

AI guardrails: Stack prompt-injection detection, PII masking, and a semantic prompt guard on an LLM API to enforce safety and compliance requirements.

LLM cost governance: Combine the LLM Cost policy with LLM Cost-Based Rate Limit to define cost constraints that the gateway enforces transparently.

MCP server security: Apply MCP Authentication, MCP Authorization, and MCP Access Control together to fully secure an MCP server: authenticate the caller, validate their OAuth scopes, and restrict which tools they can invoke.

Semantic caching: Place the Semantic Cache policy on a high-traffic LLM API to serve cached responses for semantically equivalent questions, cutting both latency and cost.

Multi-model routing: Use Model Weighted Round Robin to distribute traffic across model endpoints by weight.

Independent Versioning​

Every policy in the hub is versioned on its own track. When a new version ships, prior versions remain fully available; so running deployments do not break by upon an update.

Extending the Hub​

The API Platform CLI can build a custom gateway image that bundles any combination of hub policies and policies you write yourself. So you can fill your requirement gaps, if any, with local implementations, and contribute them to Policy Hub.

Was this page helpful?