Schedule a plan change
const url = 'http://localhost:8080/v1/subscriptions/hc_sub_dauq502q3gpgqfoq5c2g/schedule-plan-change';const options = { method: 'POST', headers: { 'Idempotency-Key': '5f0c8a2e-7b1d-4c3e-9a6f-2d8b4e1c7a90', Authorization: 'Bearer <token>', 'Content-Type': 'application/json' }, body: '{"plan_id":"hc_pln_dajr5o2q3gpgqfoq5c3k"}'};
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/subscriptions/hc_sub_dauq502q3gpgqfoq5c2g/schedule-plan-change \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --header 'Idempotency-Key: 5f0c8a2e-7b1d-4c3e-9a6f-2d8b4e1c7a90' \ --data '{ "plan_id": "hc_pln_dajr5o2q3gpgqfoq5c3k" }'Moves the subscription to another plan at the end of the current
period. The subscription must be active. A period that ended and
is not invoiced yet is billed first, so the change is scheduled for
the end of the period that is running.
The subscription keeps its plan until then, and shows the change in
pending_ and pending_. When the period
ends, Hardcount bills it on the current plan, moves the subscription
to the new plan and sends subscription..
Cancel the change with
DELETE /. A second
change replaces the first.
A subscription’s plan does not change in the middle of a period. To
move a customer to another plan now, cancel the subscription
(POST /, which bills the usage so far)
and create a new one.
Sends subscription. and writes an audit
log entry.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”The subscription’s ID (hc_).
Example
hc_sub_dauq502q3gpgqfoq5c2gHeader 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
The plan to move the subscription to at the end of the current period (hc_). Must differ from the current one and use the same base-fee billing timing (in advance or in arrears).
Example
{ "plan_id": "hc_pln_dajr5o2q3gpgqfoq5c3k"}Responses
Section titled “Responses”The subscription, with the scheduled change in pending_ and pending_.
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 / 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
The subscription’s ID (hc_).
The account the subscription belongs to.
Your code for the subscription: letters, digits, hyphens and underscores. Unique in your account and mode (live or test).
The subscription’s name, as shown in the dashboard.
The customer the subscription bills (hc_).
The plan the subscription bills now (hc_): its base fee
and its usage prices. A scheduled plan change shows in
pending_ until it takes effect. Absent only on a
canceled subscription that an earlier release left with no plan.
The plan the subscription moves to at
pending_ (hc_). Absent when no change
is scheduled.
When the scheduled plan change takes effect: the end of the period in which it was scheduled. Absent when no change is scheduled.
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 atcanceled_. It bills nothing more, and no route makes itat activeagain. A subscription canceled before it started has nostarted_and no billing period.at
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.
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.
When the subscription was canceled. Absent until then.
True when the subscription cancels at the end of the current period. False after the subscription is canceled.
When a scheduled cancel takes effect: with
cancel_, current_. Absent
when no cancel is scheduled.
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.
End of the current period (exclusive): the start of the next one. On a canceled subscription it keeps its last value.
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.
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.
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.
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_.
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_). A parked subscription is not attempted again
until POST / is called.
object
Failed attempts on the work that is due now. At least 1.
The attempt at which the subscription parks (8).
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.
When the latest attempt failed.
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.
True when automatic attempts have stopped.
When the subscription was created.
When the subscription last changed.
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", "pending_plan_id": "hc_pln_dajr5o2q3gpgqfoq5c3k", "pending_plan_effective_at": "2026-11-01T00:00:00Z", "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-16T10:30:00Z"}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" }}No subscription with this ID in this account and mode.
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": "not_found", "message": "subscription not found", "request_id": "req_dbjg652q3gpgqfoq5cd0" }}Code invalid_: the subscription is not active, the new
plan is archived, its meters (the meters it has a price for)
overlap another active subscription of the customer, or its
currency differs from the current plan’s, the customer’s billing
profile or the customer’s other active subscriptions. Code
already_ (param: plan_): the customer has another
active subscription on the plan, or scheduled to move to it;
the message names its code. Code
unbilled_: a billing period ended and could not be
invoiced; retry billing first. Code concurrent_:
Postgres stopped the change because of another change to the
same records (it broke a deadlock, or ended a wait for a lock),
so the subscription is unchanged; send the same request again,
with the same Idempotency-Key. A period that had ended and was
billed first stays billed.
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_state", "message": "The plan can only be changed on an active subscription. This one is canceled.", "request_id": "req_dbjg652q3gpgqfoq5cd0" }}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" }}Code validation_: plan_id is missing
(param: plan_); the new plan equals the current one or is
not found; or its base-fee timing differs from the current
plan’s.
Also: the body has an unknown field (param names it; the
body must use only the fields listed here).
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": "unknown field \"immediate\"", "request_id": "req_dbjg652q3gpgqfoq5cd0", "param": "immediate" }}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