Developers

Public API data formats

How the Costfluent Public API writes money, dates, currencies and IDs, and how a write is made conditional on the version you read.

The OpenAPI document declares each field's format. This page explains the ones an integration has to handle with care.

Money

Every amount of money is a decimal string, never a JSON number, so no client sums binary floats that drift:

JSONCode
{ "amount": "1250.50000000", "currency": "EUR" }
  • Responses write every amount with exactly eight decimals, a point and no exponent.
  • Requests send an amount the same way, with up to eight decimals: "1250.5" and "1250.50000000" are the same amount. A JSON number, an exponent or a thousands separator is refused with 400.
  • A budget amount is kept to the cent, so a budget amount with more than two decimals is refused rather than rounded.
  • Compare amounts by value, not as text: "49" and "49.00000000" are equal.
  • Percentages, ratios such as allocation coverage, exchange rates and usage quantities stay JSON numbers.
  • A cost data row's quantity (measure=usage or count) is a JSON number. A usage or count report's data keeps its figures in the cost and totalCost fields as decimal strings, and its summary.measure says they are a quantity or a count, in no currency.
  • A cost alert's thresholdValue is a decimal string whether it is an amount or a percentage, as its thresholdType says.

Dates and months

  • A date is YYYY-MM-DD, such as startDate, endDate and a custom integration's chargePeriodStart. A charge period is a day, so a time is refused.
  • A window of days is a startDate and an endDate, both included, so March is startDate=2026-03-01 and endDate=2026-03-31. Cost data, allocation coverage, the allocation rule preview, exchange rates and business metric values take a window this way, and coverage answers it the same way.
  • The audit log filters moments, not days: its from is included and its to is not, so one interval's to can be the next one's from without listing an entry twice.
  • A forecast month is YYYY-MM.
  • A timestamp, such as createdAt, is an ISO 8601 date and time.

Currencies

A currency is an upper-case three-letter ISO 4217 code, such as EUR or GBP.

IDs

Every Costfluent object is addressed by a prefixed ID, such as wsp_ for a workspace, bud_ for a budget, crp_ for a cost report, seg_ for a segment and prv_ for an integration. The prefix says what the ID names, and the API refuses an ID of the wrong kind. Treat the rest as opaque.

A batch of costs sent to a custom integration answers with a batchId beginning with cbt_: a receipt for that batch, not an upload you can read back.

Conditional updates

Reading an app, a budget, a business metric, a cost alert, a cost report or its report schedule, a dashboard or one of its widgets, a folder, an integration, a saved filter, a team, a virtual tag or a workspace answers with an ETag header, the version of the object it returned. Send it back as If-Match on the PUT, PATCH or DELETE that changes the object, and on a cost alert's pause and resume, a report schedule's activate and deactivate, and the saved-filter of a dashboard or folder:

TerminalCode
curl --request PUT https://api.costfluent.com/v1/budgets/$BUDGET_ID \ --header "Authorization: Bearer $COSTFLUENT_API_TOKEN" \ --header "If-Match: \"774\"" \ --header "Content-Type: application/json" \ --data '{"amount": "15000"}'

When someone changed the object after your read, the write is refused with 412 and precondition_failed, and nothing changes: read it again, then decide. Without If-Match, the last write wins.

alt [Unchanged since your read] [Changed since your read] Read the object The object, with its ETag The write, with If-Match: that ETag Applied, with its new ETag 412 precondition_failed, nothing changed Your client or script The Costfluent Public API
A write sent with the ETag of your read applies only if no one changed the object since; otherwise it is refused with 412 and nothing changes.

How it behaves

  • A create and an update answer with the object's new ETag too. A list carries no versions.
  • A segment and an allocation rule have no read of their own, so take their ETag from the create or update that answered them.
  • If-Match: * applies the write whatever the version.
  • The ETag is opaque: compare it, never read meaning into it.
  • A cost alert's version also changes each time it is evaluated, because its lastEvaluatedAt changes with it.
  • The Terraform provider sends the ETag of its last read or write with every update and deletion, so an edit made in Costfluent between a plan and its apply stops the apply instead of being overwritten. Plan again to see the edit, then apply.

Retrying a create

Every POST that creates an object, and a batch of costs sent to a custom integration, takes an Idempotency-Key header: a value you choose for that one request, such as a UUID, at most 255 printable ASCII characters. Send the same request again under the same key, after a timeout or a dropped connection, and it is answered with the first response instead of creating a second object:

TerminalCode
curl --request POST https://api.costfluent.com/v1/folders \ --header "Authorization: Bearer $COSTFLUENT_API_TOKEN" \ --header "Idempotency-Key: 6f1c2b9e-4d0a-4f7e-9b3a-2c8d5e1f0a47" \ --header "Content-Type: application/json" \ --data '{"workspaceId": "wsp_...", "title": "Platform"}'
POST, with an Idempotency-Key The response is lost to a timeout The same POST, under the same key The first response, Idempotent-Replayed: true Creates the object Your client or script The Costfluent Public API
A create sent again under the same Idempotency-Key answers the first response instead of creating a second object, for 24 hours after the first request.
  • A replay answers the first status, Location and body, with Idempotent-Replayed: true, for 24 hours after the first request. After that the key is forgotten, and the request creates again.
  • A key belongs to your organization and the operation it was first sent to. Sent again with another body, path or query, or by another token, it is refused with 422 and idempotency_key_reused, and nothing is created: send that request under a new key.
  • A copy sent while the first is still running waits for it and answers its response. If the first runs on for more than 30 seconds, the copy answers 409 and concurrency_conflict; retry it.
  • A key is kept only for a create that succeeded. A refused request, such as one that fails validation, gives its key back, so the corrected request can use it.
  • Without the header, every request creates, as before.
  • No replay answers a secret. A webhook created without a signing secret is given one, which only the first answer returns, as signingSecret; a replay leaves it out. In every answer's config, a webhook's signing secret and a Slack or Teams incoming-webhook URL come back as ***, and a webhook's url as its scheme and host followed by /***.
  • The Go SDK and the Terraform provider send a new key with every create and reuse it on their own retries.