Skip to main content
POST
/
policies
/
usage-limits
curl --request POST \
  --url https://api.portkey.ai/v1/policies/usage-limits \
  --header 'Content-Type: application/json' \
  --header 'x-portkey-api-key: <api-key>' \
  --data '
{
  "name": "Monthly Cost Limit per API Key",
  "conditions": [
    {
      "key": "workspace_id",
      "value": "workspace-123"
    }
  ],
  "group_by": [
    {
      "key": "api_key"
    }
  ],
  "type": "cost",
  "credit_limit": 1000,
  "alert_threshold": 800,
  "periodic_reset": "monthly"
}
'
{
  "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "object": "policy_usage_limits"
}

Authorizations

x-portkey-api-key
string
header
required

Body

application/json
conditions
object[]
required

Array of conditions that define which requests the policy applies to

Minimum array length: 1
group_by
object[]
required

Array of group by fields that define how usage is aggregated

Minimum array length: 1
type
enum<string>
required

Policy type

Available options:
cost,
tokens
credit_limit
number
required

Maximum usage allowed

Required range: x >= 0
name
string

Policy name

Maximum string length: 255
Example:

"Monthly Cost Limit"

alert_threshold
number | null

Threshold at which to send alerts. Must be less than credit_limit.

Required range: x >= 0
periodic_reset
enum<string> | null

Reset period. If not provided, limit is cumulative.

Available options:
monthly,
weekly
workspace_id
string

Workspace ID or slug. Required if not using API key authentication.

organisation_id
string<uuid>

Organization ID. Required if not using API key authentication.

Response

Policy created successfully

id
string<uuid>

Created policy UUID

object
string

Resource type

Example:

"policy_usage_limits"