POST
/
cost
/
query
Cost Query
curl --request POST \
  --url https://trace.wandb.ai/cost/query \
  --header 'Authorization: Basic <encoded-value>' \
  --header 'Content-Type: application/json' \
  --data '{
  "project_id": "entity/project",
  "fields": [
    "id",
    "llm_id",
    "prompt_token_cost",
    "completion_token_cost",
    "prompt_token_cost_unit",
    "completion_token_cost_unit",
    "effective_date",
    "provider_id"
  ],
  "query": {
    "$expr": {
      "$and": [
        {
          "$literal": "<any>"
        }
      ]
    }
  },
  "sort_by": [
    {
      "field": "<string>",
      "direction": "asc"
    }
  ],
  "limit": 10,
  "offset": 0
}'
{
  "results": [
    {
      "id": "2341-asdf-asdf",
      "llm_id": "gpt4",
      "prompt_token_cost": 1,
      "completion_token_cost": 1,
      "prompt_token_cost_unit": "USD",
      "completion_token_cost_unit": "USD",
      "effective_date": "2024-01-01T00:00:00Z",
      "provider_id": "openai"
    }
  ]
}

Authorizations

Authorization
string
header
required

Basic authentication header of the form Basic <encoded-value>, where <encoded-value> is the base64-encoded string username:password.

Body

application/json
project_id
string
required
Examples:

"entity/project"

fields
string[] | null
Examples:
[
"id",
"llm_id",
"prompt_token_cost",
"completion_token_cost",
"prompt_token_cost_unit",
"completion_token_cost_unit",
"effective_date",
"provider_id"
]
query
object | null

The top-level object for querying traced calls.

The Query wraps a single $expr, which uses Mongo-style aggregation operators to filter calls. This expression can combine logical conditions, comparisons, type conversions, and string matching.

Examples: ``` # Filter calls where op_name == "predict" { "$expr": { "$eq": [ {"$getField": "op_name"}, {"$literal": "predict"} ] } }

# Filter where a call's display name contains "llm"
{
"$expr": {
"$contains": {
"input": {"$getField": "display_name"},
"substr": {"$literal": "llm"},
"case_insensitive": true
}
}
}
```
sort_by
SortBy · object[] | null
limit
integer | null
Examples:

10

offset
integer | null
Examples:

0

Response

Successful Response

results
CostQueryOutput · object[]
required