> ## Documentation Index
> Fetch the complete documentation index at: https://docs.genlook.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Product Stats

> Per-product generation counts and average duration, optionally windowed by date.

Returns generation counts and average duration for a single product. Useful for dashboards that surface "this product was tried on N times this month" or for spotting failure spikes per SKU.

## Path Parameters

<ParamField path="externalId" type="string" required>
  Your product identifier. Works for both catalog products (created via `POST /products`) and inline-created products (including `_anon_*` IDs).
</ParamField>

## Query Parameters

<ParamField query="from" type="string">
  ISO 8601 timestamp. Only count generations created at or after this time. Omit for lifetime stats.
</ParamField>

<ParamField query="to" type="string">
  ISO 8601 timestamp. Only count generations created at or before this time. Omit for lifetime stats.
</ParamField>

<RequestExample>
  ```bash cURL (lifetime) theme={null}
  curl "https://api.genlook.app/tryon/v1/products/shirt-42/stats" \
    -H "x-api-key: gk_your_api_key"
  ```

  ```bash cURL (windowed) theme={null}
  curl "https://api.genlook.app/tryon/v1/products/shirt-42/stats?from=2026-04-01T00:00:00Z&to=2026-05-01T00:00:00Z" \
    -H "x-api-key: gk_your_api_key"
  ```

  ```ts Node SDK theme={null}
  import { Genlook } from "@genlook/api";

  const client = new Genlook({ apiKey: process.env.GENLOOK_API_KEY! });

  // Lifetime stats
  const lifetime = await client.products.stats("shirt-42");

  // Windowed — accepts Date or ISO strings
  const monthly = await client.products.stats("shirt-42", {
    from: new Date("2026-04-01T00:00:00Z"),
    to: new Date("2026-05-01T00:00:00Z"),
  });
  console.log(monthly.totalGenerations, monthly.avgGenerationTimeMs);
  ```
</RequestExample>

## Response

<ResponseField name="totalGenerations" type="integer" required>
  Total generations against this product in the window.
</ResponseField>

<ResponseField name="completedGenerations" type="integer" required>
  Subset that reached `COMPLETED`.
</ResponseField>

<ResponseField name="failedGenerations" type="integer" required>
  Subset that ended in `FAILED`.
</ResponseField>

<ResponseField name="avgGenerationTimeMs" type="integer" required>
  Average end-to-end duration of completed generations, in milliseconds. `0` if there are no completed generations in the window.
</ResponseField>

<ResponseExample>
  ```json Success theme={null}
  {
    "totalGenerations": 187,
    "completedGenerations": 181,
    "failedGenerations": 4,
    "avgGenerationTimeMs": 9120
  }
  ```

  ```json Product not found (404) theme={null}
  {
    "code": "PRODUCT_NOT_FOUND",
    "message": "Product 'shirt-42' not found.",
    "status": 404
  }
  ```
</ResponseExample>

## Notes

* `totalGenerations` includes pending and processing generations as well as completed and failed ones, so the four numbers don't always sum to the total.
* Stats are eventually consistent — a generation that just finished may take a few seconds to appear.
* For account-wide aggregates, sum the per-product stats yourself or use the Genlook dashboard.
