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

# Get account usage

> Read your GoldRush account usage programmatically — daily usage, aggregate credit consumption against your plan, and a per-API-key breakdown.

<CardGroup cols={2}>
  <Card title="Credential"> ServiceKey (account-scoped)</Card>
  <Card title="Processing"> Realtime</Card>
</CardGroup>

Returns the same three datasets the Platform **Usage** page renders — daily usage, aggregate credit consumption against your plan, and a per-API-key breakdown — as JSON, filterable by time range.

This endpoint is authenticated with a **ServiceKey**, an account-scoped credential distinct from your standard GoldRush API keys (`cqt_…`). See [Service Keys](/docs/service-keys) for how to create, use, and rotate one.

<Note>
  Platform endpoints on `api.covalenthq.com` require a **trailing slash** — call `/platform/usage/`, not `/platform/usage`.
</Note>

## Endpoint

```
GET https://api.covalenthq.com/platform/usage/
Authorization: Bearer <GOLDRUSH_SERVICE_KEY>
```

## Request

Filter with either a rolling `duration` or an explicit `from`/`to` window. Every section of the response is computed over that single window (`period`).

<ParamField query="duration" type="integer" default="1">
  Rolling window in months, counting back from today. One of `1`, `3`, `6`, or `12`. The default `1` is month-to-date. Ignored when `from`/`to` are supplied.
</ParamField>

<ParamField query="from" type="string">
  Start of an explicit window (`YYYY-MM-DD`). Use together with `to` instead of `duration`.
</ParamField>

<ParamField query="to" type="string">
  End of an explicit window (`YYYY-MM-DD`). Use together with `from` instead of `duration`.
</ParamField>

### Example

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://api.covalenthq.com/platform/usage/?duration=1" \
    -H "Authorization: Bearer $GOLDRUSH_SERVICE_KEY"
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch(
    "https://api.covalenthq.com/platform/usage/?duration=1",
    {
      headers: {
        Authorization: `Bearer ${process.env.GOLDRUSH_SERVICE_KEY}`,
      },
    },
  );

  const body = await response.json();
  ```

  ```python Python theme={null}
  import os, requests

  response = requests.get(
      "https://api.covalenthq.com/platform/usage/",
      params={"duration": 1},
      headers={"Authorization": f"Bearer {os.environ['GOLDRUSH_SERVICE_KEY']}"},
  )
  response.raise_for_status()

  body = response.json()
  ```
</CodeGroup>

The GoldRush CLI exposes the same data:

```bash theme={null}
goldrush usage --duration 1 --by-key
```

## Response

The response is a `{ "data": { … } }` envelope containing the window it was computed over (`period`) and the three datasets.

```json theme={null}
{
  "data": {
    "period": {
      "from": "2026-07-01",
      "to": "2026-07-26"
    },
    "aggregate": {
      "credits_consumed": 412000,
      "max_credits": 1000000,
      "premium_credits": 380000,
      "free_credits": 32000,
      "plan": "Advanced",
      "flex_credits": {
        "limit": 250000
      }
    },
    "by_day": [
      {
        "date": "2026-07-25",
        "premium_credits": 18400,
        "free_credits": 1200
      }
    ],
    "by_api_key": [
      {
        "apikey": "cqt_rQ…",
        "credits": 210000
      }
    ]
  }
}
```

### Field descriptions

<ResponseField name="period" type="object">
  The single time window every section is computed over.

  <Expandable title="period">
    <ResponseField name="from" type="string">Start of the window (`YYYY-MM-DD`).</ResponseField>
    <ResponseField name="to" type="string">End of the window (`YYYY-MM-DD`).</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="aggregate" type="object">
  Aggregate credit consumption for the window.

  <Expandable title="aggregate">
    <ResponseField name="credits_consumed" type="integer">Total credits used in the window.</ResponseField>
    <ResponseField name="max_credits" type="integer">Credit ceiling for your plan.</ResponseField>
    <ResponseField name="premium_credits" type="integer">Premium credits used in the window.</ResponseField>
    <ResponseField name="free_credits" type="integer">Free credits used in the window.</ResponseField>
    <ResponseField name="plan" type="string">Name of your current plan.</ResponseField>
    <ResponseField name="flex_credits" type="object">Flex (overage) credit allowance, including its `limit`.</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="by_day" type="object[]">
  Per-day usage over the window.

  <Expandable title="by_day[]">
    <ResponseField name="date" type="string">The day (`YYYY-MM-DD`).</ResponseField>
    <ResponseField name="premium_credits" type="integer">Premium credits used that day.</ResponseField>
    <ResponseField name="free_credits" type="integer">Free credits used that day.</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="by_api_key" type="object[]">
  Credits attributed to each API key over the window.

  <Expandable title="by_api_key[]">
    <ResponseField name="apikey" type="string">The API key the credits are attributed to.</ResponseField>
    <ResponseField name="credits" type="integer">Credits consumed by that key in the window.</ResponseField>
  </Expandable>
</ResponseField>

## Common uses

* **Budget guardrails in code** — watch `aggregate.credits_consumed` against `max_credits` (and `flex_credits.limit`) to alert or throttle before you hit the ceiling.
* **Per-key cost attribution** — use `by_api_key` to split spend across projects, environments, or downstream customers for chargeback and show-back.
* **Usage trends** — feed `by_day` (premium vs. free) into your own BI or observability stack to forecast month-end spend and catch runaway jobs.

## Common errors

| Status             | Cause                                                            | Fix                                                                                     |
| ------------------ | ---------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| `401 Unauthorized` | Header missing or malformed, or the ServiceKey has been revoked. | Confirm `Authorization: Bearer <key>` and that the key is still active on the Platform. |
| `403 Forbidden`    | A regular API key was supplied instead of a ServiceKey.          | Create a [ServiceKey](/docs/service-keys) and retry.                                         |
