> For the complete documentation index, see [llms.txt](https://docs.astralbeam.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.astralbeam.io/api-reference/stats.md).

# Statistics

Endpoints for bridge statistics and health monitoring.

## Get Bridge Statistics

Get overall bridge statistics with per-chain breakdown.

```
GET /api/v1/stats
```

### Query Parameters

| Name    | Type   | Description                         |
| ------- | ------ | ----------------------------------- |
| `chain` | string | Filter statistics to specific chain |

### Response

```json
{
  "success": true,
  "data": {
    "overall": {
      "totalTransactions": 50,
      "completedTransactions": 42,
      "last24Hours": {
        "eth2casper": 3,
        "casper2eth": 5
      }
    },
    "byChain": {
      "sepolia": {
        "transactionsByStatus": {
          "eth2casper": {
            "completed": 6,
            "detected": 1
          },
          "casper2eth": {
            "completed": 8,
            "detected": 4
          }
        },
        "volumes": {
          "byToken": {
            "USDC": { "volume": "500.00", "count": 3 },
            "sCSPR": { "volume": "6010.0", "count": 3 }
          }
        },
        "last24Hours": {
          "eth2casper": 0,
          "casper2eth": 2
        }
      },
      "base-sepolia": {
        "transactionsByStatus": {
          "eth2casper": {
            "completed": 6
          },
          "casper2eth": {
            "completed": 5
          }
        },
        "volumes": {
          "byToken": {
            "TEST": { "volume": "343.5", "count": 10 },
            "sCSPR": { "volume": "500.0", "count": 1 }
          }
        },
        "last24Hours": {
          "eth2casper": 0,
          "casper2eth": 1
        }
      },
      "casper": {
        "transactionsByStatus": {
          "eth2casper": {},
          "casper2eth": {
            "completed": 16,
            "detected": 4
          }
        },
        "volumes": {
          "byToken": {
            "sCSPR": { "volume": "11500.0", "count": 4 },
            "wCSPR": { "volume": "105.0", "count": 3 }
          }
        },
        "last24Hours": {
          "eth2casper": 0,
          "casper2eth": 4
        }
      }
    },
    "syncStates": {
      "sepolia": {
        "lastBlock": 7850000,
        "lastSyncedAt": "2026-01-25T03:30:00Z"
      },
      "base-sepolia": {
        "lastBlock": 22100000,
        "lastSyncedAt": "2026-01-25T03:30:00Z"
      }
    }
  }
}
```

### Chain Grouping Logic

Each EVM chain shows **both directions**:

* **eth2casper**: Transactions that started on that EVM chain (locks)
* **casper2eth**: Transactions that ended on that EVM chain (unlocks/mints from Casper)

The **casper** section is an aggregate of all Casper-originated transactions across all EVM chains. Use this to see total volume bridged from Casper, regardless of destination.

### Examples

**Get overall statistics:**

```bash
curl "https://api.csprbridge.com/api/v1/stats"
```

**Get statistics for specific chain:**

```bash
curl "https://api.csprbridge.com/api/v1/stats?chain=sepolia"
```

**Errors:**

| Status | Body                                                                                | When                                                          |
| ------ | ----------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| `400`  | `{ "error": "Unknown chain filter. Use one of the configured chain short names." }` | The `chain` query parameter does not match any enabled chain. |

***

## Get Per-Chain Statistics

Get transaction statistics for each enabled chain.

```
GET /api/v1/stats/chains
```

### Response

```json
{
  "success": true,
  "data": {
    "sepolia": {
      "chainId": 11155111,
      "chainName": "Ethereum Sepolia",
      "totalTransactions": 825,
      "completedTransactions": 800,
      "pendingTransactions": 20,
      "failedTransactions": 5,
      "successRate": 96.97,
      "avgCompletionTimeSeconds": 900,
      "last24Hours": {
        "transactions": 43,
        "volume": "150000000"
      }
    },
    "base-sepolia": {
      "chainId": 84532,
      "chainName": "Base Sepolia",
      "totalTransactions": 675,
      "completedTransactions": 650,
      "pendingTransactions": 20,
      "failedTransactions": 5,
      "successRate": 96.30,
      "avgCompletionTimeSeconds": 850,
      "last24Hours": {
        "transactions": 34,
        "volume": "100000000"
      }
    }
  }
}
```

### Example

```bash
curl "https://api.csprbridge.com/api/v1/stats/chains"
```

***

## Health Check

Check API and indexer health status.

```
GET /api/v1/stats/health
```

### Response (Healthy)

```json
{
  "success": true,
  "data": {
    "status": "healthy",
    "version": "0.10.0",
    "uptime": 86400,
    "timestamp": "2024-01-15T12:00:00Z",
    "components": {
      "database": {
        "status": "connected",
        "latencyMs": 5
      },
      "indexer": {
        "status": "synced",
        "lastProcessedBlock": 5100000,
        "blocksBehind": 0
      },
      "relayers": {
        "status": "healthy",
        "activeCount": 5,
        "requiredCount": 3
      }
    }
  }
}
```

### Response (Degraded)

```json
{
  "success": true,
  "data": {
    "status": "degraded",
    "version": "0.10.0",
    "uptime": 86400,
    "timestamp": "2024-01-15T12:00:00Z",
    "components": {
      "database": {
        "status": "connected",
        "latencyMs": 150
      },
      "indexer": {
        "status": "behind",
        "lastProcessedBlock": 5099000,
        "blocksBehind": 1000
      },
      "relayers": {
        "status": "degraded",
        "activeCount": 3,
        "requiredCount": 3
      }
    },
    "issues": [
      "Indexer is 1000 blocks behind",
      "Only 3 of 5 relayers active"
    ]
  }
}
```

### HTTP Status Codes

| Code | Meaning                                       |
| ---- | --------------------------------------------- |
| 200  | System is healthy or degraded but operational |
| 503  | System is unhealthy and not operational       |

### Example

```bash
# Simple health check
curl -w "%{http_code}" "https://api.csprbridge.com/api/v1/stats/health"

# Get detailed health info
curl "https://api.csprbridge.com/api/v1/stats/health" | jq '.data.components'
```

***

## Get Relayer Statistics

Get statistics for all bridge relayers.

```
GET /api/v1/stats/relayers
```

### Response

```json
{
  "success": true,
  "data": {
    "totalRelayers": 5,
    "activeRelayers": 5,
    "threshold": 3,
    "relayers": [
      {
        "address": "0x1234...5678",
        "status": "active",
        "lastSeen": "2024-01-15T11:59:00Z",
        "attestationsSubmitted": 500,
        "successRate": 99.8
      },
      {
        "address": "0xabcd...ef01",
        "status": "active",
        "lastSeen": "2024-01-15T11:59:30Z",
        "attestationsSubmitted": 485,
        "successRate": 99.5
      }
    ],
    "recentActivity": {
      "last1Hour": {
        "attestations": 45,
        "avgResponseTimeMs": 2500
      },
      "last24Hours": {
        "attestations": 1080,
        "avgResponseTimeMs": 2800
      }
    }
  }
}
```

### Example

```bash
curl "https://api.csprbridge.com/api/v1/stats/relayers"
```

***

## Statistics Schema

### Overall Statistics

| Field                   | Type    | Description                         |
| ----------------------- | ------- | ----------------------------------- |
| `totalTransactions`     | integer | Total transactions processed        |
| `completedTransactions` | integer | Successfully completed transactions |
| `failedTransactions`    | integer | Failed transactions                 |
| `pendingTransactions`   | integer | Currently pending transactions      |
| `totalVolume`           | string  | Total volume (raw token units)      |
| `last24Hours`           | object  | Transactions in last 24 hours       |

### Chain Statistics

| Field                      | Type    | Description                 |
| -------------------------- | ------- | --------------------------- |
| `chainId`                  | integer | EVM chain ID                |
| `chainName`                | string  | Display name                |
| `totalTransactions`        | integer | Transactions for this chain |
| `successRate`              | number  | Success percentage          |
| `avgCompletionTimeSeconds` | integer | Average completion time     |

### Sync State

| Field                  | Type    | Description                  |
| ---------------------- | ------- | ---------------------------- |
| `lastBlock`            | integer | Latest block on chain        |
| `lastProcessedBlock`   | integer | Latest processed by indexer  |
| `blocksBeforeFinality` | integer | Blocks required for finality |
| `isSynced`             | boolean | Whether indexer is synced    |

***

## Usage Examples

### Monitor Bridge Health

```javascript
async function monitorHealth() {
  const response = await fetch('https://api.csprbridge.com/api/v1/stats/health');

  if (!response.ok) {
    console.error('Bridge is DOWN');
    return;
  }

  const { data } = await response.json();

  if (data.status === 'healthy') {
    console.log('Bridge is healthy');
  } else if (data.status === 'degraded') {
    console.warn('Bridge is degraded:', data.issues);
  } else {
    console.error('Bridge is unhealthy');
  }
}

// Check every minute
setInterval(monitorHealth, 60000);
```

### Dashboard Statistics

```javascript
async function getDashboardStats() {
  const [statsRes, chainsRes] = await Promise.all([
    fetch('https://api.csprbridge.com/api/v1/stats'),
    fetch('https://api.csprbridge.com/api/v1/stats/chains')
  ]);

  const stats = await statsRes.json();
  const chains = await chainsRes.json();

  return {
    totalTransactions: stats.data.overall.totalTransactions,
    last24Hours: stats.data.overall.last24Hours.total,
    chainBreakdown: Object.entries(chains.data).map(([name, data]) => ({
      chain: name,
      transactions: data.totalTransactions,
      successRate: data.successRate
    }))
  };
}
```

### Python Health Check

```python
import requests
import sys

def check_health():
    try:
        response = requests.get(
            'https://api.csprbridge.com/api/v1/stats/health',
            timeout=10
        )

        if response.status_code == 503:
            print("CRITICAL: Bridge is unhealthy")
            sys.exit(2)

        data = response.json()['data']

        if data['status'] == 'degraded':
            print(f"WARNING: {', '.join(data.get('issues', []))}")
            sys.exit(1)

        print("OK: Bridge is healthy")
        sys.exit(0)

    except requests.RequestException as e:
        print(f"CRITICAL: Cannot reach API - {e}")
        sys.exit(2)

if __name__ == '__main__':
    check_health()
```

### curl with jq

```bash
# Get completion rate
curl -s "https://api.csprbridge.com/api/v1/stats" | \
  jq '.data.overall | {
    total: .totalTransactions,
    completed: .completedTransactions,
    rate: ((.completedTransactions / .totalTransactions) * 100 | round)
  }'

# Check sync status
curl -s "https://api.csprbridge.com/api/v1/stats" | \
  jq '.data.syncStates | to_entries[] | {chain: .key, synced: .value.isSynced}'

# Get 24h volume per chain
curl -s "https://api.csprbridge.com/api/v1/stats/chains" | \
  jq 'to_entries[] | {chain: .key, volume24h: .value.last24Hours.volume}'
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.astralbeam.io/api-reference/stats.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
