Skip to main content
POST
/
v1
/
credit-grants
curl -X POST "https://api.flexprice.io/v1/credit-grants" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Welcome Bonus",
    "scope": "SUBSCRIPTION",
    "subscription_id": "sub_1234",
    "credits": "100.00",
    "cadence": "ONETIME",
    "expiration_type": "DURATION",
    "expiration_duration": 30,
    "expiration_duration_unit": "DAYS",
    "start_date": "2024-01-15T00:00:00Z",
    "conversion_rate": "1",
    "priority": 1
  }'
{
  "id": "cg_abc123xyz",
  "name": "Welcome Bonus",
  "scope": "SUBSCRIPTION",
  "subscription_id": "sub_1234",
  "credits": "100.00000000",
  "cadence": "ONETIME",
  "expiration_type": "DURATION",
  "expiration_duration": 30,
  "expiration_duration_unit": "DAYS",
  "start_date": "2024-01-15T00:00:00Z",
  "conversion_rate": "1.00000",
  "priority": 1,
  "metadata": {},
  "created_at": "2024-01-15T10:00:00Z",
  "updated_at": "2024-01-15T10:00:00Z"
}

Request Body

name
string
required
Human-readable name for the credit grant (e.g., “Welcome Bonus”, “Q1 2024 Credits”)
scope
string
required
Scope of the credit grantValues:
  • PLAN: Credits apply to all subscriptions of a specific plan
  • SUBSCRIPTION: Credits apply to a specific subscription
plan_id
string
Required if scope is PLAN. The ID of the plan this grant applies to.
subscription_id
string
Required if scope is SUBSCRIPTION. The ID of the subscription this grant applies to.
credits
string
required
Number of credits to grant (must be greater than zero)
cadence
string
required
How credits are appliedValues:
  • ONETIME: Credits are applied once
  • RECURRING: Credits are applied repeatedly based on period
period
string
Required if cadence is RECURRING. The recurring period.Values: DAILY, WEEKLY, MONTHLY, QUARTERLY, YEARLY
period_count
integer
Required if cadence is RECURRING. Number of periods for recurring grants (must be > 0)
expiration_type
string
required
How credits expireValues:
  • NEVER: Credits never expire
  • DURATION: Credits expire after a specific duration
  • BILLING_CYCLE: Credits expire at the end of the billing cycle
expiration_duration
integer
Required if expiration_type is DURATION. Duration before expiration (must be > 0)
expiration_duration_unit
string
Required if expiration_type is DURATION. Unit for expiration duration.Values: DAYS, WEEKS, MONTHS, YEARS
start_date
string
Required if scope is SUBSCRIPTION. Start date for the credit grant (ISO 8601 format)Not allowed for PLAN-scoped grants.
end_date
string
Optional for SUBSCRIPTION scope. End date for the credit grant (ISO 8601 format)Must be >= start_date if provided. Not allowed for PLAN-scoped grants.
conversion_rate
string
Conversion rate from credits to currency during consumptionExample: If “2”, then 1 credit = 0.5 currency units
topup_conversion_rate
string
Conversion rate for top-ups (e.g., how many credits per currency unit when loading)
priority
integer
Priority for credit consumption (lower number = higher priority)Credits with lower priority numbers are consumed first.
metadata
object
Custom metadata as key-value pairs

Response

id
string
Unique identifier for the credit grant
name
string
Name of the credit grant
scope
string
Scope of the grant (PLAN or SUBSCRIPTION)
plan_id
string
ID of the plan (if scope is PLAN)
subscription_id
string
ID of the subscription (if scope is SUBSCRIPTION)
credits
string
Number of credits granted
cadence
string
Cadence of the grant (ONETIME or RECURRING)
period
string
Period for recurring grants
period_count
integer
Number of periods for recurring grants
expiration_type
string
How credits expire (NEVER, DURATION, or BILLING_CYCLE)
expiration_duration
integer
Duration before expiration (if expiration_type is DURATION)
expiration_duration_unit
string
Unit for expiration duration
start_date
string
Start date for the grant (subscription-scoped only)
end_date
string
End date for the grant (subscription-scoped only)
conversion_rate
string
Conversion rate from credits to currency
topup_conversion_rate
string
Conversion rate for top-ups
priority
integer
Priority for credit consumption
metadata
object
Custom metadata
created_at
string
Timestamp when grant was created
updated_at
string
Timestamp when grant was last updated
curl -X POST "https://api.flexprice.io/v1/credit-grants" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Welcome Bonus",
    "scope": "SUBSCRIPTION",
    "subscription_id": "sub_1234",
    "credits": "100.00",
    "cadence": "ONETIME",
    "expiration_type": "DURATION",
    "expiration_duration": 30,
    "expiration_duration_unit": "DAYS",
    "start_date": "2024-01-15T00:00:00Z",
    "conversion_rate": "1",
    "priority": 1
  }'
{
  "id": "cg_abc123xyz",
  "name": "Welcome Bonus",
  "scope": "SUBSCRIPTION",
  "subscription_id": "sub_1234",
  "credits": "100.00000000",
  "cadence": "ONETIME",
  "expiration_type": "DURATION",
  "expiration_duration": 30,
  "expiration_duration_unit": "DAYS",
  "start_date": "2024-01-15T00:00:00Z",
  "conversion_rate": "1.00000",
  "priority": 1,
  "metadata": {},
  "created_at": "2024-01-15T10:00:00Z",
  "updated_at": "2024-01-15T10:00:00Z"
}

Credit Grant Scopes

Credits granted at the plan level apply to all subscriptions using that plan.Use cases:
  • Included credits in a plan (e.g., “Enterprise plan includes 1000 API calls/month”)
  • Plan-level promotions
  • Standard credit allotments
Characteristics:
  • Automatically applied to new subscriptions
  • Cannot specify start/end dates (tied to subscription lifecycle)
  • Ideal for recurring credits that are part of the plan definition
Credits granted to a specific subscription.Use cases:
  • One-time promotional credits for a customer
  • Compensation credits
  • Custom credit agreements
  • Trial period bonuses
Characteristics:
  • Requires start_date
  • Optional end_date for time-limited grants
  • Applied only to the specified subscription
  • Flexible scheduling and expiration

Expiration Types

NEVER

Credits never expire. Suitable for purchased credits or permanent grants.

DURATION

Credits expire after a specific duration (e.g., 30 days, 6 months).

BILLING_CYCLE

Credits expire at the end of the current billing cycle. Common for monthly allowances.

Recurring Credit Grants

Recurring credit grants automatically apply credits at regular intervals:
For recurring grants, FlexPrice automatically schedules credit applications. You don’t need to manually create credits each period.