> This page is for Gateway.

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

# Get shadow comparison

GET https://api-gateway.merge.dev/v1/migrations/{migration_id}/comparison

Baseline-vs-candidate runtime metrics from shadow-mirror traffic.

Same window scoping as the dashboard: default lower bound = current
shadow-run start; upper bound = the cutover instant once completed/reverted;
explicit ``start_time`` / ``end_time`` override. Returns zeroed sides when
ES logging isn't configured, the migration never shadowed, or nothing has
been mirrored yet.

Reference: https://docs.merge.dev/merge-gateway/migrations-api/migrations/get-shadow-comparison

## Authentication

- `Authorization` header (bearer token, required) — Your gateway API key (mg_ prefix), the same key used for /v1/responses

## Request

### Path parameters

- `migration_id` (string, required)

### Query parameters

- `start_time` (string, optional, nullable)
- `end_time` (string, optional, nullable)

## Response

### 200

Successful Response

- `migration_id` (string, required)
- `baseline` (VariantMetricsOut, required) — Aggregated runtime metrics for one side of a migration (baseline or candidate).
- `candidate` (VariantMetricsOut, required) — Aggregated runtime metrics for one side of a migration (baseline or candidate).

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### VariantMetricsOut

Aggregated runtime metrics for one side of a migration (baseline or candidate).

- `model` (string, required)
- `request_count` (integer, optional, default: 0)
- `success_count` (integer, optional, default: 0)
- `error_count` (integer, optional, default: 0)
- `total_cost_usd` (double, optional, default: 0)
- `avg_cost_usd` (double, optional, default: 0)
- `avg_prompt_tokens` (double, optional, default: 0)
- `avg_completion_tokens` (double, optional, default: 0)
- `avg_total_tokens` (double, optional, default: 0)
- `avg_latency_ms` (double, optional, default: 0)

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `input` (any, optional)
- `ctx` (ValidationErrorCtx, optional)

### ValidationErrorLocItems

- string
- integer

### ValidationErrorCtx

## Examples

**Response**

```json
{
  "migration_id": "string",
  "baseline": {
    "model": "string",
    "request_count": 0,
    "success_count": 0,
    "error_count": 0,
    "total_cost_usd": 0,
    "avg_cost_usd": 0,
    "avg_prompt_tokens": 0,
    "avg_completion_tokens": 0,
    "avg_total_tokens": 0,
    "avg_latency_ms": 0
  },
  "candidate": {
    "model": "string",
    "request_count": 0,
    "success_count": 0,
    "error_count": 0,
    "total_cost_usd": 0,
    "avg_cost_usd": 0,
    "avg_prompt_tokens": 0,
    "avg_completion_tokens": 0,
    "avg_total_tokens": 0,
    "avg_latency_ms": 0
  }
}
```

**SDK Code**

```python
import requests

url = "https://api-gateway.merge.dev/v1/migrations/migration_id/comparison"

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

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

print(response.json())
```

```javascript
const url = 'https://api-gateway.merge.dev/v1/migrations/migration_id/comparison';
const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};

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"
	"net/http"
	"io"
)

func main() {

	url := "https://api-gateway.merge.dev/v1/migrations/migration_id/comparison"

	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(res)
	fmt.Println(string(body))

}
```

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

url = URI("https://api-gateway.merge.dev/v1/migrations/migration_id/comparison")

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

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

HttpResponse<String> response = Unirest.get("https://api-gateway.merge.dev/v1/migrations/migration_id/comparison")
  .header("Authorization", "Bearer <token>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://api-gateway.merge.dev/v1/migrations/migration_id/comparison', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api-gateway.merge.dev/v1/migrations/migration_id/comparison");
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api-gateway.merge.dev/v1/migrations/migration_id/comparison")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

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