New: Audio API, Embeddings & Realtime WebSocket now available!
osmAPI LogoosmAPI

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

FieldDescription
cost_usd_totalTotal inference cost for this request (excludes storage).
cost_usd_inputCost of processing input/prompt tokens.
cost_usd_outputCost of generating completion tokens.
cost_usd_cached_inputSavings from cached tokens (when provider caching applies).
cost_usd_requestFixed per-request cost (for models with request-based pricing).
cost_usd_web_searchCost 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:

WhereCurrencyWhy
API response (cost_usd_*)USD ($)Matches provider pricing (OpenAI, Google, Groq all price in USD). Developers can directly compare costs with provider documentation.
Dashboard & billingINR (₹)Credits are topped up in INR via Razorpay. Usage costs are deducted in INR from your credit balance.

How It Works

  1. You top up credits in INR (e.g., ₹100 via Razorpay)
  2. 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)
  3. The USD cost is converted to INR based on the current market exchange rate and deducted from your credit balance
  4. The API response shows USD so you can track costs against provider pricing
  5. 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 remaining

Use 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?