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 subscription

POST
/v1/subscriptions
curl --request POST \
--url http://localhost:8080/v1/subscriptions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: 5f0c8a2e-7b1d-4c3e-9a6f-2d8b4e1c7a90' \
--data '{ "code": "acme-pro", "display_name": "Acme Pro", "customer_id": "hc_cus_dakhnk2q3gpgqfoq5c0g", "plan_id": "hc_pln_dajr5o2q3gpgqfoq5c1g", "billing_time": "calendar" }'

Creates a subscription that bills a customer for one plan. It starts now, active from today: its first period starts today in the account’s billing time zone. A customer who needs two plans gets two subscriptions.

The plan’s currency must match the customer’s billing profile and the customer’s other active subscriptions; canceled ones do not count. The customer may have no other active subscription on the plan or scheduled to move to it, and the plan may not bill a meter that another active subscription of the customer bills. The customer and the plan must not be archived.

A subscription whose plan bills a non-zero base fee in advance is saved together with its first invoice, in one database transaction: both are saved, or neither is. The invoice is then collected like any other invoice.

Sends the subscription.created webhook event.

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 code for the subscription: letters, digits, hyphens and underscores. Unique in your account and mode.

string
display_name
required

The subscription’s name. Must not be blank.

string
customer_id
required

The customer to bill (hc_cus_…), in this account and mode.

string
plan_id
required

The plan to bill, a plan of this account and mode (hc_pln_…).

string
billing_time

How monthly periods line up. See the subscription’s billing_time.

string
default: calendar
Allowed values: calendar anniversary

Example

{
"code": "acme-pro",
"display_name": "Acme Pro",
"customer_id": "hc_cus_dakhnk2q3gpgqfoq5c0g",
"plan_id": "hc_pln_dajr5o2q3gpgqfoq5c1g",
"billing_time": "calendar"
}

Subscription created

Media typeapplication/json

A customer’s subscription: the plan it bills, a plan change scheduled for the end of the current period, its status and its current billing period. Every route under /v1/subscriptions that returns a subscription returns this object.

A subscription bills in one currency, the currency of its plan. A customer who needs two plans has two subscriptions. A customer has at most one active subscription on a plan, and two may not bill the same meter. Usage, and a base fee billed in arrears, are invoiced when a period ends. A base fee billed in advance is invoiced when its period starts: the first one in the same transaction that creates the subscription, each later one on the invoice that closes the period before.

object
id
required

The subscription’s ID (hc_sub_…).

string
tenant_id

The account the subscription belongs to.

string
code
required

Your code for the subscription: letters, digits, hyphens and underscores. Unique in your account and mode (live or test).

string
display_name
required

The subscription’s name, as shown in the dashboard.

string
customer_id
required

The customer the subscription bills (hc_cus_…).

string
plan_id

The plan the subscription bills now (hc_pln_…): its base fee and its usage prices. A scheduled plan change shows in pending_plan_id until it takes effect. Absent only on a canceled subscription that an earlier release left with no plan.

string
pending_plan_id

The plan the subscription moves to at pending_plan_effective_at (hc_pln_…). Absent when no change is scheduled.

string
pending_plan_effective_at

When the scheduled plan change takes effect: the end of the period in which it was scheduled. Absent when no change is scheduled.

string format: date-time
status
required

Where the subscription is in its life.

  • active: billing, from the start of the day it is created (in the account’s time zone). Usage and base fees billed in arrears are invoiced when each period ends; a base fee billed in advance when its period starts.
  • canceled: ended at canceled_at. It bills nothing more, and no route makes it active again. A subscription canceled before it started has no started_at and no billing period.
string
Allowed values: active canceled
billing_time
required

How monthly periods line up. The first period starts on the day the subscription is created. calendar: every period ends on the 1st of a month, in your account’s billing time zone, so the first period runs from that day to the next 1st. anniversary: each period starts on the same day of the month as the first one (the last day of a shorter month). A plan billed yearly always bills a year from that first day, whatever this says.

string
Allowed values: calendar anniversary
started_at

The moment the subscription was created. Its first period, and the usage it bills, start at the beginning of that day in the account’s time zone. A subscription that an earlier release activated from a draft has the moment of that activation instead.

string format: date-time
canceled_at

When the subscription was canceled. Absent until then.

string format: date-time
cancel_at_period_end
required

True when the subscription cancels at the end of the current period. False after the subscription is canceled.

boolean
cancel_effective_at

When a scheduled cancel takes effect: with cancel_at_period_end, current_billing_period_end. Absent when no cancel is scheduled.

string format: date-time
current_billing_period_start

Start of the current billing period, the beginning of a day in your account’s billing time zone. On a canceled subscription it keeps its last value.

string format: date-time
current_billing_period_end

End of the current period (exclusive): the start of the next one. On a canceled subscription it keeps its last value.

string format: date-time
current_billing_period_display

The current period as text, with the last day included, in your account’s billing time zone, for example “Oct 1, 2026 – Oct 31, 2026”. Absent when the subscription has no current period, or when the time zone could not be read.

string
next_billing_at

When the current period’s invoice is due to be built: the end of the current period. The billing run builds it once the invoice grace after that time has passed. A canceled subscription keeps its last value, and nothing is billed at that time.

string format: date-time
billing_anchor_day

Day of the month the subscription bills on (1-31): the day its first period started, or the day an earlier release switched it to a plan with another billing interval. Absent for calendar-monthly subscriptions.

integer
billing_failure

Present on a subscription while the billing run is failing on the work that subscription has due now: the close of its current period, which also cancels it when a cancel is scheduled. Absent otherwise: a subscription that bills cleanly, or whose due work changed, carries no billing_failure.

After each failed attempt the billing run waits before the next one: 15 minutes, 1 hour, 4 hours, 12 hours, then 24 hours three times. The eighth failure parks the subscription (parked: true, no next_attempt_at). A parked subscription is not attempted again until POST /v1/subscriptions/{id}/retry-billing is called.

object
attempts
required

Failed attempts on the work that is due now. At least 1.

integer
max_attempts
required

The attempt at which the subscription parks (8).

integer
last_error
required

Why the latest attempt failed: a sentence an operator can act on, or a generic line carrying the subscription id as the reference to search the server log for. Never raw error text.

string
failed_at
required

When the latest attempt failed.

string format: date-time
next_attempt_at

The billing run does not attempt the subscription before this instant. The attempt happens on the first run at or after it, so on an hourly schedule it can be up to an hour later. Absent when parked.

string format: date-time
parked
required

True when automatic attempts have stopped.

boolean
created_at
required

When the subscription was created.

string format: date-time
updated_at
required

When the subscription last changed.

string format: date-time

Example

{
"id": "hc_sub_dauq502q3gpgqfoq5c2g",
"tenant_id": "hc_ten_dajqj02q3gpgqfoq5c00",
"code": "acme-pro",
"display_name": "Acme Pro",
"customer_id": "hc_cus_dakhnk2q3gpgqfoq5c0g",
"plan_id": "hc_pln_dajr5o2q3gpgqfoq5c1g",
"status": "active",
"billing_time": "calendar",
"started_at": "2026-10-01T09:12:44Z",
"cancel_at_period_end": false,
"current_billing_period_start": "2026-10-01T00:00:00Z",
"current_billing_period_end": "2026-11-01T00:00:00Z",
"current_billing_period_display": "Oct 1, 2026 – Oct 31, 2026",
"next_billing_at": "2026-11-01T00:00:00Z",
"created_at": "2026-10-01T09:12:44Z",
"updated_at": "2026-10-01T09:12:44Z"
}

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"
}
}

No customer with this customer_id in this account and mode (code not_found).

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": "not_found",
"message": "customer not found",
"request_id": "req_dbjg652q3gpgqfoq5cd0"
}
}

Code already_exists (param: code): another subscription in this account and mode has this code. Code already_on_plan (param: plan_id): the customer has another active subscription on the plan, or scheduled to move to it; the message names its code. Code invalid_state: the customer or the plan is archived; the plan bills a meter that another active subscription of the customer already bills; or the plan’s currency differs from the customer’s billing profile or from the customer’s other active subscriptions. Code concurrent_change: Postgres stopped the create because of another change to the same records (it broke a deadlock, or ended a wait for a lock), so nothing was created; send the same request again, with the same Idempotency-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": "already_exists",
"message": "subscription code \"acme-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 (param names it): code, display_name, customer_id or plan_id missing; a code with other characters; an unknown plan (param: plan_id). Or the body has an unknown field (param names it; the body must use only the fields listed here). items, status and start_now are such fields: a subscription bills one plan, and always starts when it is created.

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": "must contain only alphanumeric characters, hyphens, and underscores",
"request_id": "req_dbjg652q3gpgqfoq5cd0",
"param": "code"
}
}

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