API Documentation

Ingestion API Reference.

acost provides a high-performance REST API to track AI costs from any backend environment. No SDK required—just a simple POST request.

Create API Key

Configuration

Environment Variables

Store these keys in your secure backend configuration. Never expose your API key in client-side code.

.env configuration
ACOST_BASE_URL=https://tracker-acost.vercel.app
ACOST_API_KEY=acost_your_secret_key

Official Support

We provide high-precision tracking for the following providers.

OpenAI

OpenAI

Anthropic

Anthropic

Google

Google

OpenRouter

OpenRouter

xAI

xAI

DeepSeek

DeepSeek

Qwen

Qwen

Minimax

Xiaomi

Dual-Source Pricing

We track both official rates via PriceToken.ai and OpenRouter market rates. Our engine automatically switches to OpenRouter pricing if provider: "openrouter" is sent.

Custom Providers

You can use any provider, but we recommend sending a manual estimatedCost for unlisted vendors to ensure absolute accuracy.

Request Schema

Every event requires the following core fields for precise tracking.

FieldTypeStatus
userId

Unique identifier for your application user.

stringRequired
model

Exact model ID used (e.g. gpt-4o).

stringRequired
feature

Grouping tag for your product features.

stringRequired
prompt

The input text sent to the AI model.

stringRequired
responseContent

The generated text response from the model.

stringRequired
inputTokens

Prompt token count.

numberRequired
outputTokens

Completion token count.

numberRequired
rawResponse

Full provider JSON response (crucial for auditing).

objectRequired
provider

AI vendor. Defaults to PriceToken.ai rates if omitted.

stringOptional
latency

Request duration in milliseconds.

numberOptional
estimatedCost

Manual cost override. If omitted, acost will calculate this using model metadata.

numberOptional

Payload Formats

Single Event

Pass a single object under the event key.

Batch (Up to 100)

Pass an array of objects under the events key.

Responses

200 OKAccepted
400 Bad RequestSchema Error
401 UnauthorizedInvalid Key

Implementation Examples

Ready-to-use snippets for your backend environment.

cURL Request
curl -X POST https://tracker-acost.vercel.app \
-H "Content-Type: application/json" \
-H "x-api-key: acost_your_secret_key" \
-d '{
"event": {
"userId": "user_123",
"model": "gpt-4o-mini",
"feature": "chat-answer",
"prompt": "What is the capital of France?",
"responseContent": "The capital of France is Paris.",
"inputTokens": 1200,
"outputTokens": 280,
"latency": 842,
"rawResponse": { "id": "chatcmpl-123", "object": "chat.completion", "usage": { "prompt_tokens": 1200, "completion_tokens": 280, "total_tokens": 1480 } }
}
}'
Secure SSL Ingestion Enabled