---
title: "Atomic credit debit + ledger append"
method: POST
path: "/credits/consume"
tags: ["credits"]
---

# Atomic credit debit + ledger append

`POST /credits/consume`

## Request

- Base URL: `https://api.autron.ai`
- URL: `https://api.autron.ai/credits/consume`
- Auth: API key in header `Authorization`

Called by the agent app's chat route in a fire-and-forget
``after()`` tail task once a chat turn's stream completes.

Idempotency: replays of the same ``chat_request_id`` return
``{ status: "duplicate", credit_cost, balance_after }`` without
debiting again — the unique partial index on
``credit_transaction.chat_request_id`` is the source of truth.

Free-tier callers (no credit_balance row) get
``{ status: "no_balance", ... }`` instead of an error — the
agent's free-tier message-count gate handles those users via a
different path.

## Request body

- object
  - `chat_request_id` string
  - `model` string
  - `user_public_id` string
  - `input_tokens` integer
  - `output_tokens` integer
  - `cached_input_tokens` integer
  - `cached_output_tokens` integer
  - `long_context_input_tokens` integer
  - `long_context_output_tokens` integer
  - `long_context_cached_input_tokens` integer
  - `audio_seconds` number
  - `source` string
  - `internal` boolean
  - `on_behalf_of_company_public_id` string
  - `on_behalf_of_seller_public_id` string

## Response `200`

Success

---

[API](https://skmtc.dev/autron/apis/autron-api.md) · [All operations](https://skmtc.dev/autron/apis/autron-api/llms.txt) · [OpenAPI document](https://skmtc.dev/autron/apis/autron-api/revisions/f696bfa7295f?raw)
