> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.runtype.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.runtype.com/_mcp/server.

# Query traces

POST https://api.runtype.com/v1/logs/trace/query
Content-Type: application/json

Filter runs and group them by one or two dimensions into aggregates (count, failure rate, tokens, cost, duration, tool calls, signal fire rate), each with sample execution ids to drill into. Reads trace headers on indexed columns; model and tool-call metrics probe spans and cap the window at 7 days.

Reference: https://docs.runtype.com/api-reference/runtype-api/logs/query-traces

## Authentication

- `Authorization` header (bearer token, required) — API key or Clerk session token

## Servers

- `https://api.runtype.com` (Production, default)
- `https://api.runtype-staging.com` (Staging)

## Request

### Body (application/json)

This endpoint expects a TraceQueryRequest.

- `agentIds` (list of string, optional)
- `agentVersionIds` (list of string, optional) — Hosted runs carry no agentVersionId on the trace header yet, so this filter matches ingested runs only.
- `cursor` (string, optional)
- `flowIds` (list of string, optional)
- `from` (string, optional) — ISO 8601; default 7 days before `to`.
- `groupBy` (list of enum, optional)
  - Allowed values: `agent`, `agent_version`, `flow`, `surface`, `model`, `source`, `status`, `stop_reason`, `day`
- `includeChildren` (boolean, optional) — Count subagent and nested-flow runs too; unscoped reads fold them by default.
- `includeToolCalls` (boolean, optional) — Tool-call percentiles per group. Reads spans, so the window is capped at 7 days. Default false.
- `limit` (integer, optional)
- `model` (string, optional) — Runs with any model call to this model. Reads spans, so the window is capped at 7 days.
- `signal` (string, optional) — Runs where this signal fired: `key` or `key:value`.
- `signalRate` (string, optional) — Fire rate of this signal (`key` or `key:value`) per group; uniform and filtered samples are reported apart.
- `source` (enum, optional)
  - Allowed values: `hosted`, `ingested`
- `status` (enum, optional)
  - Allowed values: `running`, `completed`, `failed`
- `stopReason` (string, optional)
- `surfaceId` (string, optional)
- `to` (string, optional) — ISO 8601; default now. Windows over 30 days are refused.

## Response

### 200

Aggregates

- `data` (TraceQueryResult, required)
- `success` (boolean, required)

## Errors

### 400 Bad Request Error

Unreadable filter, window over the cap, or too many runs to probe; `code` says which

- `error` (string, required)
- `code` (string, optional) — Stable error code. `insufficient_scope` marks an API key that lacks a scope this request needs.
- `details` (list of ErrorDetailsItems, optional)
- `requiredScopes` (list of string, optional) — On `insufficient_scope`: every API key scope this request needs.

### 401 Unauthorized Error

Unauthorized

- `error` (string, required)
- `code` (string, optional) — Stable error code. `insufficient_scope` marks an API key that lacks a scope this request needs.
- `details` (list of ErrorDetailsItems, optional)
- `requiredScopes` (list of string, optional) — On `insufficient_scope`: every API key scope this request needs.

### 403 Forbidden Error

API key lacks a read scope (FLOWS:READ, AGENTS:READ or ANALYTICS:READ)

- `error` (string, required)
- `code` (string, optional) — Stable error code. `insufficient_scope` marks an API key that lacks a scope this request needs.
- `details` (list of ErrorDetailsItems, optional)
- `requiredScopes` (list of string, optional) — On `insufficient_scope`: every API key scope this request needs.

### 500 Internal Server Error

Internal server error

- `error` (string, required)
- `code` (string, optional) — Stable error code. `insufficient_scope` marks an API key that lacks a scope this request needs.
- `details` (list of ErrorDetailsItems, optional)
- `requiredScopes` (list of string, optional) — On `insufficient_scope`: every API key scope this request needs.

### 503 Service Unavailable Error

Log store temporarily unavailable; no entries or counts could be read

- `error` (string, required)
- `code` (string, optional) — Stable error code. `insufficient_scope` marks an API key that lacks a scope this request needs.
- `details` (list of ErrorDetailsItems, optional)
- `requiredScopes` (list of string, optional) — On `insufficient_scope`: every API key scope this request needs.

## Types

### TraceQueryResult

- `groupBy` (list of enum, required)
  - Allowed values: `agent`, `agent_version`, `flow`, `surface`, `model`, `source`, `status`, `stop_reason`, `day`
- `groups` (list of TraceQueryResultGroupsItems, required)
- `nextCursor` (string, required, nullable)
- `totals` (TraceQueryResultTotals, required)
- `truncated` (boolean, required)
- `warnings` (list of TraceQueryResultWarningsItems, required)
- `window` (TraceQueryResultWindow, required)

### ErrorDetailsItems

- `message` (string, required)
- `code` (string, optional) — Stable Runtype validation code (e.g. MISSING_REQUIRED_FIELD, INVALID_ENUM).
- `path` (string, optional) — Dotted JSON path to the offending field.
- `suggestion` (string, optional) — Actionable hint (allowed values, accepted range, …).

### TraceQueryResultGroupsItems

- `cost` (TraceQueryResultGroupsItemsCost, required)
- `count` (double, required)
- `durationMs` (TraceQueryResultGroupsItemsDurationMs, required)
- `failed` (double, required)
- `failureRate` (double, required, nullable)
- `key` (map from string to string, required)
- `sampleExecutionIds` (list of string, required)
- `tokens` (TraceQueryResultGroupsItemsTokens, required)
- `toolCalls` (TraceQueryResultGroupsItemsToolCalls, required, nullable)
- `signalRate` (TraceQueryResultGroupsItemsSignalRate, optional)

### TraceQueryResultTotals

- `cost` (TraceQueryResultTotalsCost, required)
- `count` (double, required)
- `durationMs` (TraceQueryResultTotalsDurationMs, required)
- `failed` (double, required)
- `failureRate` (double, required, nullable)
- `tokens` (TraceQueryResultTotalsTokens, required)
- `toolCalls` (TraceQueryResultTotalsToolCalls, required, nullable)
- `signalRate` (TraceQueryResultTotalsSignalRate, optional)

### TraceQueryResultWarningsItems

- `code` (string, required)
- `message` (string, required)

### TraceQueryResultWindow

- `from` (string, required)
- `to` (string, required)

### TraceQueryResultGroupsItemsCost

- `p50` (double, required, nullable)
- `p95` (double, required, nullable)
- `pricedRuns` (double, required)
- `sum` (double, required, nullable)
- `unpricedRuns` (double, required)

### TraceQueryResultGroupsItemsDurationMs

- `p50` (double, required, nullable)
- `p95` (double, required, nullable)

### TraceQueryResultGroupsItemsTokens

- `p50` (double, required, nullable)
- `p95` (double, required, nullable)
- `reportedRuns` (double, required)
- `sum` (double, required, nullable)

### TraceQueryResultGroupsItemsToolCalls

- `p50` (double, required, nullable)
- `p95` (double, required, nullable)

### TraceQueryResultGroupsItemsSignalRate

- `filtered` (TraceQueryResultGroupsItemsSignalRateFiltered, required)
- `uniform` (TraceQueryResultGroupsItemsSignalRateUniform, required)

### TraceQueryResultTotalsCost

- `p50` (double, required, nullable)
- `p95` (double, required, nullable)
- `pricedRuns` (double, required)
- `sum` (double, required, nullable)
- `unpricedRuns` (double, required)

### TraceQueryResultTotalsDurationMs

- `p50` (double, required, nullable)
- `p95` (double, required, nullable)

### TraceQueryResultTotalsTokens

- `p50` (double, required, nullable)
- `p95` (double, required, nullable)
- `reportedRuns` (double, required)
- `sum` (double, required, nullable)

### TraceQueryResultTotalsToolCalls

- `p50` (double, required, nullable)
- `p95` (double, required, nullable)

### TraceQueryResultTotalsSignalRate

- `filtered` (TraceQueryResultTotalsSignalRateFiltered, required)
- `uniform` (TraceQueryResultTotalsSignalRateUniform, required)

### TraceQueryResultGroupsItemsSignalRateFiltered

- `evaluated` (double, required)
- `fired` (double, required)
- `rate` (double, required, nullable)

### TraceQueryResultGroupsItemsSignalRateUniform

- `evaluated` (double, required)
- `fired` (double, required)
- `rate` (double, required, nullable)

### TraceQueryResultTotalsSignalRateFiltered

- `evaluated` (double, required)
- `fired` (double, required)
- `rate` (double, required, nullable)

### TraceQueryResultTotalsSignalRateUniform

- `evaluated` (double, required)
- `fired` (double, required)
- `rate` (double, required, nullable)

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "data": {
    "groupBy": [
      "agent"
    ],
    "groups": [
      {
        "cost": {
          "p50": 1.1,
          "p95": 1.1,
          "pricedRuns": 1.1,
          "sum": 1.1,
          "unpricedRuns": 1.1
        },
        "count": 1.1,
        "durationMs": {
          "p50": 1.1,
          "p95": 1.1
        },
        "failed": 1.1,
        "failureRate": 1.1,
        "key": {},
        "sampleExecutionIds": [
          "string"
        ],
        "tokens": {
          "p50": 1.1,
          "p95": 1.1,
          "reportedRuns": 1.1,
          "sum": 1.1
        },
        "toolCalls": {
          "p50": 1.1,
          "p95": 1.1
        },
        "signalRate": {
          "filtered": {
            "evaluated": 1.1,
            "fired": 1.1,
            "rate": 1.1
          },
          "uniform": {
            "evaluated": 1.1,
            "fired": 1.1,
            "rate": 1.1
          }
        }
      }
    ],
    "nextCursor": "string",
    "totals": {
      "cost": {
        "p50": 1.1,
        "p95": 1.1,
        "pricedRuns": 1.1,
        "sum": 1.1,
        "unpricedRuns": 1.1
      },
      "count": 1.1,
      "durationMs": {
        "p50": 1.1,
        "p95": 1.1
      },
      "failed": 1.1,
      "failureRate": 1.1,
      "tokens": {
        "p50": 1.1,
        "p95": 1.1,
        "reportedRuns": 1.1,
        "sum": 1.1
      },
      "toolCalls": {
        "p50": 1.1,
        "p95": 1.1
      },
      "signalRate": {
        "filtered": {
          "evaluated": 1.1,
          "fired": 1.1,
          "rate": 1.1
        },
        "uniform": {
          "evaluated": 1.1,
          "fired": 1.1,
          "rate": 1.1
        }
      }
    },
    "truncated": true,
    "warnings": [
      {
        "code": "string",
        "message": "string"
      }
    ],
    "window": {
      "from": "string",
      "to": "string"
    }
  },
  "success": true
}
```

**SDK Code**

```python
import requests

url = "https://api.runtype.com/v1/logs/trace/query"

payload = {}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.runtype.com/v1/logs/trace/query';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://api.runtype.com/v1/logs/trace/query"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

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

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

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.runtype.com/v1/logs/trace/query")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.runtype.com/v1/logs/trace/query")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.runtype.com/v1/logs/trace/query', [
  'body' => '{}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.runtype.com/v1/logs/trace/query");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.runtype.com/v1/logs/trace/query")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```