---
title: Get usage history
---

[Skip to content](#_top)

[API Reference](https://developers.cloudflare.com/api/go)

[AI Gateway](https://developers.cloudflare.com/api/go/resources/ai_gateway)

[Billing](https://developers.cloudflare.com/api/go/resources/ai_gateway/subresources/billing)

Copy Markdown

Open in **Claude**Open in **ChatGPT**Open in **Cursor**

---

**Copy Markdown****View as Markdown**

# Get usage history

client.AIGateway.Billing.UsageHistory(ctx, params) (\*[BillingUsageHistoryResponse](<https://developers.cloudflare.com/api/go/resources/ai_gateway#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingUsageHistoryResponse%20%3E%20(schema)>), error)

GET/accounts/{account\_id}/ai-gateway/billing/usage-history

Retrieve aggregated usage meter event summaries for the given time range.

##### Security

<details>

<summary>API Token</summary>



The preferred authorization scheme for interacting with the Cloudflare API. <a href="https://developers.cloudflare.com/fundamentals/api/get-started/create-token/">Create a token</a>.

**Example:**<code>Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY</code>

</details>

<details>

<summary>API Email + API Key</summary>



The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

**Example:**<code>X-Auth-Email: user@example.com</code>

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

**Example:**<code>X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194</code>

</details>

##### Accepted Permissions (at least one required)

`AI Gateway Write``AI Gateway Read`

##### ParametersExpand Collapse

<details>

<summary>

params BillingUsageHistoryParams

</summary>

AccountID param.Field\[string]

Path param: Cloudflare account ID.

<a href="#(resource)%20ai_gateway.billing%20%3E%20(method)%20usage_history%20%3E%20(params)%20default%20%3E%20(param)%20account_id">Link to this property</a>

<details>

<summary>

ValueGroupingWindow param.Field\[<a href="https://developers.cloudflare.com/api/go/resources/ai_gateway/subresources/billing/methods/usage_history#(resource)%20ai_gateway.billing%20%3E%20(method)%20usage_history%20%3E%20(params)%20default%20%3E%20(param)%20value_grouping_window%20%3E%20(schema)">BillingUsageHistoryParamsValueGroupingWindow</a>]

Query param: Grouping window for usage data.

</summary>

const BillingUsageHistoryParamsValueGroupingWindowDay <a href="https://developers.cloudflare.com/api/go/resources/ai_gateway/subresources/billing/methods/usage_history#(resource)%20ai_gateway.billing%20%3E%20(method)%20usage_history%20%3E%20(params)%20default%20%3E%20(param)%20value_grouping_window%20%3E%20(schema)">BillingUsageHistoryParamsValueGroupingWindow</a> = "day"

<a href="#(resource)%20ai_gateway.billing%20%3E%20(method)%20usage_history%20%3E%20(params)%20default%20%3E%20(param)%20value_grouping_window%20%3E%20(schema)%20%3E%20(member)%200">Link to this property</a>

const BillingUsageHistoryParamsValueGroupingWindowHour <a href="https://developers.cloudflare.com/api/go/resources/ai_gateway/subresources/billing/methods/usage_history#(resource)%20ai_gateway.billing%20%3E%20(method)%20usage_history%20%3E%20(params)%20default%20%3E%20(param)%20value_grouping_window%20%3E%20(schema)">BillingUsageHistoryParamsValueGroupingWindow</a> = "hour"

<a href="#(resource)%20ai_gateway.billing%20%3E%20(method)%20usage_history%20%3E%20(params)%20default%20%3E%20(param)%20value_grouping_window%20%3E%20(schema)%20%3E%20(member)%201">Link to this property</a>

</details>

<a href="#(resource)%20ai_gateway.billing%20%3E%20(method)%20usage_history%20%3E%20(params)%20default%20%3E%20(param)%20value_grouping_window">Link to this property</a>

EndTime param.Field\[float64]Optional

Query param: End time as Unix timestamp in milliseconds.

<a href="#(resource)%20ai_gateway.billing%20%3E%20(method)%20usage_history%20%3E%20(params)%20default%20%3E%20(param)%20end_time">Link to this property</a>

StartTime param.Field\[float64]Optional

Query param: Start time as Unix timestamp in milliseconds.

<a href="#(resource)%20ai_gateway.billing%20%3E%20(method)%20usage_history%20%3E%20(params)%20default%20%3E%20(param)%20start_time">Link to this property</a>

</details>

[Link to this property](<#(resource)%20ai_gateway.billing%20%3E%20(method)%20usage_history%20%3E%20(params)%20default>)

##### ReturnsExpand Collapse

<details>

<summary>

type BillingUsageHistoryResponse struct{…}

</summary>

<details>

<summary>

History \[]BillingUsageHistoryResponseHistory

</summary>

ID string

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingUsageHistoryResponse%20%3E%20(schema)%20%3E%20(property)%20history%20%3E%20(items)%20%3E%20(property)%20id">Link to this property</a>

AggregatedValue float64

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingUsageHistoryResponse%20%3E%20(schema)%20%3E%20(property)%20history%20%3E%20(items)%20%3E%20(property)%20aggregated_value">Link to this property</a>

EndTime float64

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingUsageHistoryResponse%20%3E%20(schema)%20%3E%20(property)%20history%20%3E%20(items)%20%3E%20(property)%20end_time">Link to this property</a>

StartTime float64

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingUsageHistoryResponse%20%3E%20(schema)%20%3E%20(property)%20history%20%3E%20(items)%20%3E%20(property)%20start_time">Link to this property</a>

</details>

<a href="#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingUsageHistoryResponse%20%3E%20(schema)%20%3E%20(property)%20history">Link to this property</a>

</details>

[Link to this property](<#(resource)%20ai_gateway.billing%20%3E%20(model)%20BillingUsageHistoryResponse%20%3E%20(schema)>)

### Get usage history

Go

HTTPTypeScriptPythonGoTerraform

```
package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/ai_gateway"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  response, err := client.AIGateway.Billing.UsageHistory(context.TODO(), ai_gateway.BillingUsageHistoryParams{
    AccountID: cloudflare.F("account_id"),
    ValueGroupingWindow: cloudflare.F(ai_gateway.BillingUsageHistoryParamsValueGroupingWindowDay),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.History)
}
```

200 example

```
{
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "messages": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "result": {
    "history": [
      {
        "id": "id",
        "aggregated_value": 0,
        "end_time": 0,
        "start_time": 0
      }
    ]
  },
  "success": true,
  "result_info": {
    "has_more": true,
    "page": 0,
    "per_page": 0,
    "total_count": 0
  }
}
```

##### Returns Examples

200 example

```
{
  "errors": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "messages": [
    {
      "code": 0,
      "message": "message"
    }
  ],
  "result": {
    "history": [
      {
        "id": "id",
        "aggregated_value": 0,
        "end_time": 0,
        "start_time": 0
      }
    ]
  },
  "success": true,
  "result_info": {
    "has_more": true,
    "page": 0,
    "per_page": 0,
    "total_count": 0
  }
}
```