Skip to main content
POST
This endpoint registers credit consumption in one of two modes:
  • Tokens: send provider, modelName and the token counts. The credit cost is calculated from the model’s pricing.
  • Direct amount: send amount and amountType to charge work that is not measured in tokens (a third-party API call, a fixed-price action, etc.). 1 credit = 1 USD.
Never mix both modes in the same request. Use Cases:
  • Track AI agent interactions and their associated costs
  • Bill custom integrations that use AI models
  • Monitor and control credit spending per agent or feature
  • Implement usage-based billing for your organization
This endpoint requires a valid subscription or sufficient credit balance. The request will fail if the organization has exceeded its usage limits.

Body

string
Required unless amount is sent. The AI model provider. Accepted values:
  • azure
  • azure-2
  • azure-oss
  • openai-responses
  • gemini
  • gemini-vertex
  • deepseek
  • openrouter
  • bedrock (deprecated)
string
Required unless amount is sent. The specific model name used for the request. The provider + modelName pair must match this table exactly — an unknown pair is rejected with 400 and no event is recorded. Available models per provider:
integer
default:"0"
The number of input tokens consumed in the request. Must be a non-negative integer.
integer
default:"0"
The number of output tokens generated in the response. Must be a non-negative integer.
integer
Optional multiplier for credit calculation (between 1 and 10). Useful for premium features or custom pricing tiers. Not allowed with amountType: "price".
number
Direct amount to charge, instead of tokens. A JSON number or a plain decimal string ("0.5"), greater than 0, lower than 1,000,000,000 and with at most 6 decimals. Values with more decimals are rejected with 400, never rounded: round float results (for example 0.30000000000000004) to 6 decimals before sending. Cannot be combined with inputTokens, outputTokens or cachedInputTokens. When sent, provider and modelName are optional free text (for example "provider": "twilio") and are not checked against the pricing table.
string
Required when amount is sent. Accepted values:
  • cost: amount is what the work cost. The organization’s billing coefficient is applied, the same way it is for tokens.
  • price: amount is the final price. Exactly that many credits are charged, with no coefficient.
string
Optional, 1 to 255 characters, unique per organization. If a request arrives with a key that was already used, the original event is returned with duplicate: true and nothing is charged again. Use it to retry safely after a timeout. The body of the retry is not compared with the original: a reused key always returns the original event, even if the new body is different.
string
default:"agent_run"
The feature or action that triggered this credit spend (e.g., agent_run, chat_completion, embedding).
string
Optional. The ID of the agent associated with this usage. Useful for per-agent analytics and billing.
object
Optional. Additional metadata to associate with this credit event. Can include any custom fields for tracking purposes.

Response

boolean
Indicates whether the credit spend was successfully recorded.
string
The ID of the organization that was charged.
string
A unique identifier for this credit spend event. Useful for auditing and reconciliation.
string
How the consumption was expressed: tokens or amount.
boolean
true when the request reused an idempotencyKey and the original event was returned without charging again.
object
object
Always present for tokens. For amount, only present when provider or modelName was sent.
object
Only for unitType = "tokens".
object
Only for unitType = "amount".