CEL reference overview
Common Expression Language (CEL) is a fast, safe expression language used throughout Agentgateway to evaluate user-defined expressions against live request data. CEL expressions are evaluated at request time against a rich context of variables describing the request, response, authentication state, and more. CEL is not as general-purpose as Lua or WASM, but it is significantly faster and sufficient for the majority of gateway policy use cases.Where CEL is used
Agentgateway uses CEL in several places across the request processing pipeline:- Authorization rules — define which requests are allowed or denied
- Rate limiting conditions — select the attribute to rate limit on (for example, per user or per API key)
- Logs and traces — define which request attributes to include as structured fields
- Header and body transformations — compute new header or body values
- MCP authorization — control which MCP tools, prompts, and resources a caller can access
Expression syntax
CEL expressions are single-line expressions that evaluate to a value. They support:Available context objects
Agentgateway exposes the following top-level objects to CEL expressions. Not all objects are available in all contexts — for example,response is not available during a request-phase transformation, and mcp is only present for MCP requests.
Agentgateway uses static analysis at configuration load time to determine which context fields your expressions reference. Fields that are not referenced are not collected, so you only pay for what you use. This is especially important for
request.body and response.body, which require buffering.Practical examples
Custom CEL functions
Agentgateway extends CEL with custom functions beyond the standard library.JSON and encoding
JSON and encoding
JWT and authentication
JWT and authentication
Control flow and variables
Control flow and variables
Map and collection utilities
Map and collection utilities
String and regex
String and regex
Standard library highlights
Standard library highlights
All standard CEL functions are available, including collections (
contains, size, has, map, filter, all, exists), type conversion (string, bytes, double, int, uint), strings (startsWith, endsWith, matches, trim, replace, split, substring), time functions (duration, timestamp, getFullYear, getMonth), and IP/CIDR helpers (isIP, ip, cidr).Header views
Therequest.headers and response.headers objects expose chainable methods for common header access patterns:
Query string access
request.pathAndQuery and request.uri expose query-aware methods:
Reference pages
Request context
Full reference for
request, response, source, env, jwt, apiKey, basicAuth, backend, and metadata objects.MCP context
Full reference for the
mcp object: tools, prompts, and resources.LLM context
Full reference for the
llm object: model, token counts, prompt, completion, and parameters.