Available on Enterprise Self Hosting plan only.Requires 1.17.0 or higher version of the Gateway.
Policies
Policies allow you to set usage limits and rate limits for your workspaces.Policy Types
There are two types of policies you can configure:Control the total usage (cost or tokens) over a period. When the limit is reached, requests will be blocked until the limit resets based on the periodic reset schedule (daily, weekly, or monthly).Use cases:
- Set monthly budget caps per API key
- Limit token consumption per user
- Control costs across teams or projects
Control the rate of requests or tokens per minute/hour/day. When the rate limit is exceeded, requests will be throttled to prevent overuse.Use cases:
- Prevent API abuse with request rate limits
- Control token consumption velocity
- Manage load across different user groups
Policy Structure
All policies share common structural concepts:Conditions
Conditions define which requests the policy applies to. Each condition has akey and value:
Valid keys:
api_key- Apply to a specific API keyworkspace_id- Apply to a workspacemetadata.*- Apply based on custom metadata fields (e.g.,metadata._user,metadata.team)
Group By
Group by defines how usage is aggregated. Each group entry has akey:
Valid keys:
api_key- Group by API keyworkspace_id- Group by workspacemetadata.*- Group by custom metadata fields
Authentication
All policy endpoints require authentication. You can authenticate using:- API Key: Include in
x-portkey-api-keyheader
Permissions
Policies require the following RBAC permissions:policies:create- Create policiespolicies:read- Read policiespolicies:update- Update policiespolicies:delete- Delete policiespolicies:list- List policies
Base URL
All policy endpoints are under:Usage Limits Policies
Usage limits policies allow you to set maximum usage (cost or tokens) that can be consumed over a period. When the limit is reached, requests will be blocked until the limit resets.Policy structure
A descriptive name for the policy to help identify its purpose.
Defines which requests the policy applies to. Must be a non-empty array of condition objects. See Conditions section above for valid keys.
Defines how usage is aggregated. Must be a non-empty array of group objects. See Group By section above for valid keys.
The type of usage to limit. Valid values:
cost- Limit based on total cost in dollarstokens- Limit based on total tokens consumed
The maximum usage allowed. For
cost type, this is in dollars. For tokens type, this is the number of tokens.Optional threshold to trigger alerts before the limit is reached. Must be less than
credit_limit.How often the usage counter resets. Valid values:
daily- Resets every day at midnight UTCweekly- Resets every Monday at midnight UTCmonthly- Resets on the first day of each month at midnight UTC
Validation Rules
- Conditions: Must be a non-empty array. Each condition must have
keyandvaluefields. - Group By: Must be a non-empty array. Each group must have a
keyfield. - Valid Keys: For both
conditionsandgroup_by, valid keys are:api_keyworkspace_id- Any key starting with
metadata.(e.g.,metadata._user)
- Alert Threshold: Must be less than
credit_limitif provided. - Workspace: Workspace ID is required (can be provided via API key or request body).
Examples
- Monthly cost limit per API key
- Token limit by user
Limit each API key to $1000 per month:
Rate Limits Policies
Rate limits policies allow you to control the rate of requests or tokens consumed per minute, hour, or day. When the rate limit is exceeded, requests will be throttled.Policy structure
A descriptive name for the policy to help identify its purpose.
Defines which requests the policy applies to. Must be a non-empty array of condition objects. See Conditions section above for valid keys.
Defines how rate limits are aggregated. Must be a non-empty array of group objects. See Group By section above for valid keys.
The type of rate limit. Valid values:
requests- Limit based on number of requeststokens- Limit based on number of tokens
The time unit for the rate limit. Valid values:
rpm- Requests or tokens per minuterph- Requests or tokens per hourrpd- Requests or tokens per day
The maximum number of requests or tokens allowed per time unit.
Validation Rules
- Conditions: Must be a non-empty array. Each condition must have
keyandvaluefields. - Group By: Must be a non-empty array. Each group must have a
keyfield. - Valid Keys: For both
conditionsandgroup_by, valid keys are:api_keyworkspace_id- Any key starting with
metadata.(e.g.,metadata._user)
- Value: Must be a numeric value.
- Workspace: Workspace ID is required (can be provided via API key or request body).
Examples
- Requests per minute per API key
- Tokens per hour by user
- Daily request limit
Limit each API key to 100 requests per minute:

