# Generation

> Returns Lykia's record of a single request: model, provider, token counts, cost, timing and the providers that were tried.

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

Lykia keeps a record of each request that reached a provider, and this endpoint returns the record for the request id you pass. The id is the `id` field of a [`POST /chat/completions`](https://www.getlykia.com/en/docs/api-reference/chat-completions) response (it starts with `gen-`), and also comes in its `X-Generation-Id` header; in a streamed response every chunk carries the same id. Requests rejected before any provider was tried, such as a `402` for an empty balance, have no record.

The record is written when the request finishes, so a request that is still running returns `404`; try again a few seconds later. Any API key of the project can read its records, and an id from another project behaves as if it does not exist.

## Query parameters

- `id` (string, required) — The request id, for example `gen-1795373724-YQhkPKb4HcCr0wWN`.

## Example

**Request**

cURL

```bash
curl "https://api.getlykia.com/v1/generation?id=gen-1795373724-YQhkPKb4HcCr0wWN" \
  -H "Authorization: Bearer $LYKIA_API_KEY"
```

Python

```python
import os

import requests

response = requests.get(
    "https://api.getlykia.com/v1/generation?id=gen-1795373724-YQhkPKb4HcCr0wWN",
    headers={"Authorization": f"Bearer {os.environ['LYKIA_API_KEY']}"},
    timeout=30,
)
response.raise_for_status()

generation = response.json()["data"]
print(generation["model_resolved"], generation["provider"], generation["status"])
print("cost (USD):", generation["cost"], "latency (ms):", generation["latency_ms"])
```

TypeScript

```typescript
const response = await fetch("https://api.getlykia.com/v1/generation?id=gen-1795373724-YQhkPKb4HcCr0wWN", {
  headers: { Authorization: `Bearer ${process.env.LYKIA_API_KEY}` },
});
if (!response.ok) {
  throw new Error(`Lykia returned ${response.status}: ${await response.text()}`);
}

const { data: generation } = await response.json();
console.log(generation.model_resolved, generation.provider, generation.status);
console.log("cost (USD):", generation.cost, "latency (ms):", generation.latency_ms);
```

Go

```go
package main

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

func main() {
	req, err := http.NewRequest(http.MethodGet, "https://api.getlykia.com/v1/generation?id=gen-1795373724-YQhkPKb4HcCr0wWN", 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)
	}
	defer resp.Body.Close()

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

	var result struct {
		Data struct {
			ModelResolved string  `json:"model_resolved"`
			Provider      string  `json:"provider"`
			Status        string  `json:"status"`
			Cost          float64 `json:"cost"`
			LatencyMs     int     `json:"latency_ms"`
		} `json:"data"`
	}
	if err := json.Unmarshal(body, &result); err != nil {
		panic(err)
	}
	g := result.Data
	fmt.Println(g.ModelResolved, g.Provider, g.Status)
	fmt.Println("cost (USD):", g.Cost, "latency (ms):", g.LatencyMs)
}
```

**Response (200)**

```json
{
  "data": {
    "id": "gen-1795373724-YQhkPKb4HcCr0wWN",
    "created_at": "2026-11-22T18:55:24.863Z",
    "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": 27,
      "completion": 34,
      "reasoning": 0,
      "cache_read": 0,
      "cache_write": 0
    },
    "cost": 0.000024,
    "list_cost": 0.000024,
    "byok_fee": 0,
    "latency_ms": 1183,
    "ttft_ms": null,
    "attempts": [
      {
        "provider": "openai",
        "status": "ok",
        "latency_ms": 1182,
        "error": null
      }
    ],
    "app": {
      "referer": "https://example.com",
      "title": "Example Support Bot"
    },
    "user": "user-4821",
    "endpoint": "chat.completions",
    "preset": "text",
    "metadata": {
      "feature": "ticket-summary",
      "plan": "pro"
    },
    "cost_details": {
      "upstream_cost": 0.000024,
      "platform_fee": 0,
      "is_byok": false
    },
    "kind": "chat"
  }
}
```

## Response

- `data` (object)
  - `id` (string) — The request id.
  - `created_at` (string) — When the request was made, ISO 8601.
  - `model` (string) — The model you asked for.
  - `model_resolved` (string | null) — The model that actually served the request (for a failed request, the last one tried); different from `model` after a fallback.
  - `provider` (string | null) — The id of the provider that served the request (the last one tried, for a failed request; for example `openai`). The values are the `slug` values listed by [`GET /providers`](https://www.getlykia.com/en/docs/api-reference/providers).
  - `streamed` (boolean) — Whether the response was streamed.
  - `usage_type` (string) — How it was paid for: `credits`, `byok` (your own provider key; the provider bills you) or `free` (a free model).
  - `status` (string) — `ok`, `error` (every provider failed, or the provider failed during a stream) or `cancelled` (the client disconnected).
  - `finish_reason` (string | null) — Why generation stopped (`stop`, `length`, `tool_calls`…).
  - `tokens` (object) — Token counts: `prompt`, `completion`, `reasoning` (the model's thinking tokens), `cache_read` (input read from the cache) and `cache_write` (input written to the cache).
  - `cost` (number) — What was deducted from credits, in USD. Always `0` for BYOK requests.
  - `list_cost` (number) — The request's value at list price, in USD. Equal to `cost` when you pay with credits; for BYOK, the list-price equivalent of what the provider bills you.
  - `byok_fee` (number) — The fee for this request when the company's BYOK usage is past the plan's monthly allowance, in USD; otherwise `0`. It is deducted from credits the next day, together with the project's other BYOK fees for that day.
  - `latency_ms` (integer) — Total duration of the request, in milliseconds.
  - `ttft_ms` (integer | null) — For streamed requests, the time until the first chunk arrived, in milliseconds. `null` for requests that were not streamed.
  - `attempts` (array) — The providers tried, in order, each with `provider`, `status` (`ok`, `error` or `cancelled`), `latency_ms` and `error` (the reason it failed, or `null`). Failed attempts are not billed.
  - `app` (object) — The `HTTP-Referer` and `X-Title` headers sent with the request, as `referer` and `title`.
  - `user` (string | null) — The `user` tag you sent in the request.
  - `endpoint` (string) — Which endpoint served the request: `chat.completions`, `embeddings`, `images.generations`, `videos`, `audio.speech`, `audio.transcriptions` or `audio.voices`.
  - `kind` (string) — What the request produced: `chat`, `embedding`, `image`, `video`, `speech`, `transcription` or `voice` (a voice clone).
  - `preset` (string | null) — The preset name when `model` was `@name` (without the `@`), otherwise `null`. `model` is then the real model the preset pointed to.
  - `metadata` (object) — The `metadata` tags you sent, or `{}`.
  - `cost_details` (object) — `upstream_cost` (list-price value), `platform_fee` (BYOK fee for this request) and `is_byok`, as in the response's `usage.cost_details`.
  - `media` (object) — Only on image, video, speech, transcription and voice records:
    - `units` (object) — What was billed, such as `image`, `second`, `character` or `tokens`.
    - `units_estimated` (boolean) — `true` when the provider did not report the units and Lykia's reservation estimate was used.
    - `billed_by_provider` (boolean) — `true` when the provider charged for a rejected or failed request; that cost is charged.
    - `job_id` (string | null) — The video job id (the same as the record id).
    - `outputs` (integer) — How many output files Lykia stored.

A video job's record is written when the job ends; its id is the job id:

```json
{
    "data": {
        "id": "gen-1795463406-qOWSYdRnX7cEsv8q",
        "created_at": "2026-11-23T19:50:06.503Z",
        "model": "bytedance/seedance-1.0-pro",
        "model_resolved": "bytedance/seedance-1.0-pro",
        "provider": "bytedance",
        "streamed": false,
        "usage_type": "credits",
        "status": "ok",
        "finish_reason": null,
        "tokens": {
            "prompt": 0,
            "completion": 0,
            "reasoning": 0,
            "cache_read": 0,
            "cache_write": 0
        },
        "cost": 0.2574,
        "list_cost": 0.2574,
        "byok_fee": 0,
        "latency_ms": 33380,
        "ttft_ms": null,
        "attempts": [],
        "app": {
            "referer": null,
            "title": null
        },
        "user": null,
        "endpoint": "videos",
        "preset": null,
        "metadata": {},
        "cost_details": {
            "upstream_cost": 0.2574,
            "platform_fee": 0,
            "is_byok": false
        },
        "kind": "video",
        "media": {
            "units": {
                "tokens": 108000
            },
            "units_estimated": false,
            "billed_by_provider": false,
            "job_id": "gen-1795463406-qOWSYdRnX7cEsv8q",
            "outputs": 1
        }
    }
}
```

To list several records at once, filtered by user, preset, model or metadata, use [`GET /generations`](https://www.getlykia.com/en/docs/api-reference/generations).

> **Note:** This response does not include the prompt or the model's answer. Prompt and response text is stored only when prompt logging is turned on for the project, and you view it in the dashboard; see [Privacy and logging](https://www.getlykia.com/en/docs/guides/privacy-and-logging).

Records are deleted automatically when the retention period set by Lykia ends (90 days by default).
