Calculate cost for a model call
curl --request POST \
--url https://api.narev.ai/v1/traces/cost \
--header 'Content-Type: application/json' \
--data '
{
"model_id": "gpt-4o",
"provider_id": "openai",
"usage": {
"prompt_tokens": 1000,
"completion_tokens": 500,
"cache_read_tokens": 0,
"cache_write_tokens": 0,
"reasoning_tokens": 0,
"web_search_count": 0
}
}
'import requests
url = "https://api.narev.ai/v1/traces/cost"
payload = {
"model_id": "gpt-4o",
"provider_id": "openai",
"usage": {
"prompt_tokens": 1000,
"completion_tokens": 500,
"cache_read_tokens": 0,
"cache_write_tokens": 0,
"reasoning_tokens": 0,
"web_search_count": 0
}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
model_id: 'gpt-4o',
provider_id: 'openai',
usage: {
prompt_tokens: 1000,
completion_tokens: 500,
cache_read_tokens: 0,
cache_write_tokens: 0,
reasoning_tokens: 0,
web_search_count: 0
}
})
};
fetch('https://api.narev.ai/v1/traces/cost', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.narev.ai/v1/traces/cost",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model_id' => 'gpt-4o',
'provider_id' => 'openai',
'usage' => [
'prompt_tokens' => 1000,
'completion_tokens' => 500,
'cache_read_tokens' => 0,
'cache_write_tokens' => 0,
'reasoning_tokens' => 0,
'web_search_count' => 0
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.narev.ai/v1/traces/cost"
payload := strings.NewReader("{\n \"model_id\": \"gpt-4o\",\n \"provider_id\": \"openai\",\n \"usage\": {\n \"prompt_tokens\": 1000,\n \"completion_tokens\": 500,\n \"cache_read_tokens\": 0,\n \"cache_write_tokens\": 0,\n \"reasoning_tokens\": 0,\n \"web_search_count\": 0\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.narev.ai/v1/traces/cost")
.header("Content-Type", "application/json")
.body("{\n \"model_id\": \"gpt-4o\",\n \"provider_id\": \"openai\",\n \"usage\": {\n \"prompt_tokens\": 1000,\n \"completion_tokens\": 500,\n \"cache_read_tokens\": 0,\n \"cache_write_tokens\": 0,\n \"reasoning_tokens\": 0,\n \"web_search_count\": 0\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.narev.ai/v1/traces/cost")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"model_id\": \"gpt-4o\",\n \"provider_id\": \"openai\",\n \"usage\": {\n \"prompt_tokens\": 1000,\n \"completion_tokens\": 500,\n \"cache_read_tokens\": 0,\n \"cache_write_tokens\": 0,\n \"reasoning_tokens\": 0,\n \"web_search_count\": 0\n }\n}"
response = http.request(request)
puts response.read_body{
"model_id": "<string>",
"provider_id": "<string>",
"cost_breakdown": {
"total": 123
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"model_id": "<string>",
"provider_id": "<string>",
"cost_breakdown": null,
"error": "<string>"
}{
"model_id": "<string>",
"provider_id": "<string>",
"cost_breakdown": null,
"error": "<string>"
}Calculate cost for trace
Given a model ID, provider, and token usage, returns an itemized cost breakdown in USD.
POST
/
v1
/
traces
/
cost
Calculate cost for a model call
curl --request POST \
--url https://api.narev.ai/v1/traces/cost \
--header 'Content-Type: application/json' \
--data '
{
"model_id": "gpt-4o",
"provider_id": "openai",
"usage": {
"prompt_tokens": 1000,
"completion_tokens": 500,
"cache_read_tokens": 0,
"cache_write_tokens": 0,
"reasoning_tokens": 0,
"web_search_count": 0
}
}
'import requests
url = "https://api.narev.ai/v1/traces/cost"
payload = {
"model_id": "gpt-4o",
"provider_id": "openai",
"usage": {
"prompt_tokens": 1000,
"completion_tokens": 500,
"cache_read_tokens": 0,
"cache_write_tokens": 0,
"reasoning_tokens": 0,
"web_search_count": 0
}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
model_id: 'gpt-4o',
provider_id: 'openai',
usage: {
prompt_tokens: 1000,
completion_tokens: 500,
cache_read_tokens: 0,
cache_write_tokens: 0,
reasoning_tokens: 0,
web_search_count: 0
}
})
};
fetch('https://api.narev.ai/v1/traces/cost', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.narev.ai/v1/traces/cost",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model_id' => 'gpt-4o',
'provider_id' => 'openai',
'usage' => [
'prompt_tokens' => 1000,
'completion_tokens' => 500,
'cache_read_tokens' => 0,
'cache_write_tokens' => 0,
'reasoning_tokens' => 0,
'web_search_count' => 0
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.narev.ai/v1/traces/cost"
payload := strings.NewReader("{\n \"model_id\": \"gpt-4o\",\n \"provider_id\": \"openai\",\n \"usage\": {\n \"prompt_tokens\": 1000,\n \"completion_tokens\": 500,\n \"cache_read_tokens\": 0,\n \"cache_write_tokens\": 0,\n \"reasoning_tokens\": 0,\n \"web_search_count\": 0\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.narev.ai/v1/traces/cost")
.header("Content-Type", "application/json")
.body("{\n \"model_id\": \"gpt-4o\",\n \"provider_id\": \"openai\",\n \"usage\": {\n \"prompt_tokens\": 1000,\n \"completion_tokens\": 500,\n \"cache_read_tokens\": 0,\n \"cache_write_tokens\": 0,\n \"reasoning_tokens\": 0,\n \"web_search_count\": 0\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.narev.ai/v1/traces/cost")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"model_id\": \"gpt-4o\",\n \"provider_id\": \"openai\",\n \"usage\": {\n \"prompt_tokens\": 1000,\n \"completion_tokens\": 500,\n \"cache_read_tokens\": 0,\n \"cache_write_tokens\": 0,\n \"reasoning_tokens\": 0,\n \"web_search_count\": 0\n }\n}"
response = http.request(request)
puts response.read_body{
"model_id": "<string>",
"provider_id": "<string>",
"cost_breakdown": {
"total": 123
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"model_id": "<string>",
"provider_id": "<string>",
"cost_breakdown": null,
"error": "<string>"
}{
"model_id": "<string>",
"provider_id": "<string>",
"cost_breakdown": null,
"error": "<string>"
}Body
application/json
Example:
"gpt-4o"
Available options:
aionlabs, anthropic, arcee, baseten, bedrock, cerebras, charm, chutes, cloudflare, cohere, deepinfra, deepseek, fireworks, github-models, gmi, google_ai_studio, groq, inception, interfaze, minimax, mistral, moonshot, nebius, novita, nvidia, openai, sambanova, siliconflow, stepfun, together, venice, xai, xiaomi, zai, 302ai, abacus, abliteration-ai, aihubmix, alibaba, alibaba-cn, alibaba-coding-plan, alibaba-coding-plan-cn, alibaba-token-plan, alibaba-token-plan-cn, ambient, anyapi, atomic-chat, auriko, azure, azure-cognitive-services, bailing, berget, clarifai, claudinio, cloudferro-sherlock, cloudflare-ai-gateway, cloudflare-workers-ai, cortecs, crof, databricks, digitalocean, dinference, drun, evroc, fastrouter, freemodel, friendli, frogbot, github-copilot, gitlab, gmicloud, google-vertex, google-vertex-anthropic, helicone, hpc-ai, huggingface, iflowcn, inceptron, inference, io-net, jiekou, kenari, kimi-for-coding, kuae-cloud-coding-plan, lilac, llama, llmgateway, llmtr, lmstudio, longcat, lucidquery, meganova, merge-gateway, minimax-cn, minimax-cn-coding-plan, minimax-coding-plan, mixlayer, moark, modelscope, moonshotai-cn, morph, nano-gpt, nearai, neon, neuralwatt, nova, ollama-cloud, opencode, opencode-go, orcarouter, ovhcloud, perplexity, perplexity-agent, poe, poolside, privatemode-ai, qihang-ai, qiniu-ai, regolo-ai, requesty, routing-run, sakana, sap-ai-core, sarvam, scaleway, siliconflow-cn, snowflake-cortex, stackit, stepfun-ai, subconscious, submodel, synthetic, tencent-coding-plan, tencent-token-plan, tencent-tokenhub, the-grid-ai, tinfoil, trustedrouter, umans-ai, umans-ai-coding-plan, upstage, v0, vercel, vivgrid, vultr, wafer.ai, wandb, xiaomi-token-plan-ams, xiaomi-token-plan-cn, xiaomi-token-plan-sgp, xpersona, zai-coding-plan, zeldoc, zenmux, zhipuai, zhipuai-coding-plan Example:
"openai"
Show child attributes
Show child attributes
Was this page helpful?