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 →

Errors

When a request fails, Hardcount answers with an HTTP status and a JSON body that names the problem with a code. This page shows the body, what each status means, and every code the API sends, with what to do about it.

Every error has this shape, including an unknown path and a method the path does not take:

{
"error": {
"type": "invalid_request_error",
"code": "validation_error",
"message": "external_id is required",
"request_id": "req_<id>",
"param": "external_id"
}
}
Field Always there What it is
type Yes The kind of error; see Statuses
code Yes A stable name for the problem. Branch on it in your code.
message Yes A sentence for people. Do not parse it: the words can change.
request_id Yes The request’s ID; see Find a request in your logs
param No The field or query parameter that failed, when one did

A few answers add fields beside error; see Answers in another shape.

Status type Meaning Retry?
400 invalid_request_error The request cannot be read: the body is not JSON, or a field has the wrong JSON type No. Fix the request.
401 authentication_error No key, or a wrong, revoked or expired one No. Fix the key.
403 authentication_error The key or session may not do this No
404 invalid_request_error The resource or the path does not exist No
405 invalid_request_error The path does not take this method. The Allow header lists the ones it takes. No
409 invalid_request_error It conflicts with what exists: a duplicate, or the resource is in the wrong state for this action Sometimes; see the code
413 invalid_request_error The body is too large No. Send less.
422 invalid_request_error A field or a business rule failed No. Fix the request.
429 rate_limit_error Too many requests Yes, after Retry-After seconds
500 api_error Something went wrong on the server See Retry after an error
502 api_error Stripe or the email server refused or did not answer See the code
503 api_error A part of Hardcount was not available for a moment Yes
504 api_error The request ran past its time limit before any answer was written See Retry after an error

The status sets the default code. A more specific code replaces it where the API has one.

code When What to do
invalid_request The body is not one JSON value, or a field has the wrong JSON type (invalid JSON body). A usage batch has no events or more than 1,000. Fix the request
code When What to do
unauthorized No key or session, or a wrong, revoked or expired one. Also a wrong sign-in, and a bad public cost-dashboard link. Fix the key. The messages: When a key is refused.
invalid_token A payment-update link that is unknown, expired or already used, or whose invoice was removed Ask for a new link
code When What to do
forbidden The key’s type may not call this route. A route that takes only a dashboard session. A browser request from another site. The other mode’s Stripe connection. Use the right key; see Authentication
code When What to do
not_found The resource, or one the body names, does not exist in this account and mode. A bad hosted invoice link gets it too. Check the ID and the key’s mode
route_not_found No route has this path Check the URL
invoice_not_found The invoice behind a payment-update link was removed while the request ran Ask for a new link
customer_not_found The customer behind a payment-update link no longer exists Ask for a new link
code When What to do
method_not_allowed The path does not take this method Use a method from the Allow header

Most of these say the resource is in the wrong state now. Read it again, then decide.

Duplicates and state

code When What to do
already_exists A value that must be unique is taken, such as a customer’s external_id. param names it. Use another value, or read the one that exists
invalid_state The resource is in the wrong state for this action Read it, wait or change it, then try again
concurrent_change Another change to the same records stopped the request: Postgres broke a deadlock or ended the request’s wait for a lock, or, for a cancel, the subscription changed twice while the cancel priced it. Only the routes listed below answer it. Send the same request again. With an Idempotency-Key, the same key works. Some steps stay done (below).
already_bootstrapped POST /v1/bootstrap after the first account exists Do not retry
member_elsewhere GET /v1/auth/invite/{token} or POST /v1/auth/accept-invite, which the invited person’s browser calls: the invited email already belongs to another account on this server, and an email can belong to only one. Do not retry. The person who sent the invitation invites a different address.

These routes answer concurrent_change:

  • Subscriptions: create, cancel, and schedule a plan change.
  • Customers: update, and write the billing profile.
  • Invoices: create, record payment, and collect when it settles the invoice without a card charge.
  • Credit notes: issue, and the issue step of create with auto_issue. The create step itself answers 500.

Postgres ends a wait for a lock only when a lock_timeout is set, for example on the database user Hardcount runs as. On any other route or step, a deadlock or an ended lock wait answers 500 internal_error, which an Idempotency-Key stores (Idempotency).

A cancel prices its final invoice before it writes anything. When the subscription changes in that time, for example because its billing period closes, the cancel writes nothing and prices once more on its own. If the subscription changes again, the cancel answers concurrent_change and the subscription is not canceled.

After concurrent_change, a step that the request saved on its own before Postgres stopped it stays done. The routes not listed here save nothing first:

  • Cancel, and scheduling a plan change: the invoice for a billing period that had already ended. It may already be charged. The request sent again does not bill that period twice.
  • Collect: the customer’s credit that the request applied to the invoice before the settle that Postgres stopped. Sent again, Collect finds nothing left due, so it applies no credit and marks the invoice paid.
  • Create with auto_issue: the note it made, which is voided. The request sent again makes and issues a new note.

Idempotency (how idempotency keys work)

code When What to do
conflict_idempotency A request with this Idempotency-Key is still running or did not finish. Hardcount answers at once, without waiting for it. Wait a moment, then retry with the same key. Wait longer before each later try.
conflict_idempotency_unresolved A request with this key started more than 15 minutes ago and never recorded an answer Check whether the change happened; retry with a new key only if not

Pricing

code When What to do
price_exists The plan already prices this meter with the same dimension_match Change that price instead
price_conflict Another price on the plan and meter would take the same events with the same number of labels Make one price more specific
meter_overlap A subscriber of the plan has another subscription with this meter, or has the plan twice Price the meter on a new plan
meter_has_usage You tried to change the aggregation of a meter that has events Make a new meter

Subscriptions

code When What to do
unbilled_period A billing period has ended and could not be invoiced, so the change waits Fix the billing failure (POST /v1/subscriptions/{id}/retry-billing), then try again
already_on_plan Creating a subscription, or scheduling a plan change, when another active subscription of the customer is on the plan or scheduled to move to it. The message names its code. Cancel that subscription first, or choose another plan
billing_not_failing retry-billing on a subscription whose billing is not failing Nothing to do

Invoices and payments

code When What to do
payment_in_flight A card charge for the invoice is running, or its result is not known yet. Every charge takes a second or so. A void, write-off, offline payment, credit note, collection or email would run at the same time as that charge. Wait a few minutes, then retry. After an unclear answer from Stripe, Hardcount can take about an hour to settle the charge.
payment_in_progress A payment for this invoice is already in progress, on the hosted page for example Wait, then read the invoice
not_payable The invoice cannot be paid now, for example it is voided. Collect answers it for a draft that is not a top-up, a voided invoice and a written-off one; the hosted page answers it for a paid one too. Do not retry. For a written-off debt, record an offline payment or issue a new invoice.
invoice_already_paid Collect on a paid invoice Nothing to do
no_payment_method Collect when the customer has no card set up Send the customer a setup link
no_amount_due Collect on an invoice with nothing due that it did not mark paid: credit covered it while the request ran, or a payment is processing Send Collect again. If it answers the same, read the invoice.
amount_below_minimum The amount is below Stripe’s smallest card charge Void it, record an offline payment, or bill it later
card_refused The bank refused the saved card for good Ask the customer for a new card
invoice_not_collectible You asked to resend a payment link for an invoice that is not unpaid or written off Do not retry
invoice_not_sendable You asked to email a draft or voided invoice Finalize it first, or do not send it
no_email_on_file You asked to resend a payment link to a customer with no email Add an email to the customer
invoice_lines_changed The invoice changed while the request ran Read it again, then retry
invoice_not_manual You tried to add a line to a draft invoice that billing made for a subscription. That invoice keeps the lines and tax that billing gave it. Bill the charge on its own one-off invoice
credit_note_exceeds_invoice, invoice_not_open_receivable A credit note no longer fits the invoice, which changed while the request ran Read the invoice, then retry with the right amount
customer_currency_conflict A one-off invoice’s currency is not the customer’s billing currency Use the customer’s currency
tax_calculation_expired Stripe Tax’s calculation for the invoice is too old to finalize Retry the tax, then finalize
stripe_refund_unresolved Retrying a credit note’s refund, refunding a top-up’s unused credit (commit relief), or marking a refund as returned another way, while a refund made in Stripe for this invoice is not recorded yet, or is still in progress at Stripe If it is not recorded: record it, attach it or dismiss it on the invoice. If it is in progress: wait for Stripe to settle it. Then send the request again.
dispute_loss_unrecorded Refunding a top-up’s unused credit (commit relief) while a dispute the customer’s bank won on its payment has no credit note yet Write it with POST /v1/invoices/{id}/disputes/{dispute_id}/record-loss, then refund what is left
credit_block_changed The customer’s credit changed while it was being returned Retry

Setup on this server

code When What to do
email_not_configured An action that sends email, on a server with no email set up (SMTP_HOST). Nothing was sent. The person who runs your server sets up email: Email setup
stripe_not_connected An action that needs Stripe, in a mode with no Stripe keys Connect Stripe under Settings
return_address_not_set A setup link (send-setup-email, or setup-session with no return_url) on a server with no CUSTOMER_PORTAL_URL, so Stripe would have no page to send the customer back to. Nothing was created at Stripe. The person who runs your server sets CUSTOMER_PORTAL_URL: Settings
online_payment_unavailable The hosted invoice or payment-update page cannot take a card: the seller has not connected Stripe for this mode, or the server has no address for Stripe to send the customer back to (HOSTED_INVOICE_BASE_URL, PAYMENT_UPDATE_RETURN_URL) The customer pays another way. A payment-update link is not used up, so it works once the seller fixes the setup

Rare: a record that must be unique already exists

These guard against a record being written twice, mostly by Hardcount’s own billing run. A request rarely gets one. Do not retry; read the invoice or the credit ledger, and report it if the state looks wrong: invoice_number_taken, invoice_billing_period_taken, invoice_public_token_collision, invoice_unique_violation, credit_note_source_taken, credit_reversal_source_taken, credit_commit_fund_taken, credit_unique_violation and credit_source_amount_mismatch.

code When What to do
batch_too_large A POST /v1/usage-events/batch body is over 1 MB, or a POST /v1/integrations/litellm/spend body is over 32 MB. Nothing was saved. Send smaller batches
payload_too_large The body is over the 1 MB limit, with or without an Idempotency-Key. Nothing was changed, and the answer is not kept for the key. A Stripe webhook body over 64 KB gets it too. Send a smaller body. For a Stripe webhook, nothing: Stripe’s events are smaller.
code When What to do
validation_error A field failed a rule, such as a missing external_id, a bad limit, a list sort or dir the list does not take, a field the operation does not take, or a query parameter it does not take. A list filter that takes a fixed set of values got another, such as status on the invoice list. param names it. Fix the field
batch_rejected At least one event of a usage batch failed. Nothing was stored. The body lists each failure in errors. Fix the events named, then send the whole batch again
idempotency_error An Idempotency-Key was first used by another caller (another API key or dashboard user) or with a different method, path, query string or body Use a new key for a new request
customer_has_no_subscription An invoice preview or a usage summary for a customer with no active subscription Send subscription_id, or a period with from and to
subscription_has_no_cycle An invoice preview for a subscription with no current billing period Send a period
missing_email You asked to email a payment-method link to a customer with no email Add an email
note_too_long That email’s note is over 2,000 bytes Shorten it
invalid_state You asked to rotate the public link of a draft invoice Finalize the invoice first
invalid_or_expired The dashboard’s check of a password-reset link (GET /v1/auth/password-reset/check) found it unknown, expired or used. Setting the password, or accepting an invite, with a bad token answers validation_error with param: token instead. Ask for a new link

Each sends a Retry-After header with the seconds to wait.

code When What to do
rate_limited Over a rate limit Wait Retry-After seconds, then retry
login_throttled Too many failed sign-ins for an email Wait, then sign in again
cooldown_active Someone asked to email this customer a payment-method link less than a minute ago, even if that request then failed. Counted only on a server with Redis. Wait a minute, then send it with a new Idempotency-Key: this answer is stored like any other
code When What to do
internal_error An unexpected fault. The details are in the server’s log, not in the answer. See Retry after an error. Look up the request_id in the logs.
code When What to do
provider_error Stripe refused the request, such as a declined card. The message says why. Read the message; do not retry blindly
payment_outcome_unknown Stripe never answered. The charge or refund may have gone through. Check the invoice before you retry
stripe_key_unusable Stripe refused the account’s key, or no key is connected for this mode. Nothing was charged. If Stripe refused the key on the confirm, the invoice shows unknown until the first scheduled run after the key works again. Fix the Stripe key under Settings
stripe_error The hosted page could not start a Stripe Checkout session Try again later
smtp_error The email server refused the test email. The message says what it answered. Fix the email settings
email_enqueue_failed An email could not be queued Retry
code When What to do
authentication_unavailable Hardcount could not check the key or session Retry the same request
idempotency_unavailable Hardcount could not record the Idempotency-Key, so it ran nothing Retry with the same key after Retry-After (1 second)
ingest_unavailable The usage store did not answer, or could not write the events. Send the same events, with the same keys, after Retry-After (1 second): each is recorded once
collect_unavailable POST /v1/invoices/{id}/collect was stopped before its first request to Stripe, by a database fault, unreadable Stripe credentials or too many recent Stripe failures. No card was charged. Credit it applied stays applied, and is not applied twice. Retry the same request after Retry-After (1 second), with the same Idempotency-Key if you sent one. If that answers 409 payment_in_flight, wait as that code says.
currency_unavailable POST /v1/invoices could not read the customer’s currency. No invoice was made. Retry the same request, with the same Idempotency-Key if you sent one
settings_unavailable POST /v1/invoices/{id}/finalize could not read the account’s time zone, which sets the due date of a draft created before invoices carried their own zone. The invoice was not finalized. Retry the same request after Retry-After (1 second), with the same Idempotency-Key if you sent one
unbilled_usage_unavailable Record-loss, or a credit note with stripe_refund_id on a top-up, could not read the customer’s usage not invoiced yet, which the note counts as credit already used. Nothing was written. Retry the same request after Retry-After (1 second), with the same Idempotency-Key if you sent one
code When What to do
timeout The request ran past its 30-second time limit before any answer was written. A request that runs too long can also end with 500 internal_error. See Retry after an error
  • 4xx: do not send the same request again, except after 409 codes that say so and after 429. Fix the request first. If it carried an Idempotency-Key, send the fixed request with a new key: the answer was stored, and the old key with a changed body answers 422 idempotency_error. A 400 invalid JSON body is not stored: send the fixed body with the same key.
  • 429 rate_limited and login_throttled: wait Retry-After seconds, then send the same request, with the same key. Nothing ran and nothing was stored. cooldown_active is stored: see its row above.
  • 503 authentication_unavailable and idempotency_unavailable: send the same request with the same key. Nothing ran.
  • 503 ingest_unavailable: send the same events with the same keys. Each is recorded once, even if the store wrote them before its answer was lost.
  • 503 collect_unavailable: no card was charged. Send the same request with the same key. If that answers 409 payment_in_flight, wait as that code says.
  • 503 currency_unavailable, settings_unavailable and unbilled_usage_unavailable: the change was not made, and a 503 is never stored. Send the same request with the same key.
  • 500, 502 and 504 on a usage route: send the same events with the same keys. A key is never counted twice.
  • 500, 502 and 504 on another write sent with an Idempotency-Key: the answer is stored, so a retry with the same key gets it again. That includes the 500 internal_error of a crash inside Hardcount. Read the resource to see whether the change happened, and retry with a new key only if it did not. See Idempotency.

Every answer has a Hardcount-Request-Id header, such as req_d3l2a8c5d6q3f0bnsp0g. An error has the same value in request_id. Hardcount makes the ID itself; a request cannot set it.

The server writes one JSON log line per request, with the ID in the request_id field. Every other line the request writes, such as the details of a 500, carries it too. To find them on a quick start install:

Terminal window
cd deploy/compose
docker compose logs hardcount-api | grep 'req_d3l2a8c5d6q3f0bnsp0g'

Under make dev, search the terminal output of the API.

A request body may hold only the fields its operation lists in the API reference.

  • Any other field is refused with 422 and param naming it. That includes a misspelled field, a field the operation does not take, a field the server sets (such as id, tenant_id or created_at), and a name in another case (such as Email for email). Nothing is changed.
  • A usage batch names each such event in errors instead.
  • An operation with no request body, such as POST /v1/subscriptions/{id}/cancel, takes no body, {} or null.
  • A body that is not one JSON value is refused with 400.
  • The Stripe and Postmark webhooks and the LiteLLM callback are the exceptions: they take their sender’s body as it comes.

Bodies are limited to 1 MB, LiteLLM callback bodies to 32 MB, and Stripe webhook bodies to 64 KB. A larger body gets 413: batch_too_large from the usage batch and the LiteLLM callback, payload_too_large from the other routes. The Postmark webhook is the exception below.

A query string may hold only the parameters its operation lists in the API reference.

  • Any other is refused with 422 validation_error, param naming it and the message unknown query parameter "<name>". That includes a misspelled filter, such as staus for status. When several are unknown, param names the first in sorted order.
  • A parameter sent with an empty value, such as status=, is still one the operation takes.
  • A query string that does not parse (a bad % escape, or ; between parameters) is refused whole, with no param.
  • The Stripe and Postmark webhooks and the cost dashboard’s public link take any query string.
  • A rejected usage batch (422 batch_rejected) has, beside error, errors (one line per failing event), ingested: 0 and total.
  • POST /v1/billing/run answers 206 when some subscriptions could not be billed, with invoices_generated and errors.
  • A replayed Idempotency-Key returns the first answer’s body byte for byte.
  • A CSV export that fails partway ends with a row that starts EXPORT_INCOMPLETE, or stops with no such row when the connection is cut. Treat a file as complete only if your client got the whole response without an error.
  • GET /health/ready answers 503 with {"status", "checks"}.
  • The Postmark webhook accepts a body that is too large or not JSON with 200 and {"status": "skipped", "reason": "<reason>"}.
  • Plain text, not JSON, comes from two places:
    • The HTTP server itself, before Hardcount sees the request. A request it cannot parse gets 400; headers over about 12 KB get 431; an unknown transfer encoding gets 501; an unsupported HTTP version gets 505. These answers have no Hardcount-Request-Id.
    • /metrics, the Prometheus route, answers a plain-text 500 if it cannot read the metrics.

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