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

# Interface

# Get generation

<Tip title="💡 Troubleshooting">
  Encountering errors? See the [API Error Codes Reference](/en/guide/advanced/error-codes) for a complete list of error types and troubleshooting steps.
</Tip>

```
GET https://api.agipower.ai/v1/management/generation?id=<generation_id>
```

<Warning title="⚠️ Previous URL deprecated">
  The previous endpoint `GET /v1/generation` is deprecated. Please migrate to the new URL `GET /v1/management/generation`. The old URL will be removed in a future release.
</Warning>

The Get generation endpoint is used to retrieve generation details, such as usage and costs.

<Tip>
  This endpoint supports retrieving generation details for all API protocols, including OpenAI Chat Completions, OpenAI Responses, Anthropic, and Vertex AI.
</Tip>

<Warning title="⚠️ Subscription Plan Limitations">
  This endpoint only supports billing queries for **Pay As You Go** API keys. If you call this endpoint with a subscription-plan API key (prefixed with `sk-ss-v1-`), billing-related fields (such as `usage`, `ratingResponses`, etc.) will not be returned.

  To retrieve billing information, please use a Pay As You Go API key. See:

  * [Pay As You Go Guide](../../guide/pay-as-you-go.md)
  * [Subscription Guide](../../guide/subscription.md)
</Warning>

## Metering and Billing Information

### Metering (Token Usage)

**Metering data** (e.g., token usage in the `nativeTokens` field) is returned **synchronously with the request** in the protocol’s native format:

* **OpenAI Chat Completions protocol**: returned in the response `usage` field
* **OpenAI Responses protocol**: returned in the response `usage` field
* **Anthropic protocol**: returned in the response `usage` field
* **Vertex AI protocol**: returned in the response `usageMetadata` field

### Billing (Billing & Costs)

**Billing data** (cost-related fields such as `usage`, `ratingResponses`, etc.) is **not currently returned synchronously** with the request. After the request completes, you must query it via this endpoint **3–5 minutes** later.

<Info title="💡 Billing upgrade in progress">
  We’re improving and upgrading our billing architecture to enable synchronous billing data in responses as soon as possible. Stay tuned!
</Info>

## Request params

### Authorization Header **Required**

**Header parameters:**

```http theme={null}
Authorization: Bearer <AGIPower_API_KEY>
```

* **Name**: `Authorization`
* **Format**: `Bearer &lt;API_KEY&gt;`
* **Description**: Your AGIPower API key
  * **Pay As You Go API key**: supports querying full metering and billing information
  * **Subscription API key** (prefixed with `sk-ss-v1-`): supports metering only; billing information is not supported

<Tip title="💡 Get an API key">
  - Pay As You Go API key: create one in the [AGIPower Console](https://agipower.ai/platform/pay-as-you-go)
  - Subscription API key: create one in the [Subscription Management](https://agipower.ai/platform/subscription)
</Tip>

### generate\_id `string` **Required**

**Query parameters:**

The generation id returned by AGIPower API endpoints. You can obtain it from:

* [Create Chat Completion](../openai/create-chat-completion.md) - OpenAI Chat Completions protocol
* [Create a Model Response](../openai/openai-responses.md) - OpenAI Responses protocol
* [Create Messages](../anthropic/create-messages-new.md) - Anthropic protocol
* [Generate Content](../vertexai/generate-content.md) - Vertex AI protocol

## Returns

### api `string`

API type. Values vary by protocol:

* `chat.completions` - OpenAI Chat Completions protocol
* `responses` - OpenAI Responses protocol
* `messages` - Anthropic protocol
* `generateContent` - Vertex AI protocol

### generationId `string`

The current generation id.

### model `string`

Model ID.

### createAt `string`

The time when the server received the inference request.

### generationTime `integer`

Total duration of this inference from first token to completion, in milliseconds.

### latency `integer`

Time to first token, in milliseconds.

### nativeTokens `object`

Usage information consumed by this inference, including:

* `completion_tokens` `integer` - Tokens used for the completion
* `prompt_tokens` `integer` - Tokens used for the prompt
* `total_tokens` `integer` - Total tokens
* `completion_tokens_details` `object` - Completion token details
  * `reasoning_tokens` `integer` - Tokens used for reasoning
* `prompt_tokens_details` `object` - Prompt token details
  * `cached_tokens` `integer` - Cached tokens

### streamed `boolean`

Whether the response is streamed.

### finishReason `string`

The reason the model stopped generating.

### usage `number`

Credits consumed by this inference.

### ratingResponses `object`

Billing response details, including:

* `billAmount` `number` - Billed amount
* `discountAmount` `number` - Discount amount
* `originAmount` `number` - Original amount
* `priceVersion` `string` - Price version
* `ratingDetails` `array` - Billing detail items, each containing:
  * `billAmount` `number` - Billed amount
  * `discountAmount` `number` - Discount amount
  * `feeItemCode` `string` - Fee item code (e.g., `completion`, `prompt`)
  * `originAmount` `number` - Original amount
  * `rate` `number` - Rate

### requestRetryTimes `integer`

Number of request retries.

### finalRetry `boolean`

Whether this is the final retry.

<Card title="GET /v1/management/generation">
  ```cURL theme={null}
  curl https://api.agipower.ai/v1/management/generation?id=<generation_id> \
    -H "Authorization: Bearer $AGIPower_API_KEY"
  ```
</Card>

<Card title="API Response">
  ```json theme={null}
  {
    "api": "chat.completions",
    "generationId": "gen_01abc123def456",
    "model": "openai/gpt-4o",
    "createAt": "2026-03-26T06:00:00.000Z",
    "generationTime": 3200,
    "latency": 500,
    "nativeTokens": {
      "completion_tokens": 128,
      "prompt_tokens": 32,
      "total_tokens": 160,
      "completion_tokens_details": {
        "reasoning_tokens": 0
      },
      "prompt_tokens_details": {
        "cached_tokens": 0
      }
    },
    "streamed": true,
    "finishReason": "stop",
    "usage": 0.0052,
    "ratingResponses": {
      "billAmount": 0.0052,
      "discountAmount": 0,
      "originAmount": 0.0052,
      "priceVersion": "v1",
      "ratingDetails": [
        {
          "billAmount": 0.0016,
          "discountAmount": 0,
          "feeItemCode": "prompt",
          "originAmount": 0.0016,
          "rate": 0.00005
        },
        {
          "billAmount": 0.0036,
          "discountAmount": 0,
          "feeItemCode": "completion",
          "originAmount": 0.0036,
          "rate": 0.00003
        }
      ]
    },
    "requestRetryTimes": 0,
    "finalRetry": false
  }
  ```
</Card>
