Gravitee Custom Policies
Sam
a month ago
Summary
I explain how to extend Gravity's AI Agent Management Gateway beyond its 77 built‑in policies by creating a custom per‑user token budget policy in Java. I describe why the default token‑rate limit (per key) doesn't fit scenarios where the user identifier lives in the request body, and show how my policy tracks individual budgets in a sliding‑window cache (Hazelcast or Redis) and dynamically routes over‑budget requests to a smaller model instead of returning a 429 error. I walk through packaging the policy as a JAR, deploying it via existing CI/CD pipelines, and configuring it through the UI or management API. Finally, I demonstrate the policy in action with Alice and Bob, illustrate the full observability stack, and highlight that custom policies integrate seamlessly with Gravity's dashboards and logs, making governance and FinOps controls easy to add.