Cost Breakdown
Get real-time cost data for every AI request directly in the API response.
Cost Breakdown
osmAPI includes cost data in every API response, so you can track spending programmatically without checking a dashboard. Know exactly what each request costs the moment it completes.
Cost breakdowns are included automatically for all verified accounts.
Response Format
Every completion response includes an extended usage object with cost details:
{
"id": "tx_osm_98765",
"object": "chat.completion",
"created": 1700000000,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Analysis complete. The requested data has been processed."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 120,
"completion_tokens": 45,
"total_tokens": 165,
"cost_usd_total": 0.00345,
"cost_usd_input": 0.0018,
"cost_usd_output": 0.00165,
"cost_usd_cached_input": 0,
"cost_usd_request": 0,
"cost_usd_web_search": 0.0
}
}Cost Fields
| Field | Description |
|---|---|
cost_usd_total | Total inference cost for this request (excludes storage). |
cost_usd_input | Cost of processing input/prompt tokens. |
cost_usd_output | Cost of generating completion tokens. |
cost_usd_cached_input | Savings from cached tokens (when provider caching applies). |
cost_usd_request | Fixed per-request cost (for models with request-based pricing). |
cost_usd_web_search | Cost of web search queries for this request. |
cost_usd_total is the sum of all individual cost fields for this request.
Streaming
Cost data is included in the final chunk of streamed responses, right before the [DONE] signal:
data: {"id":"tx_osm_123","usage":{"prompt_tokens":50,"completion_tokens":100,"cost_usd_total":0.0025,"cost_usd_input":0.0005,"cost_usd_output":0.0020}}
data: [DONE]Example: Budget Tracking
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.osmapi.com/v1",
apiKey: process.env.OSM_API_KEY,
});
async function processRequest() {
const completion = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Perform a comprehensive audit." }],
});
const { usage } = completion as any;
if (usage?.cost_usd_total) {
console.log(`Cost: $${usage.cost_usd_total.toFixed(4)}`);
}
}Currency: USD vs INR
osmAPI uses two currencies for different purposes:
| Where | Currency | Why |
|---|---|---|
API response (cost_usd_*) | USD ($) | Matches provider pricing (OpenAI, Google, Groq all price in USD). Developers can directly compare costs with provider documentation. |
| Dashboard & billing | INR (₹) | Credits are topped up in INR via Razorpay. Usage costs are deducted in INR from your credit balance. |
How It Works
- You top up credits in INR (e.g., ₹100 via Razorpay)
- Each API request's cost is calculated internally in INR, then converted to USD for the API response (e.g., $0.000003 for a gpt-4o-mini call)
- The USD cost is converted to INR based on the current market exchange rate and deducted from your credit balance
- The API response shows USD so you can track costs against provider pricing
- The dashboard shows INR so you can track your credit balance
The USD to INR exchange rate is based on the current market value and updated periodically. All model prices on the models page can be toggled between USD and INR using the currency switcher.
Example
API response: cost_usd_total = $0.000003 (what the provider charges)
Credit deducted: ₹0.000282 ($0.000003 × current market rate)
Dashboard shows: ₹99.999718 remainingUse Cases
- Budget Alerts: Set up alerts when individual requests or users exceed a cost threshold.
- Per-User Billing: Track exact costs per user in multi-tenant apps.
- Model Selection: Compare costs across models to pick the most cost-effective option for each task.
How is this guide?