Create a plan
const url = 'http://localhost:8080/v1/plans';const options = { method: 'POST', headers: { 'Idempotency-Key': '5f0c8a2e-7b1d-4c3e-9a6f-2d8b4e1c7a90', Authorization: 'Bearer <token>', 'Content-Type': 'application/json' }, body: '{"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"}]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}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_ is required when the base fee is above 0.
The create is written to the audit log.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”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_, 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_ 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_ 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_.
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-2d8b4e1c7a90Request Bodyrequired
Section titled “Request Bodyrequired”object
Your short name for the plan. Letters, digits, - and
_; at most 100 characters; unique in the account and
mode. Fixed after create.
The display name. Spaces at the ends are trimmed; then at most 255 bytes (UTF-8).
Your description of the plan.
ISO 4217 code, such as USD, stored in upper case.
Zero-decimal currencies such as JPY are refused. Fixed
after create.
How often a subscription to the plan is billed. Fixed after create.
The recurring base fee per billing period, in the currency’s minor unit (cents for USD). 0 or more; 0 when left out.
Required when base_ is above 0. With a base
of 0 it may be left out, and the plan is in_arrears;
in_ with a base of 0 is refused. See
base_ on Plan.
The plan’s usage prices, created with it in one request. Each takes the plan’s currency.
One price to add to a plan: the body of
POST /, and one entry of prices on
POST /. The meter and labels, then the shape. On
POST /, a refused field of a price is named with
prices[i]. first, such as prices[0]..
object
The meter whose usage the price bills. It must be a meter in this account and mode.
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_).
object
per_ bills quantity × unit_. graduated bills each tier’s part of the quantity at that tier’s rate. package bills ceil(quantity ÷ package_) × package_: a part package bills as a whole one.
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_. 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.
Used when mode is graduated. Each up_to is a whole number above the one before. The last tier has up_ (no upper bound), and only the last. Otherwise 422 with param tiers. A tier’s rate takes the limits of unit_; a refusal names tiers[i]. (i counts from 0).
One tier of a graduated price.
object
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.
Price per unit in cents in this tier, as a decimal string. "0"
makes the tier free.
Used when mode is package. The units in one package, above 0.
Price of one package in cents, as a decimal string (e.g. “0.2” with package_ 1000 = $0.002 per 1,000 units), with the limits of unit_. Used when mode is package.
Optional. A plan is created active; archive it with PATCH.
A Stripe product tax code, txcd_ and 8 digits, such as
txcd_. Empty or omitted leaves it unset. See
tax_ on Plan for which invoice lines carry it.
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" } ]}Responses
Section titled “Responses”The new plan, with its prices.
A plan as get, create and update plan answer it: the plan with its prices, and whether it is used.
object
The plan’s ID, hc_pln_ and 20 characters.
The account the plan belongs to.
Your short name for the plan. Letters, digits, - and _, at
most 100 characters, unique in the account and mode. Fixed
after create.
The plan’s display name. Create refuses one longer than 255 bytes (UTF-8); an update does not check the length.
ISO 4217 code in upper case, such as USD. Fixed after create.
The plan’s prices take it.
How often a subscription to the plan is billed. Fixed after create.
An archived plan takes no new subscriptions and no plan change onto it. Subscriptions already on it keep billing.
The recurring base fee per billing period, in the currency’s minor unit (cents for USD). 0 for a usage-only plan.
When the base fee is invoiced, relative to the period it
covers. in_: the base fee and the usage are billed at
the period end. in_: 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_.
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.
One usage price of a plan: a meter, the events it takes
(dimension_) and its rate. The price takes the plan’s
currency. Its id stays the same when its rate changes; its meter
and dimension_ are its identity and never change. Every
shape field is always sent: the ones the mode does not use are
"0", 0 or [].
object
The price’s ID, hc_prc_ and 20 characters.
The account the price belongs to.
The plan the price belongs to.
The meter whose usage the price bills.
The labels an event must carry for this price to take it, for
example {"model": "claude-opus-4..
{} takes every event of the meter. Of the prices whose labels
an event carries, the one with the most labels takes it.
object
How the price bills a quantity; see PriceShape.
Price per unit, as a decimal string of cents. "0" unless mode
is per_.
Empty ([]) unless mode is graduated.
One tier of a graduated price.
object
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.
Price per unit in cents in this tier, as a decimal string. "0"
makes the tier free.
The units in one package. 0 unless mode is package.
Price of one package, as a decimal string of cents. "0" unless
mode is package.
When the price was first added to the plan.
When the content shown was saved.
Your description of the plan. Absent when empty.
A Stripe product tax code, such as txcd_, 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_. Absent when not set.
When the plan was created.
When the plan was last changed.
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_ and base_ 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.
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.
The body of an error answer. error. is the broad class,
error. is the exact reason for your code to branch on, and
error. is a sentence for a person. Quote
error. when you ask for help.
object
What went wrong.
object
One of invalid_, authentication_,
rate_ or api_. Every error the API
answers has this shape, including an unknown path (404,
code route_) and a method the path does not take
(405, code method_, with an Allow header).
The few exceptions are listed in
Errors.
The exact reason, such as validation_, not_,
already_, invalid_ or a more specific code
the operation lists. Branch on this, not on message.
What went wrong, written for a person to read.
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.
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.
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.
The body of an error answer. error. is the broad class,
error. is the exact reason for your code to branch on, and
error. is a sentence for a person. Quote
error. when you ask for help.
object
What went wrong.
object
One of invalid_, authentication_,
rate_ or api_. Every error the API
answers has this shape, including an unknown path (404,
code route_) and a method the path does not take
(405, code method_, with an Allow header).
The few exceptions are listed in
Errors.
The exact reason, such as validation_, not_,
already_, invalid_ or a more specific code
the operation lists. Branch on this, not on message.
What went wrong, written for a person to read.
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.
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.
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_) can only send usage, read a customer’s live
credit balance and call GET /; 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.
The body of an error answer. error. is the broad class,
error. is the exact reason for your code to branch on, and
error. is a sentence for a person. Quote
error. when you ask for help.
object
What went wrong.
object
One of invalid_, authentication_,
rate_ or api_. Every error the API
answers has this shape, including an unknown path (404,
code route_) and a method the path does not take
(405, code method_, with an Allow header).
The few exceptions are listed in
Errors.
The exact reason, such as validation_, not_,
already_, invalid_ or a more specific code
the operation lists. Branch on this, not on message.
What went wrong, written for a person to read.
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.
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.
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_: a plan with this code
exists in this account and mode (param: code). price_:
two prices name the same meter and dimension_.
price_: 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]. for the second price.
The body of an error answer. error. is the broad class,
error. is the exact reason for your code to branch on, and
error. is a sentence for a person. Quote
error. when you ask for help.
object
What went wrong.
object
One of invalid_, authentication_,
rate_ or api_. Every error the API
answers has this shape, including an unknown path (404,
code route_) and a method the path does not take
(405, code method_, with an Allow header).
The few exceptions are listed in
Errors.
The exact reason, such as validation_, not_,
already_, invalid_ or a more specific code
the operation lists. Branch on this, not on message.
What went wrong, written for a person to read.
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.
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.
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.
The body of an error answer. error. is the broad class,
error. is the exact reason for your code to branch on, and
error. is a sentence for a person. Quote
error. when you ask for help.
object
What went wrong.
object
One of invalid_, authentication_,
rate_ or api_. Every error the API
answers has this shape, including an unknown path (404,
code route_) and a method the path does not take
(405, code method_, with an Allow header).
The few exceptions are listed in
Errors.
The exact reason, such as validation_, not_,
already_, invalid_ or a more specific code
the operation lists. Branch on this, not on message.
What went wrong, written for a person to read.
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.
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.
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_ is missing with a base
fee above 0 or is in_ 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]. (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]..
The body of an error answer. error. is the broad class,
error. is the exact reason for your code to branch on, and
error. is a sentence for a person. Quote
error. when you ask for help.
object
What went wrong.
object
One of invalid_, authentication_,
rate_ or api_. Every error the API
answers has this shape, including an unknown path (404,
code route_) and a method the path does not take
(405, code method_, with an Allow header).
The few exceptions are listed in
Errors.
The exact reason, such as validation_, not_,
already_, invalid_ or a more specific code
the operation lists. Branch on this, not on message.
What went wrong, written for a person to read.
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.
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.
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_), and 1,000 a second on the
usage routes (HARDCOUNT_). The dashboard
sessions of one account share one limit per mode. The routes under
/ and / (sign-in, password reset, invite
accept, setup) count per client address, by default 100 a minute
(HARDCOUNT_). The public invoice,
payment-update and cost-dashboard pages allow 60 a minute per client
address.
The body of an error answer. error. is the broad class,
error. is the exact reason for your code to branch on, and
error. is a sentence for a person. Quote
error. when you ask for help.
object
What went wrong.
object
One of invalid_, authentication_,
rate_ or api_. Every error the API
answers has this shape, including an unknown path (404,
code route_) and a method the path does not take
(405, code method_, with an Allow header).
The few exceptions are listed in
Errors.
The exact reason, such as validation_, not_,
already_, invalid_ or a more specific code
the operation lists. Branch on this, not on message.
What went wrong, written for a person to read.
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.
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.
Example
{ "error": { "type": "rate_limit_error", "code": "rate_limited", "message": "too many requests — please retry after the rate limit resets", "request_id": "req_dbjg652q3gpgqfoq5cd0" }}Headers
Section titled “Headers”Example
12Seconds to wait before the next request can pass, rounded up to a whole second and at least 1.
Example
1000How many requests the limit allows in its period (a minute, or a second on the usage routes).
Example
0How many requests are left in the current period.
Example
1793870460When 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