# Retrieve customer key statistics

Returns transaction counts, landed rate, median slots to land and tips for one customer key over the selected window.

Source: https://zerocopy.sh/docs/reference/management-api/retrieve-customer-key-statistics

`GET https://console.zerocopy.sh/api/v1/customer-keys/{id}/stats`

Authentication: API key, one of: `Authorization: Bearer` header.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes |  |
| `range` | query | `"24h"` or `"7d"` or `"30d"` | no | Trailing analytics window Default `"24h"`. |

## Responses

### 200

Its figures

Content type: `application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `key_id` | string | yes |  |
| `window` | `"24h"` or `"7d"` or `"30d"` | yes |  |
| `transactions` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `landed_rate` | number or null | yes |  |
| `p50_slots_to_land` | number or null | yes |  |
| `tips_lamports` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `last_seen_at` | string (date-time) or null | yes |  |

```json title="Customer-key traffic over seven days"
{
  "key_id": "key_012345abcdef",
  "window": "7d",
  "transactions": 1248,
  "landed_rate": 97.5,
  "p50_slots_to_land": 2,
  "tips_lamports": 3670000000,
  "last_seen_at": "2026-11-13T02:13:41Z"
}
```

### 400

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Invalid request"
{
  "title": "Bad request",
  "status": 400,
  "code": "invalid_request",
  "detail": "The request does not match the schema.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 401

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Unknown, revoked or expired management key"
{
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The management key is unknown, revoked or expired.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 403

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="IP restriction"
{
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden_ip",
  "detail": "This key does not allow requests from this address.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 404

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Unknown route"
{
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No such route.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 429

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Management read limit"
{
  "title": "Too many requests",
  "status": 429,
  "code": "rate_limited",
  "detail": "This key may make 600 such requests a minute.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

```json title="Concurrent analytics limit"
{
  "title": "Too many requests",
  "status": 429,
  "code": "analytics_busy",
  "detail": "This team already has two analytics reads running.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

## Code samples

```rust title="Rust"
// src/bin/management_customer_key_stats.rs
// Builds on the example project (/reference/json-rpc#example-project).
use swqos_examples::swqos::{Result, required};

#[tokio::main]
async fn main() -> Result<()> {
    let key_id: String = required("KEY_ID")?;
    let mut endpoint = reqwest::Url::parse("https://console.zerocopy.sh/api/v1/customer-keys/")?;
    endpoint.path_segments_mut().map_err(|_| "invalid base URL")?
        .pop_if_empty().push(&key_id);
    endpoint.path_segments_mut().map_err(|_| "invalid base URL")?.push("stats");
    endpoint.query_pairs_mut().append_pair("range", "7d");
    let request = reqwest::Client::new()
        .get(endpoint)
        .bearer_auth(required("MANAGEMENT_API_KEY")?);
    let response = request.send().await?;
    let status = response.status();
    let request_id = response.headers().get("Request-Id")
        .map(|value| value.to_str()).transpose()?.unwrap_or("<missing>").to_owned();
    if let Some(etag) = response.headers().get("ETag") {
        eprintln!("ETag: {}", etag.to_str()?);
    }
    let body = response.text().await?;
    if !status.is_success() {
        return Err(format!("HTTP {status}; Request-Id: {request_id}; {body}").into());
    }
    eprintln!("Request-Id: {request_id}");
    println!("{body}");
    Ok(())
}
```

```go title="Go"
// management_customer_key_stats/main.go
package main

import (
    "fmt"
    "io"
    "net/http"
    "net/url"
    "os"
)

func required(name string) (string, error) {
    value := os.Getenv(name)
    if value == "" {
        return "", fmt.Errorf("set %s", name)
    }
    return value, nil
}

func run() error {
    apiKey, err := required("MANAGEMENT_API_KEY")
    if err != nil {
        return err
    }
    keyID, err := required("KEY_ID")
    if err != nil {
        return err
    }
    endpoint, err := url.Parse("https://console.zerocopy.sh/api/v1/customer-keys/")
    if err != nil {
        return err
    }
    endpoint.Path += keyID
    endpoint.Path += "/stats"
    query := endpoint.Query()
    query.Set("range", "7d")
    endpoint.RawQuery = query.Encode()
    request, err := http.NewRequest(http.MethodGet, endpoint.String(), nil)
    if err != nil {
        return err
    }
    request.Header.Set("Authorization", "Bearer "+apiKey)
    response, err := http.DefaultClient.Do(request)
    if err != nil {
        return err
    }
    defer response.Body.Close()
    requestID := response.Header.Get("Request-Id")
    body, err := io.ReadAll(response.Body)
    if err != nil {
        return fmt.Errorf("Request-Id: %s: %w", requestID, err)
    }
    if response.StatusCode < 200 || response.StatusCode >= 300 {
        return fmt.Errorf("HTTP %d; Request-Id: %s; %s", response.StatusCode, requestID, body)
    }
    fmt.Fprintln(os.Stderr, "Request-Id:", requestID)
    if etag := response.Header.Get("ETag"); etag != "" {
        fmt.Fprintln(os.Stderr, "ETag:", etag)
    }
    fmt.Println(string(body))
    return nil
}

func main() {
    if err := run(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
}
```

```ts title="TypeScript"
// management-customer-key-stats.ts
export {}

function required(name: string): string {
  const value = process.env[name]
  if (!value) throw new Error(`set ${name}`)
  return value
}

const keyId: string = required('KEY_ID')
const endpoint = new URL('https://console.zerocopy.sh/api/v1/customer-keys/')
endpoint.pathname += encodeURIComponent(keyId)
endpoint.pathname += '/stats'
endpoint.searchParams.set('range', '7d')
const headers: Record<string, string> = {
  Authorization: `Bearer ${required('MANAGEMENT_API_KEY')}`,
}
const response = await fetch(endpoint, { method: 'GET', headers })
const requestId = response.headers.get('Request-Id')
const body = await response.text()
if (!response.ok) {
  throw new Error(`HTTP ${response.status}; Request-Id: ${requestId}; ${body}`)
}
console.error('Request-Id:', requestId)
const etag = response.headers.get('ETag')
if (etag) console.error('ETag:', etag)
console.log(body)
```
