|
| 1 | +--- |
| 2 | +title: "Get costs by property" |
| 3 | +api: "GET https://api.traceloop.com/v2/costs/by-association-property" |
| 4 | +--- |
| 5 | + |
| 6 | +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). |
| 7 | + |
| 8 | +## Request Parameters |
| 9 | + |
| 10 | +<ParamField query="property_name" type="string" required> |
| 11 | + The name of the association property to group costs by (e.g., "user_id", "session_id"). |
| 12 | +</ParamField> |
| 13 | + |
| 14 | +<ParamField query="start_time" type="string" required> |
| 15 | + The start time in ISO 8601 format (e.g., "2025-04-15T00:00:00Z"). |
| 16 | +</ParamField> |
| 17 | + |
| 18 | +<ParamField query="end_time" type="string" required> |
| 19 | + The end time in ISO 8601 format (e.g., "2025-04-28T23:00:00Z"). |
| 20 | +</ParamField> |
| 21 | + |
| 22 | +<ParamField query="env" type="string"> |
| 23 | + List of environments to include in the calculation. Separated by comma. |
| 24 | +</ParamField> |
| 25 | + |
| 26 | +<ParamField query="selected_token_types" type="string"> |
| 27 | + <span style={{backgroundColor: '#10b981', color: 'white', padding: '2px 6px', borderRadius: '4px', fontSize: '12px', fontWeight: 'bold'}}>NEW</span> Filter costs by specific token types. Separate multiple types with commas. |
| 28 | + |
| 29 | + **Supported token types:** |
| 30 | + - `input_tokens` or `prompt_tokens` (automatically normalized to `prompt_tokens`) |
| 31 | + - `output_tokens` or `completion_tokens` (automatically normalized to `completion_tokens`) |
| 32 | + - `cache_read_input_tokens` |
| 33 | + - `cache_creation_input_tokens` |
| 34 | + - Other token types as they appear in your data |
| 35 | + |
| 36 | + **Note:** `total_tokens` cannot be used as a filter. |
| 37 | + |
| 38 | + **Examples:** |
| 39 | + - `selected_token_types=input_tokens,output_tokens` |
| 40 | + - `selected_token_types=prompt_tokens,cache_read_input_tokens` |
| 41 | + - `selected_token_types=completion_tokens` |
| 42 | + |
| 43 | + When this parameter is omitted, costs for all token types are included. |
| 44 | +</ParamField> |
| 45 | + |
| 46 | +## Response |
| 47 | + |
| 48 | +<ResponseField name="property_name" type="string"> |
| 49 | + The name of the property that was queried. |
| 50 | +</ResponseField> |
| 51 | + |
| 52 | +<ResponseField name="values" type="PropertyValue[]"> |
| 53 | + A list of property values and their associated costs. |
| 54 | +</ResponseField> |
| 55 | + |
| 56 | +<ResponseField name="total_cost" type="number"> |
| 57 | + The total cost across all property values. |
| 58 | +</ResponseField> |
| 59 | + |
| 60 | +```json |
| 61 | +{ |
| 62 | + "property_name": "session_id", |
| 63 | + "values": [ |
| 64 | + { |
| 65 | + "value": "session_21", |
| 66 | + "cost": 1.23 |
| 67 | + }, |
| 68 | + { |
| 69 | + "value": "session_5", |
| 70 | + "cost": 4.56 |
| 71 | + }, |
| 72 | + { |
| 73 | + "value": "No_Value", |
| 74 | + "cost": 0.78 |
| 75 | + } |
| 76 | + ], |
| 77 | + "total_cost": 6.57 |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +The API can return special values: |
| 82 | +- `"No_Association"` as property_name if no spans have the requested association properties |
| 83 | +- `"No_Value"` as a value for spans that don't have a value for the specified property |
| 84 | +- `"Unknown_Value"` for spans where the property exists but has an empty value |
0 commit comments