# creditUsage

```graphql
query CreditUsage {
  creditUsage {
    scope {
      kind
      accountId
      projectId
    }
    groupBy
    summary {
      creditsUsed
      requests
      inputTokens
      outputTokens
      cacheCreationInputTokens
      cacheReadInputTokens
    }
    timeframe {
      from
      to
      granularity
      timezone
      bucketCount
    }
    series {
      bucketStart
      creditsUsed
      requests
      inputTokens
      outputTokens
      cacheCreationInputTokens
      cacheReadInputTokens
    }
    projects {
      projectId
      projectName
      projectSlug
      creditsUsed
      requests
      inputTokens
      outputTokens
      cacheCreationInputTokens
      cacheReadInputTokens
    }
    models {
      model
      canonicalModelId
      modelProvider
      inferenceProvider
      creditsUsed
      requests
      inputTokens
      outputTokens
      cacheCreationInputTokens
      cacheReadInputTokens
      providerCostUsd
      veryfrontChargeUsd
      costAttribution
    }
    serving {
      host
      tier
      credits
      usd
      requests
      inputTokens
      outputTokens
      cacheReadTokens
      cacheCreationTokens
    }
  }
}
```

Break the credit spend of an account down by day, project and model, optionally for one project; returns the series with token counts per model. Requires account.billing.read.

## Arguments

| Name                     | Type             | Required | Description                                                            |
| ------------------------ | ---------------- | -------- | ---------------------------------------------------------------------- |
| `input`                  | CreditUsageInput |          |                                                                        |
| `input.from`             | String           |          | Inclusive timestamp; supply to and omit preset.                        |
| `input.to`               | String           |          | Exclusive timestamp with an explicit offset.                           |
| `input.granularity`      | String           |          | hour, day, week or month; defaults to day.                             |
| `input.groupBy`          | \[String!]       |          | project, model, api\_key or member.                                    |
| `input.compare`          | String           |          | previous\_period adds the preceding timeframe and summary.             |
| `input.preset`           | String           |          | 7d, 30d or 90d. Defaults to 30d.                                       |
| `input.timezone`         | String           |          | IANA time zone for daily bucket boundaries. Defaults to UTC.           |
| `input.projectReference` | String           |          | Project ID or slug that narrows the read to one project of the account |

## Responses

| Status | Description                           |
| ------ | ------------------------------------- |
| 200    | The CreditUsage! in data.creditUsage. |

## Call it

```bash
curl -X POST "https://api.veryfront.com/graphql" \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "query": "query CreditUsage {\n  creditUsage {\n    scope {\n      kind\n      accountId\n      projectId\n    }\n    groupBy\n    summary {\n      creditsUsed\n      requests\n      inputTokens\n      outputTokens\n      cacheCreationInputTokens\n      cacheReadInputTokens\n    }\n    timeframe {\n      from\n      to\n      granularity\n      timezone\n      bucketCount\n    }\n    series {\n      bucketStart\n      creditsUsed\n      requests\n      inputTokens\n      outputTokens\n      cacheCreationInputTokens\n      cacheReadInputTokens\n    }\n    projects {\n      projectId\n      projectName\n      projectSlug\n      creditsUsed\n      requests\n      inputTokens\n      outputTokens\n      cacheCreationInputTokens\n      cacheReadInputTokens\n    }\n    models {\n      model\n      canonicalModelId\n      modelProvider\n      inferenceProvider\n      creditsUsed\n      requests\n      inputTokens\n      outputTokens\n      cacheCreationInputTokens\n      cacheReadInputTokens\n      providerCostUsd\n      veryfrontChargeUsd\n      costAttribution\n    }\n    serving {\n      host\n      tier\n      credits\n      usd\n      requests\n      inputTokens\n      outputTokens\n      cacheReadTokens\n      cacheCreationTokens\n    }\n  }\n}"
}'
```

## Example response

```json
{
  "data": {
    "creditUsage": {
      "scope": {
        "kind": "string",
        "accountId": "string",
        "projectId": "string"
      },
      "groupBy": [
        "string"
      ],
      "summary": {
        "creditsUsed": 0,
        "requests": 0,
        "inputTokens": 0,
        "outputTokens": 0,
        "cacheCreationInputTokens": 0,
        "cacheReadInputTokens": 0
      },
      "timeframe": {
        "from": "string",
        "to": "string",
        "granularity": "string",
        "timezone": "string",
        "bucketCount": 0
      },
      "series": [
        {
          "bucketStart": "string",
          "creditsUsed": 0,
          "requests": 0,
          "inputTokens": 0,
          "outputTokens": 0,
          "cacheCreationInputTokens": 0,
          "cacheReadInputTokens": 0
        }
      ],
      "projects": [
        {
          "projectId": "string",
          "projectName": "string",
          "projectSlug": "string",
          "creditsUsed": 0,
          "requests": 0,
          "inputTokens": 0,
          "outputTokens": 0,
          "cacheCreationInputTokens": 0,
          "cacheReadInputTokens": 0
        }
      ],
      "models": [
        {
          "model": "string",
          "canonicalModelId": "string",
          "modelProvider": "string",
          "inferenceProvider": "string",
          "creditsUsed": 0,
          "requests": 0,
          "inputTokens": 0,
          "outputTokens": 0,
          "cacheCreationInputTokens": 0,
          "cacheReadInputTokens": 0,
          "providerCostUsd": 0,
          "veryfrontChargeUsd": 0,
          "costAttribution": "string"
        }
      ],
      "serving": [
        {
          "host": "string",
          "tier": "string",
          "credits": 0,
          "usd": 0,
          "requests": 0,
          "inputTokens": 0,
          "outputTokens": 0,
          "cacheReadTokens": 0,
          "cacheCreationTokens": 0
        }
      ]
    }
  }
}
```
