Record a lost dispute on a top-up
const url = 'http://localhost:8080/v1/invoices/hc_inv_dbj84b2q3gpgqfoq5c40/disputes/example/record-loss';const options = { method: 'POST', headers: { 'Idempotency-Key': '5f0c8a2e-7b1d-4c3e-9a6f-2d8b4e1c7a90', Authorization: 'Bearer <token>' }};
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/invoices/hc_inv_dbj84b2q3gpgqfoq5c40/disputes/example/record-loss \ --header 'Authorization: Bearer <token>' \ --header 'Idempotency-Key: 5f0c8a2e-7b1d-4c3e-9a6f-2d8b4e1c7a90'Writes the credit note that records a dispute lost on a top-up’s own payment, when Hardcount could not write it as the loss arrived (it could not read the customer’s usage not invoiced yet). The note is for the money the customer’s bank returned, no more than the payment’s credit notes still allow, recorded as returned another way (outside Stripe: not a card refund, not emailed), and it takes back the unused credit that money paid for. It is the same step Hardcount runs on a loss, once per dispute. No request body. A dispute not on the invoice is a 404 before any other answer.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”The top-up’s invoice id (hc_).
Example
hc_inv_dbj84b2q3gpgqfoq5c40The dispute record’s id (hc_), as in the dispute’s id.
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-2d8b4e1c7a90Responses
Section titled “Responses”The dispute, with credit_ naming the note written.
A card dispute (chargeback) Stripe reported against one of the
invoice’s payments, recorded from Stripe’s charge.,
. and .closed webhook events. It holds the dispute as the
newest of those events showed it, whatever order they arrived in.
The invoice stays paid. A dispute lost on a top-up’s own payment is
recorded as a credit note that takes back the unused credit the money
paid for (credit_); any other lost dispute is yours to
record.
object
Unique identifier of the dispute record, hc_dsp_ and 24 hex characters.
The invoice whose payment is disputed.
Stripe’s dispute id (du_…).
The disputed Stripe charge (ch_…). Absent when Stripe did not send it.
The disputed payment.
Stripe’s dispute status, as Stripe sends it. The warning_
statuses are an inquiry, which comes before a chargeback or
instead of one. Stripe sends the appeal_ statuses only when
appeals are turned on: under_ moves to
appeal_ when the bank rejects your response and
you can appeal, then to appeal_ once you send the
appeal, and the dispute closes won or lost. Closing it at
appeal_ makes it lost. won, lost,
warning_ and prevented are closed.
The reason the cardholder gave, for example fraudulent. Absent when Stripe gave none.
The disputed amount, in the currency’s minor unit (cents for USD). It can differ from the payment.
The dispute’s currency, uppercase.
The deadline to respond in Stripe. Absent when Stripe gave none.
When Stripe opened the dispute.
When Stripe closed it. Absent while it is open.
The credit note that records this dispute’s loss on a top-up’s own payment: money returned by the customer’s bank (out of band), with the unused credit it paid for taken back. Absent until the loss is recorded; a dispute lost again after an appeal keeps its one note.
True for a live-mode payment, false for test mode.
When Hardcount first recorded the dispute.
When Hardcount last updated the record from a Stripe event.
Example
{ "id": "hc_dsp_6f1c0a7e9b2d4c8e1a3b5d7f", "invoice_id": "hc_inv_dbj84b2q3gpgqfoq5c40", "stripe_dispute_id": "du_1QHk2fLkdIwHu7ix2c3d4e5f", "stripe_charge_id": "ch_3QHk2fLkdIwHu7ix0a1b2c3d", "stripe_payment_intent_id": "pi_3QHk2fLkdIwHu7ix0a1b2c3d", "status": "lost", "reason": "fraudulent", "amount_cents": 9000, "currency": "USD", "opened_at": "2026-11-10T08:30:00Z", "closed_at": "2026-11-24T08:30:00Z", "credit_note_id": "hc_cn_dbjh1kmq3gpgqfoq5cf0", "livemode": false, "created_at": "2026-11-10T08:30:04Z", "updated_at": "2026-11-25T09:12:40Z"}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 invoice with this id in this account and mode, or no dispute with this id on it.
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": "dispute not found", "request_id": "req_dbjg652q3gpgqfoq5cd0" }}The loss cannot be recorded this way: the dispute is not lost,
its loss is already recorded, the invoice is not a top-up or the
dispute is not on its own payment, the dispute is in another
currency (the message says to take the credit back with commit
relief, its money as out_), or the
payment’s credit notes and refunds already return all of it.
Code invalid_; the message says which.
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": "This loss is already recorded as a credit note.", "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" }}This route takes no body, and the request sent one with a field.
param names the field. Send no body, {} or null.
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 \"at_period_end\"", "request_id": "req_dbjg652q3gpgqfoq5cd0", "param": "at_period_end" }}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.
Code unbilled_: Hardcount could not read the
customer’s usage not invoiced yet, which a note on a top-up
counts as credit already used, so it wrote nothing. This answer
is not stored under the Idempotency-Key: send the same request
with the same key after Retry-After.
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": "api_error", "code": "unbilled_usage_unavailable", "message": "Hardcount could not read the customer's usage not invoiced yet, so it wrote nothing; try again in a moment.", "request_id": "req_dbjg652q3gpgqfoq5cd0" }}Headers
Section titled “Headers”Seconds to wait before you send the request again.
Stuck, or found a bug? Ask in Discussions · Open an issue