Skip to main content
A customer’s margin is what they paid you less what their AI calls cost. TensorCost knows the cost. The revenue comes from you, and the way it comes in is a signed request that your billing job or script makes. TensorCost never holds a credential to your billing, CRM or payment system. It has no Stripe key of yours and doesn’t read your invoices. Your job reads its own system, works out each customer’s month, and sends the figures. The only secret involved is a signing secret that TensorCost made for you, which lets your job write revenue to your own workspace and nothing else.
Available on Scale and Enterprise, including BYOC. Only an admin makes signing secrets. Below Scale, existing secrets can still be listed and revoked, but pushes are refused.
If you’d rather upload a file, Cost per customer takes a CSV. The two can be used together.

What you send

Revenue is a running monthly total for one customer, one month and one currency. Each push says what the total is as of a time you choose, and the newest figure wins. Send the whole month so far, not the amount since your last push. A push replaces the figure; it never adds to it.
A customer, month and currency can appear once in a request.

The newer as_of wins

If TensorCost already holds a figure for that customer, month and currency with a later as_of, your row is skipped and listed in the response. An equal as_of writes, so the last request in wins a tie. This is what makes retries and late jobs safe: an old batch that arrives after a newer one can’t roll the figure back. A CSV upload replaces whatever is held for the customers and months it names, whatever their as_of.

Sign the request

Make a signing secret under Connect › API keys, in Revenue signing secrets, with New signing secret. You get two values:
  • A key id, tcr_ and 24 hex characters. It isn’t secret and goes in a header.
  • A secret, tcrs_ and 64 hex characters. It is shown once. Keep it in your job’s secret store.
Send three headers with each request: rawBody is the exact bytes you send. Sign the string you put on the wire, not an object you serialise a second time, because a difference in spacing or key order is a different signature. Send it with Content-Type: application/json, to the path with no trailing slash.
A good request answers 200:
index is the row’s position in rows, counting from 0. warnings carries the same index and a message, for example for an email-shaped customer id.

Retrying safely

The request_id is how TensorCost knows two requests are the same one. Ids belong to your workspace and cover pushes and deletes together.
  • A request that succeeded keeps its id for 24 hours. Sending it again answers 409 with code: "REQUEST_ID_SEEN". It is already written, so stop. New figures need a new id.
  • A request that is still being written, or whose earlier attempt died part-way, answers 409 with code: "REQUEST_ID_PENDING" and a Retry-After header in seconds, at most 300. Send the same request again after that long.
  • A request that failed (a 400 or a 5xx) can be sent again with the same id.
When you retry, sign again with a fresh timestamp. The old one may have aged out of the 5-minute window.

When a request is refused

A batch is taken whole or not at all. One bad row refuses the request and nothing is written. The 400 lists every bad row by its index, so you can fix them in one go:
An index of null is about the body itself, for example a missing request_id.

Limits

  • 1,000 rows and 1 MiB a request.
  • 60 requests a minute for a workspace.
  • Before the signature is checked, 120 requests a minute from one address naming one key id.
  • After 30 requests in a minute that name a key and fail the signature check, that key’s requests get 429 until the minute ends, even well-signed ones. A key id isn’t secret, so someone else can cause this. If it keeps happening, make a new signing secret, switch to it and revoke the old one.

Delete revenue

DELETE /v1/api/cost/revenue takes a signed JSON body, signed exactly as a push is, with the same ids, retries, window and limits. Send one of two shapes:
The first removes that customer’s month in every currency. The second removes all of the workspace’s revenue, whether it came by push or CSV. Sending both shapes, or neither, is a 400 and nothing is deleted. all must be exactly true. The answer is { "request_id": "...", "deleted": 3 }, where 0 means that month held nothing.

Rotating the signing secret

A workspace can have two active secrets at once, which is what makes rotation painless.
  1. Make a new signing secret. While two are active, a third is refused until you revoke one.
  2. Put the new key id and secret in your job and let it run once.
  3. Revoke the old one. A job still signing with it is refused from its next push.
Secrets belong to the workspace, not to the admin who made them. When that admin leaves, the secret keeps working and the other admins get an alert to rotate. Nothing revokes it for you. Each secret shows when it was last used, which tells you whether anything still signs with the old one before you revoke it.

What it feeds

Revenue shows up under Spend › Customers as revenue and margin, and sets each customer’s limit in a margin floor. The other direction is Pull customer usage.