Skip to main content
GET
/
v2
/
costs
/
by-association-property
Get costs by property
curl --request GET \
  --url https://api.traceloop.com/v2/costs/by-association-property \
  --header 'Authorization: Bearer <token>'
import requests

url = "https://api.traceloop.com/v2/costs/by-association-property"

headers = {"Authorization": "Bearer <token>"}

response = requests.get(url, headers=headers)

print(response.text)
const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};

fetch('https://api.traceloop.com/v2/costs/by-association-property', 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.traceloop.com/v2/costs/by-association-property",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"net/http"
"io"
)

func main() {

url := "https://api.traceloop.com/v2/costs/by-association-property"

req, _ := http.NewRequest("GET", url, nil)

req.Header.Add("Authorization", "Bearer <token>")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.get("https://api.traceloop.com/v2/costs/by-association-property")
.header("Authorization", "Bearer <token>")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.traceloop.com/v2/costs/by-association-property")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
{
  "property_name": "<string>",
  "values": [
    {}
  ],
  "total_cost": 123
}
Query your LLM costs broken down by a specific association property. This helps you understand how costs are distributed across different values of a property (e.g., by user_id, session_id, or any other association property you track).

Request Parameters

property_name
string
required
The name of the association property to group costs by (e.g., “user_id”, “session_id”).
start_time
string
required
The start time in ISO 8601 format (e.g., “2025-04-15T00:00:00Z”).
end_time
string
required
The end time in ISO 8601 format (e.g., “2025-04-28T23:00:00Z”).
env
string
List of environments to include in the calculation. Separated by comma.
selected_token_types
string
NEW Filter costs by specific token types. Separate multiple types with commas.Supported token types:
  • input_tokens or prompt_tokens (automatically normalized to prompt_tokens)
  • output_tokens or completion_tokens (automatically normalized to completion_tokens)
  • cache_read_input_tokens
  • cache_creation_input_tokens
  • Other token types as they appear in your data
Note: total_tokens cannot be used as a filter.Examples:
  • selected_token_types=input_tokens,output_tokens
  • selected_token_types=prompt_tokens,cache_read_input_tokens
  • selected_token_types=completion_tokens
When this parameter is omitted, costs for all token types are included.

Response

property_name
string
The name of the property that was queried.
values
PropertyValue[]
A list of property values and their associated costs.
total_cost
number
The total cost across all property values.
{
  "property_name": "session_id",
  "values": [
    {
      "value": "session_21",
      "cost": 1.23
    },
    {
      "value": "session_5",
      "cost": 4.56
    },
    {
      "value": "No_Value",
      "cost": 0.78
    }
  ],
  "total_cost": 6.57
}
The API can return special values:
  • "No_Association" as property_name if no spans have the requested association properties
  • "No_Value" as a value for spans that don’t have a value for the specified property
  • "Unknown_Value" for spans where the property exists but has an empty value