Skip to content
Hardcount
Run it locally
Pre-1.0 · one maintainer · Stripe and cards only · no SDKs (client libraries) yet · no production users yet. Docs describe v0.12.0 (30 Nov 2026) · What’s new →

Create a plan

POST
/v1/plans
curl --request POST \
--url http://localhost:8080/v1/plans \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: 5f0c8a2e-7b1d-4c3e-9a6f-2d8b4e1c7a90' \
--data '{ "code": "pro", "name": "Pro", "description": "Base fee plus metered tokens.", "currency": "USD", "billing_interval": "monthly", "base_amount_cents": 4900, "base_bill_timing": "in_arrears", "prices": [ { "meter_id": "hc_mtr_dajr122q3gpgqfoq5c10", "mode": "per_unit", "unit_amount_cents": "0.0003" } ] }'

Creates an active plan and its usage prices in one request: if any price is refused, nothing is created. Every price takes the plan’s currency. base_bill_timing is required when the base fee is above 0. The create is written to the audit log.

Idempotency-Key
string
<= 255 characters

Makes the call safe to retry. Send a random UUID, and the same value on every retry. Keys are kept per account and mode, and every API key and dashboard user of the account shares them, so make a key unpredictable. A key over 255 characters is refused with 422 validation_error, param: Idempotency-Key. A request sent with a key runs to its end even if the client disconnects: retry with the same key for its answer. For 24 hours, a repeat from the same caller (the same API key or the same dashboard user) with the same key, method, path, query string and body gets the first response again, byte for byte, with an Idempotent-Replayed: true header, instead of running again. A first answer of 401, 403, 409, 422 or 503, or a 400 invalid JSON body, is not kept, so a retry with the same key runs again. A request to a path or method no route serves holds no key. A repeat sent while the first request is still running gets 409 with code conflict_idempotency at once: retry it in a moment with the same key. The same key from another caller, or with a different method, path, query string or body, is a 422 with code idempotency_error at once, even while the first request runs. The query string must match byte for byte. After 24 hours the key is free, and a request with it runs as new. The other error cases are in Idempotency. The usage routes do not take it: each usage event carries its own idempotency_key. The requests whose answer carries a secret shown only once (creating or rotating an API key, creating a webhook endpoint or rotating its signing secret, rotating a customer’s cost dashboard token, creating a card setup session) do not take it either: Hardcount does not keep that answer.

Example

5f0c8a2e-7b1d-4c3e-9a6f-2d8b4e1c7a90
Media typeapplication/json
object
code
required

Your short name for the plan. Letters, digits, - and _; at most 100 characters; unique in the account and mode. Fixed after create.

string
name
required

The display name. Spaces at the ends are trimmed; then at most 255 bytes (UTF-8).

string
description

Your description of the plan.

string
currency
required

ISO 4217 code, such as USD, stored in upper case. Zero-decimal currencies such as JPY are refused. Fixed after create.

string
billing_interval
required

How often a subscription to the plan is billed. Fixed after create.

string
Allowed values: monthly yearly
base_amount_cents

The recurring base fee per billing period, in the currency’s minor unit (cents for USD). 0 or more; 0 when left out.

integer format: int64
base_bill_timing

Required when base_amount_cents is above 0. With a base of 0 it may be left out, and the plan is in_arrears; in_advance with a base of 0 is refused. See base_bill_timing on Plan.

string
Allowed values: in_advance in_arrears
prices

The plan’s usage prices, created with it in one request. Each takes the plan’s currency.

Array

One price to add to a plan: the body of POST /v1/plans/{id}/prices, and one entry of prices on POST /v1/plans. The meter and labels, then the shape. On POST /v1/plans, a refused field of a price is named with prices[i]. first, such as prices[0].meter_id.

object
meter_id
required

The meter whose usage the price bills. It must be a meter in this account and mode.

string
dimension_match

The labels an event must carry for the price to take it. At most 16 labels. Each key and each value is a string of 1 to 100 bytes (UTF-8), and a key may not be only spaces. Omitted or {} takes every event of the meter. Two prices of one plan and meter that could both take one event with the same number of labels are refused (409 price_conflict).

object
<= 16 properties
key
additional properties
string
mode
required

per_unit bills quantity × unit_amount_cents. graduated bills each tier’s part of the quantity at that tier’s rate. package bills ceil(quantity ÷ package_size) × package_amount_cents: a part package bills as a whole one.

string
Allowed values: per_unit graduated package
unit_amount_cents

Price per unit in cents, as a decimal string (e.g. “0.0003” = $3.00 per 1,000,000 units). Used when mode is per_unit. 0 or more, under 10^18, at most 12 decimal places (trailing zeros do not count), and at most 100 characters. A JSON number is also read. A value outside them is refused with 422 and param naming the field. Invoice line amounts round to whole cents.

string
tiers

Used when mode is graduated. Each up_to is a whole number above the one before. The last tier has up_to: null (no upper bound), and only the last. Otherwise 422 with param tiers. A tier’s rate takes the limits of unit_amount_cents; a refusal names tiers[i].unit_amount_cents (i counts from 0).

Array<object>

One tier of a graduated price.

object
up_to
required

The tier’s upper bound in whole units: the tier prices the quantity above the previous tier’s bound, up to this one. null on the last tier, which has no upper bound. Only the last tier is null, and it must be.

integer format: int64
nullable
unit_amount_cents
required

Price per unit in cents in this tier, as a decimal string. "0" makes the tier free.

string
package_size

Used when mode is package. The units in one package, above 0.

integer format: int64
package_amount_cents

Price of one package in cents, as a decimal string (e.g. “0.2” with package_size 1000 = $0.002 per 1,000 units), with the limits of unit_amount_cents. Used when mode is package.

string
status

Optional. A plan is created active; archive it with PATCH.

string
Allowed values: active
tax_code

A Stripe product tax code, txcd_ and 8 digits, such as txcd_10103001. Empty or omitted leaves it unset. See tax_code on Plan for which invoice lines carry it.

string

Example

{
"code": "pro",
"name": "Pro",
"description": "Base fee plus metered tokens.",
"currency": "USD",
"billing_interval": "monthly",
"base_amount_cents": 4900,
"base_bill_timing": "in_arrears",
"prices": [
{
"meter_id": "hc_mtr_dajr122q3gpgqfoq5c10",
"mode": "per_unit",
"unit_amount_cents": "0.0003"
}
]
}

The new plan, with its prices.

Media typeapplication/json

A plan as get, create and update plan answer it: the plan with its prices, and whether it is used.

object
id
required

The plan’s ID, hc_pln_ and 20 characters.

string
tenant_id

The account the plan belongs to.

string
code
required

Your short name for the plan. Letters, digits, - and _, at most 100 characters, unique in the account and mode. Fixed after create.

string
name
required

The plan’s display name. Create refuses one longer than 255 bytes (UTF-8); an update does not check the length.

string
currency
required

ISO 4217 code in upper case, such as USD. Fixed after create. The plan’s prices take it.

string
billing_interval
required

How often a subscription to the plan is billed. Fixed after create.

string
Allowed values: monthly yearly
status
required

An archived plan takes no new subscriptions and no plan change onto it. Subscriptions already on it keep billing.

string
Allowed values: active archived
base_amount_cents
required

The recurring base fee per billing period, in the currency’s minor unit (cents for USD). 0 for a usage-only plan.

integer format: int64
base_bill_timing
required

When the base fee is invoiced, relative to the period it covers. in_arrears: the base fee and the usage are billed at the period end. in_advance: the base fee is billed at the period start; the first invoice comes when the subscription starts, and each cycle invoice carries the next period’s base fee with the past period’s usage. Usage is always billed at the period end. A plan with no base fee is in_arrears.

string
Allowed values: in_advance in_arrears
prices
required

The plan’s usage prices from now on, in the order they were added. A plan’s meters are the meters it has a price for.

Array<object>

One usage price of a plan: a meter, the events it takes (dimension_match) and its rate. The price takes the plan’s currency. Its id stays the same when its rate changes; its meter and dimension_match are its identity and never change. Every shape field is always sent: the ones the mode does not use are "0", 0 or [].

object
id
required

The price’s ID, hc_prc_ and 20 characters.

string
tenant_id

The account the price belongs to.

string
plan_id
required

The plan the price belongs to.

string
meter_id
required

The meter whose usage the price bills.

string
dimension_match
required

The labels an event must carry for this price to take it, for example {"model": "claude-opus-4.5", "token_type": "input"}. {} takes every event of the meter. Of the prices whose labels an event carries, the one with the most labels takes it.

object
key
additional properties
string
mode
required

How the price bills a quantity; see PriceShape.

string
Allowed values: per_unit graduated package
unit_amount_cents
required

Price per unit, as a decimal string of cents. "0" unless mode is per_unit.

string
tiers
required

Empty ([]) unless mode is graduated.

Array<object>

One tier of a graduated price.

object
up_to
required

The tier’s upper bound in whole units: the tier prices the quantity above the previous tier’s bound, up to this one. null on the last tier, which has no upper bound. Only the last tier is null, and it must be.

integer format: int64
nullable
unit_amount_cents
required

Price per unit in cents in this tier, as a decimal string. "0" makes the tier free.

string
package_size
required

The units in one package. 0 unless mode is package.

integer format: int64
package_amount_cents
required

Price of one package, as a decimal string of cents. "0" unless mode is package.

string
created_at
required

When the price was first added to the plan.

string format: date-time
updated_at
required

When the content shown was saved.

string format: date-time
description

Your description of the plan. Absent when empty.

string
tax_code

A Stripe product tax code, such as txcd_10103001, read only by the Stripe Tax provider. Today only the base fee line of the invoice billed when an in-advance subscription starts carries it; cycle invoices and usage lines use the account’s default_product_tax_code. Absent when not set.

string
created_at
required

When the plan was created.

string format: date-time
updated_at
required

When the plan was last changed.

string format: date-time
used
required

Whether a subscription is on the plan, was on it (canceled ones included), or is scheduled to move to it. A plan that only scheduled plan changes name is no longer used once they are canceled.

On a plan that is not used, a price change applies at once, and base_amount_cents and base_bill_timing can change. On a used plan they are fixed, and a price change applies from each subscriber’s next billing period. A subscriber who first joins the plan in a period after the change gets it from the moment they join.

boolean

Example

{
"id": "hc_pln_dajr5o2q3gpgqfoq5c1g",
"tenant_id": "hc_ten_dajqj02q3gpgqfoq5c00",
"code": "pro",
"name": "Pro",
"description": "Base fee plus metered tokens.",
"currency": "USD",
"billing_interval": "monthly",
"status": "active",
"base_amount_cents": 4900,
"base_bill_timing": "in_arrears",
"prices": [
{
"id": "hc_prc_dajr672q3gpgqfoq5c20",
"tenant_id": "hc_ten_dajqj02q3gpgqfoq5c00",
"plan_id": "hc_pln_dajr5o2q3gpgqfoq5c1g",
"meter_id": "hc_mtr_dajr122q3gpgqfoq5c10",
"dimension_match": {},
"mode": "per_unit",
"unit_amount_cents": "0.0003",
"tiers": [],
"package_size": 0,
"package_amount_cents": "0",
"created_at": "2026-09-15T09:05:00Z",
"updated_at": "2026-09-15T09:05:00Z"
}
],
"created_at": "2026-09-15T09:05:00Z",
"updated_at": "2026-09-15T09:05:00Z",
"used": false
}

The body is not one valid JSON value, it is not a JSON object, it is empty where the operation needs one, or a field has the wrong JSON type (such as a string where a number belongs). This answer is not kept for an Idempotency-Key: send the corrected request with the same key.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

One of invalid_request_error, authentication_error, rate_limit_error or api_error. Every error the API answers has this shape, including an unknown path (404, code route_not_found) and a method the path does not take (405, code method_not_allowed, with an Allow header). The few exceptions are listed in Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter the error is about. Sent only when the error names one.

A request body may hold only the fields its operation lists, spelled and cased as listed. Any other field, or one the server sets (such as id), is refused with 422 and param naming it. An operation with no request body lists no fields: send no body, {} or null. The Stripe and Postmark webhooks and the LiteLLM callback take their sender’s body as it comes.

string

Example

{
"error": {
"type": "invalid_request_error",
"code": "invalid_request",
"message": "invalid JSON body",
"request_id": "req_dbjg652q3gpgqfoq5cd0"
}
}

No valid credential: the API key or session is missing, wrong, expired or revoked. With no API key and no valid session cookie, the message starts with missing credentials. A wrong, expired and revoked key all get the same message, invalid or expired API key.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

One of invalid_request_error, authentication_error, rate_limit_error or api_error. Every error the API answers has this shape, including an unknown path (404, code route_not_found) and a method the path does not take (405, code method_not_allowed, with an Allow header). The few exceptions are listed in Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter the error is about. Sent only when the error names one.

A request body may hold only the fields its operation lists, spelled and cased as listed. Any other field, or one the server sets (such as id), is refused with 422 and param naming it. An operation with no request body lists no fields: send no body, {} or null. The Stripe and Postmark webhooks and the LiteLLM callback take their sender’s body as it comes.

string

Example

{
"error": {
"type": "authentication_error",
"code": "unauthorized",
"message": "invalid or expired API key",
"request_id": "req_dbjg652q3gpgqfoq5cd0"
}
}

The credential is valid but may not call this route. A usage-only key (hc_ingest_…) can only send usage, read a customer’s live credit balance and call GET /v1/whoami; use a secret key. The message names the permission the key lacks. A browser request that would change data (POST, PUT, PATCH or DELETE) from a page on another site gets this 403 too, with the message cross-site request blocked.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

One of invalid_request_error, authentication_error, rate_limit_error or api_error. Every error the API answers has this shape, including an unknown path (404, code route_not_found) and a method the path does not take (405, code method_not_allowed, with an Allow header). The few exceptions are listed in Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter the error is about. Sent only when the error names one.

A request body may hold only the fields its operation lists, spelled and cased as listed. Any other field, or one the server sets (such as id), is refused with 422 and param naming it. An operation with no request body lists no fields: send no body, {} or null. The Stripe and Postmark webhooks and the LiteLLM callback take their sender’s body as it comes.

string

Example

{
"error": {
"type": "authentication_error",
"code": "forbidden",
"message": "insufficient permissions: this key type does not have customer:read access",
"request_id": "req_dbjg652q3gpgqfoq5cd0"
}
}

Nothing is created. already_exists: a plan with this code exists in this account and mode (param: code). price_exists: two prices name the same meter and dimension_match. price_conflict: two prices on one meter could both take one event with the same number of labels, so neither would win; the message names the other price. For both price codes, param is prices[i].dimension_match for the second price.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

One of invalid_request_error, authentication_error, rate_limit_error or api_error. Every error the API answers has this shape, including an unknown path (404, code route_not_found) and a method the path does not take (405, code method_not_allowed, with an Allow header). The few exceptions are listed in Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter the error is about. Sent only when the error names one.

A request body may hold only the fields its operation lists, spelled and cased as listed. Any other field, or one the server sets (such as id), is refused with 422 and param naming it. An operation with no request body lists no fields: send no body, {} or null. The Stripe and Postmark webhooks and the LiteLLM callback take their sender’s body as it comes.

string

Example

{
"error": {
"type": "invalid_request_error",
"code": "already_exists",
"message": "plan code \"pro\" already exists",
"request_id": "req_dbjg652q3gpgqfoq5cd0",
"param": "code"
}
}

The body is over the 1 MB limit. Send a smaller body. The answer is the same with or without an Idempotency-Key, and it is not kept for the key: the same key works for the smaller request.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

One of invalid_request_error, authentication_error, rate_limit_error or api_error. Every error the API answers has this shape, including an unknown path (404, code route_not_found) and a method the path does not take (405, code method_not_allowed, with an Allow header). The few exceptions are listed in Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter the error is about. Sent only when the error names one.

A request body may hold only the fields its operation lists, spelled and cased as listed. Any other field, or one the server sets (such as id), is refused with 422 and param naming it. An operation with no request body lists no fields: send no body, {} or null. The Stripe and Postmark webhooks and the LiteLLM callback take their sender’s body as it comes.

string

Example

{
"error": {
"type": "invalid_request_error",
"code": "payload_too_large",
"message": "The request body is larger than the 1 MB limit. Send a smaller body.",
"request_id": "req_dbjg652q3gpgqfoq5cd0"
}
}

A field failed validation (a price names an unknown meter, a rate is outside its limits, base_bill_timing is missing with a base fee above 0 or is in_advance with a base of 0), status is set to anything but active (a plan is created active; archive it with PATCH), or the body has an unknown field. A failed check on a price’s field names it with prices[i]. first, such as prices[0].unit_amount_cents (i counts from 0). An unknown field is named by its bare key at any depth: price inside a price gives param: price, not prices[0].price.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

One of invalid_request_error, authentication_error, rate_limit_error or api_error. Every error the API answers has this shape, including an unknown path (404, code route_not_found) and a method the path does not take (405, code method_not_allowed, with an Allow header). The few exceptions are listed in Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter the error is about. Sent only when the error names one.

A request body may hold only the fields its operation lists, spelled and cased as listed. Any other field, or one the server sets (such as id), is refused with 422 and param naming it. An operation with no request body lists no fields: send no body, {} or null. The Stripe and Postmark webhooks and the LiteLLM callback take their sender’s body as it comes.

string

Example

{
"error": {
"type": "invalid_request_error",
"code": "validation_error",
"message": "is required when base_amount_cents is above 0: in_advance bills the base fee at the start of each period, in_arrears at the end",
"request_id": "req_dbjg652q3gpgqfoq5cd0",
"param": "base_bill_timing"
}
}

Too many requests. Wait for the number of seconds in Retry-After, then retry. The answers that pass the limit carry the X-RateLimit-* headers too.

Each API key has its own limit, by default 1,000 requests a minute (HARDCOUNT_RATE_LIMIT_GENERAL_PER_MIN), and 1,000 a second on the usage routes (HARDCOUNT_RATE_LIMIT_INGEST_PER_SEC). The dashboard sessions of one account share one limit per mode. The routes under /v1/auth and /v1/bootstrap (sign-in, password reset, invite accept, setup) count per client address, by default 100 a minute (HARDCOUNT_RATE_LIMIT_AUTH_PER_MIN). The public invoice, payment-update and cost-dashboard pages allow 60 a minute per client address.

Media typeapplication/json

The body of an error answer. error.type is the broad class, error.code is the exact reason for your code to branch on, and error.message is a sentence for a person. Quote error.request_id when you ask for help.

object
error

What went wrong.

object
type
required

One of invalid_request_error, authentication_error, rate_limit_error or api_error. Every error the API answers has this shape, including an unknown path (404, code route_not_found) and a method the path does not take (405, code method_not_allowed, with an Allow header). The few exceptions are listed in Errors.

string
code
required

The exact reason, such as validation_error, not_found, already_exists, invalid_state or a more specific code the operation lists. Branch on this, not on message.

string
message
required

What went wrong, written for a person to read.

string
request_id
required

The id of the request that produced this answer (req_…). It is normally the same value as the Hardcount-Request-Id response header. On an answer replayed for a repeated Idempotency-Key, the body is the first request’s, so this is the first request’s id, while the Hardcount-Request-Id header holds the new request’s id.

string
param

The request field or query parameter the error is about. Sent only when the error names one.

A request body may hold only the fields its operation lists, spelled and cased as listed. Any other field, or one the server sets (such as id), is refused with 422 and param naming it. An operation with no request body lists no fields: send no body, {} or null. The Stripe and Postmark webhooks and the LiteLLM callback take their sender’s body as it comes.

string

Example

{
"error": {
"type": "rate_limit_error",
"code": "rate_limited",
"message": "too many requests — please retry after the rate limit resets",
"request_id": "req_dbjg652q3gpgqfoq5cd0"
}
}
Retry-After
integer
Example
12

Seconds to wait before the next request can pass, rounded up to a whole second and at least 1.

X-RateLimit-Limit
integer
Example
1000

How many requests the limit allows in its period (a minute, or a second on the usage routes).

X-RateLimit-Remaining
integer
Example
0

How many requests are left in the current period.

X-RateLimit-Reset
integer format: int64
Example
1793870460

When the whole limit is available again, as Unix seconds. One request may pass sooner; Retry-After says when.

Stuck, or found a bug? Ask in Discussions · Open an issue