Skip to content
Go To Dashboard

Create a new rule

POST https://api.sapiom.ai/v1/spending-rules

Requires Bearer authentication — pass a JWT token or API key in the Authorization header.

ruleType — Type of rule:

ValueDescription
usage_limitLimit based on count or amount thresholds
spending_limitAlias for usage_limit with spend focus

conditions[].fieldType — What dimension to evaluate:

ValueDescription
serviceMatch by service name (e.g., “openai”, “linkup”)
actionMatch by action type
resourceMatch by resource identifier
qualifierMatch by qualifier value
transaction_propertyMatch by transaction metadata
payment_propertyMatch by payment metadata

conditions[].operator — Comparison operator:

ValueDescription
equalsExact match
not_equalsDoes not match
containsContains substring
not_containsDoes not contain substring
greater_thanNumeric greater than
less_thanNumeric less than

parameters[].measurementType — What to measure:

ValueDescription
count_transactionsCount of transactions
sum_payment_amountSum of payment amounts in USD (most common for budget caps)
this_payment_amountAmount of the current payment
sum_transaction_costsSum of transaction costs
this_transaction_costCost of the current transaction

parameters[].intervalUnit — Time window:

ValueDescription
minutesPer-minute window
hoursPer-hour window
daysPer-day window
weeksPer-week window
monthsPer-month window

agentIds — Optional array of agent UUIDs. When set, the rule only applies to these specific agents. Omit to apply to all agents in the tenant.

The most common use case — limit an agent to $10/day:

{
"name": "$10 daily budget",
"ruleType": "usage_limit",
"resolutionStrategy": "automatic",
"conditions": [],
"parameters": [
{
"parameterName": "Daily spend cap",
"limitValue": "10",
"measurementType": "sum_payment_amount",
"intervalValue": 24,
"intervalUnit": "hours",
"isRolling": true,
"groupBy": ["agent"],
"measurementScope": "all",
"description": "Cap total spend at $10 per 24h"
}
],
"agentIds": ["550e8400-e29b-41d4-a716-446655440000"]
}
{
"name": "Daily transaction limit",
"ruleType": "usage_limit",
"resolutionStrategy": "automatic",
"conditions": [
{
"fieldType": "service",
"fieldName": "openai",
"operator": "equals",
"value": "openai",
"conditionGroup": "primary"
}
],
"parameters": [
{
"parameterName": "Max daily transactions",
"limitValue": "100",
"measurementType": "count_transactions",
"intervalValue": 24,
"intervalUnit": "hours",
"isRolling": true,
"groupBy": ["agent"],
"measurementScope": "all",
"description": "Limits total API calls per day"
}
],
"agentIds": ["550e8400-e29b-41d4-a716-446655440000"]
}
Terminal window
curl -X POST "https://api.sapiom.ai/v1/spending-rules" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Daily spending limit",
"ruleType": "usage_limit",
"resolutionStrategy": "automatic",
"metadata": {
"category": "finance"
},
"conditions": [
{
"fieldType": "service",
"fieldName": "openai",
"operator": "equals",
"value": "openai",
"conditionGroup": "primary"
}
],
"parameters": [
{
"parameterName": "Max daily transactions",
"limitValue": "100",
"measurementType": "count_transactions",
"intervalValue": 24,
"intervalUnit": "hours",
"isRolling": true,
"groupBy": [
"agent"
],
"measurementScope": "all",
"description": "Limits total API calls per day"
}
],
"agentIds": [
"550e8400-e29b-41d4-a716-446655440000"
]
}'
{
"id": "string",
"tenantId": "string",
"numericId": 0,
"formattedId": "string",
"name": "string",
"ruleType": "usage_limit",
"resolutionStrategy": "automatic",
"status": "active",
"version": 0,
"metadata": null,
"createdAt": "2025-01-15T10:30:00Z",
"updatedAt": "2025-01-15T10:30:00Z"
}
StatusCodeDescription
400-Invalid request data
401-Unauthorized - invalid or missing authentication
403-Forbidden - insufficient permissions

See API Introduction for error handling details.