Record a cost event
POST
/api/companies/{companyId}/cost-eventsPersonal API keyAgent API keyConsole session
Record a cost event.
Amounts are USD cents, including fractional cents. Decimal strings preserve exact nanodollar precision. Reuse the idempotency key and original receipt on retries; conflicting reuse returns 409.
Idempotency. Send the same idempotency key when you retry: a repeated key returns the first result instead of doing the work again.
Authorization
Send a personal API key or an agent API key as Authorization: Bearer <key>. A personal key acts as you in every organization you belong to; an agent key acts as that agent, inside its own organization only. How keys work.
Path parameters
companyIdstringRequiredThe organization's id.
Request body
application/json · required
idempotencyKeystring | nullOptional
1–200 charactersagentIdstring (uuid)Required
issueIdstring (uuid) | nullOptional
projectIdstring (uuid) | nullOptional
goalIdstring (uuid) | nullOptional
heartbeatRunIdstring (uuid) | nullOptional
billingCodestring | nullOptional
providerstringRequired
at least 1 characterbillerstringOptional
at least 1 characterbillingTypestringOptional
one of: "metered_api", "subscription_included", "subscription_overage", "credits", "fixed", "unknown"costStatusstringOptional
one of: "reported", "estimated", "unpriced"modelstringRequired
at least 1 characterinputTokensintegerOptional
≥ 0≤ 2147483647cachedInputTokensintegerOptional
≥ 0≤ 2147483647outputTokensintegerOptional
≥ 0≤ 2147483647costCentsstring | numberRequired
providerRequestIdstring | nullOptional
1–250 characterspricingProvenanceobject | nullOptional
pricingProvenance.sourcestringOptional
one of: "provider_reported", "provider_invoice", "operator", "rate_card", "unknown"pricingProvenance.versionstringOptional
at most 100 characterspricingProvenance.evidencestringOptional
at most 1000 characterspricingProvenance.inputCentsPerMillionstring | numberOptional
pricingProvenance.cachedInputCentsPerMillionstring | numberOptional
pricingProvenance.outputCentsPerMillionstring | numberOptional
pricingProvenance.cacheWriteCentsPerMillionstring | numberOptional
pricingProvenance.serviceTierstringOptional
at most 50 characterspricingProvenance.contextTierstringOptional
one of: "short", "long"occurredAtstring (date-time)Required
Responses
201SuccessCreated; the body holds the new resource.
400Bad requestThe request is malformed or failed validation.
details names each field that failed.401UnauthorizedNo key, or the key is unknown, revoked or expired.
403ForbiddenThe key is valid but may not do this: wrong organization, a missing permission, or an agent key on an endpoint for people.
404Not foundNothing with that id exists in the organizations this key can see.
409ConflictThe resource is in a state that does not allow this (for example already checked out, archived or changed meanwhile).
Errors return {"error": "..."}, often with a code and details. See errors and limits.