# Generations

> Lists the request records of the calling key's project, newest first, with cursor paging and filters for user, preset, model, metadata and time range.

`GET https://api.getlykia.com/v1/generations`

Returns the project's request records, newest first, in pages. Each record has the same fields as [`GET /generation`](https://www.getlykia.com/en/docs/api-reference/generation). Use it to total the cost of one end user or one feature, to reconcile your own billing, or to find a request without knowing its id. Any API key of the project can read the project's records, and only those. Records are deleted when the retention period ends (90 days by default).

## Query parameters

- `limit` (integer) — Records per page, 1 to 200. Defaults to 50.
- `after` (string) — A cursor: the `next_cursor` of the previous page. Returns the records that come after it.
- `from` (string) — Only records created at or after this time (ISO 8601 date or date-time).
- `to` (string) — Only records created at or before this time.
- `user` (string) — Only records with this `user` tag.
- `preset` (string) — Only records made through this preset (the name, with or without `@`).
- `model` (string) — Only records served by this model.
- `metadata.<key>` (string) — Only records whose `metadata` has this key with this value, for example `metadata.feature=ticket-summary`. Up to 16 such filters; all must match.

An invalid parameter returns `400` with the code `invalid_query`.

## Example

Total what one end user's ticket summaries cost, page by page:

**cURL**

```bash
curl "https://api.getlykia.com/v1/generations?limit=20&user=tenant-42&metadata.feature=ticket-summary" \
  -H "Authorization: Bearer $LYKIA_API_KEY"
```

**Python**

```python
import os

import requests

params = {"limit": 50, "user": "tenant-42", "metadata.feature": "ticket-summary"}
total = 0.0
while True:
    response = requests.get(
        "https://api.getlykia.com/v1/generations",
        headers={"Authorization": f"Bearer {os.environ['LYKIA_API_KEY']}"},
        params=params,
        timeout=30,
    )
    response.raise_for_status()
    page = response.json()
    total += sum(record["cost"] for record in page["data"])
    if not page["next_cursor"]:
        break
    params["after"] = page["next_cursor"]

print(f"tenant-42 ticket summaries cost {total:.6f} USD")
```

**TypeScript**

```typescript
type Generation = { id: string; cost: number; preset: string | null; user: string | null };
type Page = { data: Generation[]; next_cursor: string | null };

const params = new URLSearchParams({ limit: "50", user: "tenant-42", "metadata.feature": "ticket-summary" });
let total = 0;
for (;;) {
  const response = await fetch(`https://api.getlykia.com/v1/generations?${params}`, {
    headers: { Authorization: `Bearer ${process.env.LYKIA_API_KEY}` },
  });
  if (!response.ok) throw new Error(`Lykia returned ${response.status}: ${await response.text()}`);
  const page = (await response.json()) as Page;
  total += page.data.reduce((sum, record) => sum + record.cost, 0);
  if (!page.next_cursor) break;
  params.set("after", page.next_cursor);
}
console.log(`tenant-42 ticket summaries cost ${total.toFixed(6)} USD`);
```

**Go**

```go
package main

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

type page struct {
	Data []struct {
		ID   string  `json:"id"`
		Cost float64 `json:"cost"`
	} `json:"data"`
	NextCursor *string `json:"next_cursor"`
}

func main() {
	params := url.Values{"limit": {"50"}, "user": {"tenant-42"}, "metadata.feature": {"ticket-summary"}}
	total := 0.0
	for {
		req, err := http.NewRequest(http.MethodGet, "https://api.getlykia.com/v1/generations?"+params.Encode(), nil)
		if err != nil {
			panic(err)
		}
		req.Header.Set("Authorization", "Bearer "+os.Getenv("LYKIA_API_KEY"))

		resp, err := http.DefaultClient.Do(req)
		if err != nil {
			panic(err)
		}
		body, _ := io.ReadAll(resp.Body)
		resp.Body.Close()
		if resp.StatusCode != http.StatusOK {
			panic(fmt.Sprintf("Lykia returned %d: %s", resp.StatusCode, body))
		}

		var p page
		if err := json.Unmarshal(body, &p); err != nil {
			panic(err)
		}
		for _, record := range p.Data {
			total += record.Cost
		}
		if p.NextCursor == nil {
			break
		}
		params.Set("after", *p.NextCursor)
	}
	fmt.Printf("tenant-42 ticket summaries cost %.6f USD\n", total)
}
```

```json
{
  "data": [
    {
      "id": "gen-1795457068-0edlh4VVDNydM3Ro",
      "created_at": "2026-11-23T18:04:28.933Z",
      "model": "openai/gpt-4o-mini",
      "model_resolved": "openai/gpt-4o-mini",
      "provider": "openai",
      "streamed": false,
      "usage_type": "credits",
      "status": "ok",
      "finish_reason": "stop",
      "tokens": {
        "prompt": 412,
        "completion": 96,
        "reasoning": 0,
        "cache_read": 0,
        "cache_write": 0
      },
      "cost": 0.000119,
      "list_cost": 0.000119,
      "byok_fee": 0,
      "latency_ms": 1180,
      "ttft_ms": null,
      "attempts": [
        {
          "provider": "openai",
          "status": "ok",
          "latency_ms": 1143,
          "error": null
        }
      ],
      "app": {
        "referer": null,
        "title": null
      },
      "user": "tenant-42",
      "endpoint": "chat.completions",
      "preset": "text",
      "metadata": {
        "feature": "ticket-summary"
      },
      "cost_details": {
        "upstream_cost": 0.000119,
        "platform_fee": 0,
        "is_byok": false
      },
      "kind": "chat"
    }
  ],
  "next_cursor": "gen-1795457068-0edlh4VVDNydM3Ro"
}
```

## Response

- `data` (array) — Request records, newest first. Each record has the fields described in [`GET /generation`](https://www.getlykia.com/en/docs/api-reference/generation), including `user`, `endpoint`, `kind`, `preset`, `metadata`, `cost_details` and, on media records, `media`.
- `next_cursor` (string | null) — Pass it as `after` to get the next page; `null` on the last page.

> **Note:** Records hold measurements, not content: the prompt and the answer are never returned here. A record appears a moment after its request finishes. For totals over long periods, the usage breakdown in the dashboard is faster than paging through records; see [Tags and usage breakdown](https://www.getlykia.com/en/docs/guides/tags-and-usage).
