Gestiona balances de quota durables con el SDK de Commet.
La quota trackea un balance durable y contable que sube y baja a medida que tus clientes crean y eliminan — tareas, números de WhatsApp, automatizaciones en paralelo. Commet incluye un monto con el plan y cobra el excedente por unidad automáticamente.
| Componente | Descripción | Ejemplo |
|---|---|---|
| Feature Code | El recurso de quota que trackeas | tasks, whatsapp_numbers, automations |
| Count | Unidades a agregar, quitar o setear | 5, 10, 50 |
| Billing | El excedente se cobra por unidad en el plan | $1/tarea/mes |
Crea una feature de quota desde Features, luego Create Feature, y elige el tipo Quota. Los feature codes deben crearse antes de usarse. Ve los balances actuales en la página de detalle de suscripción de cada cliente.
Por defecto agrega 1 unidad si se omite count.
await commet.quota.add({
customerId: 'user_123',
featureCode: 'tasks',
count: 5,
})commet.quota.add(
feature_code='tasks',
count=5,
customer_id='user_123',
)customerID := "user_123"
count := 5
client.Quota.Add(ctx, &commet.AddQuotaParams{
FeatureCode: "tasks",
Count: &count,
CustomerID: &customerID,
})commet.quota().add(AddQuotaParams.builder("tasks").customerId("user_123").count(5L).build());$commet->quota->add(
featureCode: 'tasks',
count: 5,
customerId: 'user_123',
);curl -X POST https://commet.co/api/v1/usage/quota \
-H "x-api-key: $COMMET_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"customerId": "user_123",
"featureCode": "tasks",
"count": 5
}'await commet.quota.remove({
customerId: 'user_123',
featureCode: 'tasks',
count: 2,
})commet.quota.remove(
feature_code='tasks',
count=2,
customer_id='user_123',
)customerID := "user_123"
count := 2
client.Quota.Remove(ctx, &commet.RemoveQuotaParams{
FeatureCode: "tasks",
Count: &count,
CustomerID: &customerID,
})commet.quota().remove(RemoveQuotaParams.builder("tasks").customerId("user_123").count(2L).build());$commet->quota->remove(
featureCode: 'tasks',
count: 2,
customerId: 'user_123',
);curl -X DELETE https://commet.co/api/v1/usage/quota \
-H "x-api-key: $COMMET_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"customerId": "user_123",
"featureCode": "tasks",
"count": 2
}'La quota no puede bajar de cero — quitar más que el balance actual devuelve 400 insufficient_balance.
Usa set cuando sincronizas el balance desde tu sistema.
await commet.quota.set({
customerId: 'user_123',
featureCode: 'tasks',
count: 10,
})commet.quota.set(
feature_code='tasks',
count=10,
customer_id='user_123',
)customerID := "user_123"
client.Quota.Set(ctx, &commet.SetQuotaParams{
FeatureCode: "tasks",
Count: 10,
CustomerID: &customerID,
})commet.quota().set(SetQuotaParams.builder("tasks", 10L).customerId("user_123").build());$commet->quota->set(
featureCode: 'tasks',
count: 10,
customerId: 'user_123',
);curl -X PUT https://commet.co/api/v1/usage/quota \
-H "x-api-key: $COMMET_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"customerId": "user_123",
"featureCode": "tasks",
"count": 10
}'const allowance = await commet.quota.get({
customerId: 'user_123',
featureCode: 'tasks',
})allowance = commet.quota.get(
customer_id='user_123',
feature_code='tasks',
)allowance, err := client.Quota.Get(ctx, &commet.GetQuotaAllowanceParams{
CustomerID: "user_123",
FeatureCode: "tasks",
})var allowance = commet.quota()
.get(GetQuotaAllowanceParams.builder("user_123", "tasks").build());$allowance = $commet->quota->get(
customerId: 'user_123',
featureCode: 'tasks',
);curl "https://commet.co/api/v1/usage/quota?customerId=user_123&featureCode=tasks" \
-H "x-api-key: $COMMET_API_KEY"Respuesta:
{
"featureCode": "tasks",
"current": 30,
"included": 50,
"remaining": 20,
"billedQuantity": 0,
"unlimited": false,
"overageEnabled": true
}current es el balance en vivo, included es el monto gratis del plan, remaining es lo que queda antes del excedente, y billedQuantity son las unidades extra cobradas este período. Pasa un ID de Commet (cus_xxx) o tu ID externo como customerId. Se requiere una suscripción activa por cliente.
Devuelve una asignación por cada feature de quota en la suscripción activa del cliente.
const allowances = await commet.quota.getAll({
customerId: 'user_123',
})allowances = commet.quota.get_all(
customer_id='user_123',
)allowances, err := client.Quota.GetAll(ctx, &commet.GetAllQuotaAllowancesParams{
CustomerID: "user_123",
})var allowances = commet.quota()
.getAll(GetAllQuotaAllowancesParams.builder("user_123").build());$allowances = $commet->quota->getAll(
customerId: 'user_123',
);curl "https://commet.co/api/v1/usage/quota/all?customerId=user_123" \
-H "x-api-key: $COMMET_API_KEY"¿Cómo está esta guía?