> 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.

# Compare traces

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

Structural diff of two executions (tool-sequence alignment, first divergence, per-side totals, shallow argument drift) or of two cohorts given as query filter sets (tool usage, stop reasons and signal rates over at most 50 sampled runs per side).

Reference: https://docs.runtype.com/api-reference/runtype-api/logs/compare-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 TraceCompareRequest.

- `left` (TraceCompareRequestLeft, required)
- `right` (TraceCompareRequestRight, required)
- `from` (string, optional)
- `sampleSize` (integer, optional)
- `to` (string, optional)

## Response

### 200

Comparison

- `data` (TraceCompare, 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.

### 404 Not Found Error

No trace for one of the executions

- `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

### TraceCompareRequestLeft

- TraceCompareRequestLeft0
- TraceCompareRequestLeft1

### TraceCompareRequestRight

- TraceCompareRequestRight0
- TraceCompareRequestRight1

### TraceCompare

- TraceCompare0
- TraceCompare1

### 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, …).

### TraceCompareRequestLeft0

- `executionId` (string, required)

### TraceCompareRequestLeft1

- `filters` (TraceCompareRequestLeftOneOf1Filters, required)

### TraceCompareRequestRight0

- `executionId` (string, required)

### TraceCompareRequestRight1

- `filters` (TraceCompareRequestRightOneOf1Filters, required)

### TraceCompare0

- `alignment` (list of TraceCompareOneOf0AlignmentItems, required)
- `divergence` (TraceCompareOneOf0Divergence, required, nullable)
- `left` (TraceCompareOneOf0Left, required)
- `mode` (enum, required)
  - Allowed values: `executions`
- `perTool` (list of TraceCompareOneOf0PerToolItems, required)
- `right` (TraceCompareOneOf0Right, required)
- `truncated` (TraceCompareOneOf0Truncated, required)

### TraceCompare1

- `left` (TraceCompareOneOf1Left, required)
- `mode` (enum, required)
  - Allowed values: `cohorts`
- `right` (TraceCompareOneOf1Right, required)
- `toolShareDelta` (list of TraceCompareOneOf1ToolShareDeltaItems, required)
- `window` (TraceCompareOneOf1Window, required)

### TraceCompareRequestLeftOneOf1Filters

- `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.
- `flowIds` (list of string, optional)
- `includeChildren` (boolean, optional) — Count subagent and nested-flow runs too; unscoped reads fold them by default.
- `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`.
- `source` (enum, optional)
  - Allowed values: `hosted`, `ingested`
- `status` (enum, optional)
  - Allowed values: `running`, `completed`, `failed`
- `stopReason` (string, optional)
- `surfaceId` (string, optional)

### TraceCompareRequestRightOneOf1Filters

- `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.
- `flowIds` (list of string, optional)
- `includeChildren` (boolean, optional) — Count subagent and nested-flow runs too; unscoped reads fold them by default.
- `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`.
- `source` (enum, optional)
  - Allowed values: `hosted`, `ingested`
- `status` (enum, optional)
  - Allowed values: `running`, `completed`, `failed`
- `stopReason` (string, optional)
- `surfaceId` (string, optional)

### TraceCompareOneOf0AlignmentItems

- `argDrift` (double, required, nullable)
- `leftIndex` (double, required, nullable)
- `op` (enum, required)
  - Allowed values: `match`, `left_only`, `right_only`, `reordered`
- `rightIndex` (double, required, nullable)
- `tool` (string, required)
- `driftedKeys` (list of string, optional)

### TraceCompareOneOf0Divergence

- `alignmentIndex` (double, required)
- `description` (string, required)
- `leftIndex` (double, required, nullable)
- `rightIndex` (double, required, nullable)

### TraceCompareOneOf0Left

- `cost` (double, required, nullable)
- `durationMs` (double, required, nullable)
- `executionId` (string, required)
- `inputTokens` (double, required, nullable)
- `outputTokens` (double, required, nullable)
- `source` (string, required)
- `status` (string, required, nullable)
- `stopReason` (string, required, nullable)
- `toolCalls` (double, required)
- `turns` (double, required, nullable)

### TraceCompareOneOf0PerToolItems

- `argDrift` (double, required, nullable)
- `leftCalls` (double, required)
- `leftErrors` (double, required)
- `rightCalls` (double, required)
- `rightErrors` (double, required)
- `tool` (string, required)

### TraceCompareOneOf0Right

- `cost` (double, required, nullable)
- `durationMs` (double, required, nullable)
- `executionId` (string, required)
- `inputTokens` (double, required, nullable)
- `outputTokens` (double, required, nullable)
- `source` (string, required)
- `status` (string, required, nullable)
- `stopReason` (string, required, nullable)
- `toolCalls` (double, required)
- `turns` (double, required, nullable)

### TraceCompareOneOf0Truncated

- `left` (boolean, required)
- `right` (boolean, required)

### TraceCompareOneOf1Left

- `executionIds` (list of string, required)
- `failureRate` (double, required, nullable)
- `sampleLimit` (double, required)
- `sampled` (double, required)
- `signalRates` (map from string to TraceCompareOneOf1LeftSignalRates, required)
- `stopReasons` (map from string to double, required)
- `toolUsage` (list of TraceCompareOneOf1LeftToolUsageItems, required)

### TraceCompareOneOf1Right

- `executionIds` (list of string, required)
- `failureRate` (double, required, nullable)
- `sampleLimit` (double, required)
- `sampled` (double, required)
- `signalRates` (map from string to TraceCompareOneOf1RightSignalRates, required)
- `stopReasons` (map from string to double, required)
- `toolUsage` (list of TraceCompareOneOf1RightToolUsageItems, required)

### TraceCompareOneOf1ToolShareDeltaItems

- `delta` (double, required)
- `left` (double, required)
- `right` (double, required)
- `tool` (string, required)

### TraceCompareOneOf1Window

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

### TraceCompareOneOf1LeftSignalRates

- `filtered` (TraceCompareOneOf1LeftSignalRatesFiltered, required)
- `uniform` (TraceCompareOneOf1LeftSignalRatesUniform, required)

### TraceCompareOneOf1LeftToolUsageItems

- `calls` (double, required)
- `callsPerRun` (double, required)
- `errors` (double, required)
- `runsUsing` (double, required)
- `shareOfRuns` (double, required)
- `tool` (string, required)

### TraceCompareOneOf1RightSignalRates

- `filtered` (TraceCompareOneOf1RightSignalRatesFiltered, required)
- `uniform` (TraceCompareOneOf1RightSignalRatesUniform, required)

### TraceCompareOneOf1RightToolUsageItems

- `calls` (double, required)
- `callsPerRun` (double, required)
- `errors` (double, required)
- `runsUsing` (double, required)
- `shareOfRuns` (double, required)
- `tool` (string, required)

### TraceCompareOneOf1LeftSignalRatesFiltered

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

### TraceCompareOneOf1LeftSignalRatesUniform

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

### TraceCompareOneOf1RightSignalRatesFiltered

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

### TraceCompareOneOf1RightSignalRatesUniform

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

## Examples

**Request**

```json
{
  "left": {
    "filters": {}
  },
  "right": {
    "filters": {}
  }
}
```

**Response**

```json
{
  "data": {
    "alignment": [
      {
        "argDrift": 1.1,
        "driftedKeys": [
          "string"
        ],
        "leftIndex": 1.1,
        "op": "match",
        "rightIndex": 1.1,
        "tool": "string"
      }
    ],
    "divergence": {
      "alignmentIndex": 1.1,
      "description": "string",
      "leftIndex": 1.1,
      "rightIndex": 1.1
    },
    "left": {
      "cost": 1.1,
      "durationMs": 1.1,
      "executionId": "string",
      "inputTokens": 1.1,
      "outputTokens": 1.1,
      "source": "string",
      "status": "string",
      "stopReason": "string",
      "toolCalls": 1.1,
      "turns": 1.1
    },
    "mode": "executions",
    "perTool": [
      {
        "argDrift": 1.1,
        "leftCalls": 1.1,
        "leftErrors": 1.1,
        "rightCalls": 1.1,
        "rightErrors": 1.1,
        "tool": "string"
      }
    ],
    "right": {
      "cost": 1.1,
      "durationMs": 1.1,
      "executionId": "string",
      "inputTokens": 1.1,
      "outputTokens": 1.1,
      "source": "string",
      "status": "string",
      "stopReason": "string",
      "toolCalls": 1.1,
      "turns": 1.1
    },
    "truncated": {
      "left": true,
      "right": true
    }
  },
  "success": true
}
```

**SDK Code**

```python
import requests

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

payload = {
    "left": { "filters": {} },
    "right": { "filters": {} }
}
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/compare';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"left":{"filters":{}},"right":{"filters":{}}}'
};

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/compare"

	payload := strings.NewReader("{\n  \"left\": {\n    \"filters\": {}\n  },\n  \"right\": {\n    \"filters\": {}\n  }\n}")

	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/compare")

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 = "{\n  \"left\": {\n    \"filters\": {}\n  },\n  \"right\": {\n    \"filters\": {}\n  }\n}"

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/compare")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"left\": {\n    \"filters\": {}\n  },\n  \"right\": {\n    \"filters\": {}\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.runtype.com/v1/logs/trace/compare', [
  'body' => '{
  "left": {
    "filters": {}
  },
  "right": {
    "filters": {}
  }
}',
  '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/compare");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"left\": {\n    \"filters\": {}\n  },\n  \"right\": {\n    \"filters\": {}\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

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

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.runtype.com/v1/logs/trace/compare")! 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()
```