Plans API

Create and manage credit plans, then assign them to accounts. Plans can be archived but never deleted.

About Plans

Plans define credit packages (e.g., "Starter", "Pro", "Enterprise") with recurring or one-time billing. Once created, plans can be assigned to accounts. Plans are archived (not deleted) when no longer needed, preserving historical data.

GET/v1/plans
List all credit plans for your project.

List plans

curl -X GET "https://api.credits.dev/v1/plans" \ -H "X-API-Key: YOUR_API_KEY"

Response

{
  "success": true,
  "plans": [
    {
      "id": "plan_abc123",
      "name": "Pro",
      "description": "For growing applications",
      "credits": 10000,
      "price": 49.99,
      "billingPeriod": "monthly",
      "isActive": true
    }
  ]
}
POST/v1/plans/create
Create a new recurring credit plan. amount must be a positive number; interval must be one of: 1d, week, month.

Create plan

curl -X POST "https://api.credits.dev/v1/plans/create" \ -H "X-API-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Pro", "amount": 10000, "interval": "month", "occurrences": null, "accumulate": true }'

Request Body

{
  "name": "Pro",
  "amount": 10000,
  "interval": "month",
  "occurrences": null,
  "accumulate": true,
  "markAsActive": true
}

Response

{
  "success": true,
  "plan": {
    "id": "plan_abc123",
    "name": "Pro",
    "credits": 10000,
    "interval": "month",
    "isActive": true
  }
}
GET/v1/accounts/plans?accountId=...
Get all plans assigned to a specific account (active and historical).

Get account plans

curl -X GET "https://api.credits.dev/v1/accounts/plans?accountId=acc_123" \ -H "X-API-Key: YOUR_API_KEY"

Response

{
  "success": true,
  "plans": [
    {
      "id": "accountPlan_123",
      "accountId": "acc_123",
      "planId": "plan_abc123",
      "active": true,
      "startedAt": "2024-01-01T00:00:00Z",
      "expiresAt": null,
      "plan": {
        "id": "plan_abc123",
        "name": "Pro",
        "credits": 10000
      }
    }
  ]
}
POST/v1/accounts/plans/assign
Assign a plan to an account. This will deactivate any existing active plan for the account. Use startMode to grant credits immediately (e.g. upgrade) or at the next interval (carry over existing schedule).

Assign plan to account

curl -X POST "https://api.credits.dev/v1/accounts/plans/assign" \ -H "X-API-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "accountId": "acc_123", "planId": "plan_abc123", "startMode": "immediate" }'

Request Body

{
  "accountId": "acc_123",
  "planId": "plan_abc123",
  "startMode": "immediate"
}

Response

{
  "success": true,
  "accountPlan": {
    "id": "accountPlan_123",
    "accountId": "acc_123",
    "planId": "plan_abc123",
    "active": true,
    "startedAt": "2024-01-15T10:00:00Z"
  }
}
POST/v1/accounts/plans/cancel
Cancel an active plan assignment for an account.

Cancel account plan

curl -X POST "https://api.credits.dev/v1/accounts/plans/cancel" \ -H "X-API-Key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "accountPlanId": "accountPlan_123" }'

Request Body

{
  "accountPlanId": "accountPlan_123"
}

Response

{
  "success": true,
  "accountPlan": {
    "id": "accountPlan_123",
    "accountId": "acc_123",
    "active": false,
    "cancelledAt": "2024-01-15T10:00:00Z"
  }
}