Generation
Look up a generation by its response or stream ID to retrieve confirmed token usage, the USD amount charged, and its interruption status.
GET /v1/generation looks up the confirmed ledger charge and usage for a Chat Completions, Messages, or Responses request. Use the response ID, or save the ID from the first stream event so you can reconcile an interrupted stream. This call is free: it is not billed and does not record usage.
Endpoint and authentication#
| Item | Value |
|---|---|
| Method and path | GET https://apis.opengateway.ai/v1/generation |
| Authentication | Required: Authorization: Bearer <key> |
| Query parameter | id (required): the client-visible generation ID from the response body or first stream event |
| Request body | None |
A key can look up only generations belonging to its team. An unknown ID and another team's ID both return 404. For an interrupted stream, see reconciling incomplete streams for the ID field to save and a backoff example.
curl -G 'https://apis.opengateway.ai/v1/generation' \-H "Authorization: Bearer $OPENGATEWAY_API_KEY" \--data-urlencode "id=$GENERATION_ID"
Response#
{"data": {"id": "chatcmpl_example","model": "openai/gpt-5-mini","created_at": "2026-11-19T05:00:00Z","tokens_prompt": 123,"tokens_completion": 45,"total_cost": 0.000123,"stream_interrupted": false}}
| Field | Type | Meaning |
|---|---|---|
data.id | string | Client-visible generation ID used in the query. |
data.model | string | Model ID of the final attempt. |
data.created_at | string | Time of the first attempt, in ISO 8601 format. |
data.tokens_prompt | integer | Prompt tokens summed over charged attempts. |
data.tokens_completion | integer | Completion tokens summed over charged attempts. |
data.total_cost | number | Confirmed total debited from the team balance in USD, including charged fallback attempts. |
data.stream_interrupted | boolean | true when the final attempt did not succeed, such as when a stream was cut or the attempt failed. |
The response contains no provider information or cost breakdown. Unlike response usage.cost, total_cost is the confirmed ledger value. Immediately after a price or discount change, usage.cost can differ until the price table refreshes (up to 5 minutes); use total_cost for budget reconciliation.
Errors and retries#
| Status | Code | When |
|---|---|---|
404 | generation_not_found | The ID is unknown or belongs to another team. A just-finished generation can also take a few seconds to be recorded, so retry shortly. |
404 | generation_pending | The generation has been recorded but its charge is not settled. Retry after the Retry-After header, which is 2 seconds. |
A generation remains pending while an attempt is awaiting price matching. A pending response is not a settled zero-dollar charge.
A pending response has this shape:
HTTP/1.1 404 Not FoundRetry-After: 2Content-Type: application/json{"error":{"message":"Generation chatcmpl_example is not recorded yet; retry shortly.","type":"not_found_error","code":"generation_pending"}}
An unknown or not-yet-recorded ID returns:
{"error": {"message": "Generation chatcmpl_example not found. A just-finished generation can take a few seconds to be recorded; retry shortly.","type": "not_found_error","code": "generation_not_found"}}
Poll with backoff for either of these 404 codes when a recent request may still be settling. Use a retry limit: an unknown ID or an ID from another team will not become available to this key.
Python example#
This example performs one lookup. For polling and Retry-After handling, see the streaming guide.
import jsonimport osfrom urllib.parse import urlencodefrom urllib.request import Request, urlopenquery = urlencode({"id": os.environ["GENERATION_ID"]})request = Request(f"https://apis.opengateway.ai/v1/generation?{query}",headers={"Authorization": f"Bearer {os.environ['OPENGATEWAY_API_KEY']}"},)with urlopen(request) as response:generation = json.load(response)["data"]print(generation["total_cost"])
JavaScript example#
const url = new URL("https://apis.opengateway.ai/v1/generation");url.searchParams.set("id", process.env.GENERATION_ID);const response = await fetch(url, {headers: { Authorization: `Bearer ${process.env.OPENGATEWAY_API_KEY}` },});const body = await response.json();if (!response.ok) throw new Error(`${body.error.code}: ${body.error.message}`);console.log(body.data.total_cost);