# List usage (/docs/api-reference/billing/list-billing-usage)

Billable usage over a range (the current billing month by default), per meter, dimension and bucket (`hour`, `day` or `month`, UTC), oldest first; with `group_by=environment`, per environment too. Only live environments are billed, so only they appear. Usage counts when it becomes billable (an email when the provider accepts it) and is kept for 400 days.

`GET https://api.coss.com/v1/billing/usage`

Authenticate with your API key as a bearer token (`Authorization: Bearer coss_test_…`). Responses are JSON with snake_case fields; errors are `{ error: { type, code, message, param?, issues?, request_id } }` (https://coss.com/docs/api-reference/errors.md).

## Query parameters

- `from` (string, date-time): Start (inclusive). Defaults to the start of the current billing month.
- `to` (string, date-time): End (exclusive). Defaults to now. At most 400 days after `from` (7 by hour).
- `granularity` ("hour" | "day" | "month"): Bucket size (UTC). Defaults to `day`.
- `group_by` ("environment" | "project" | "api_key" | "user"): Split each bucket per environment, project, API key or user (the member whose personal key it was).
- `meter` (string, one of "email.recipients", "email.dedicated_ip", "email.attachment_data", "email.received", "email.received_data", "email.inboxes", "sms.segments", "sms.received_segments", "sms.numbers", "sms.registrations", "sign.completed_requests", "risk.phone_checks", "risk.assessments", "risk.content_checks", "verify.verifications", "verify.sms", "forms.submissions", "forms.file_uploads", "scheduling.bookings", "scheduling.hosts", "hooks.messages"): Only this meter.

## Example request

TypeScript (the `coss` package):

```ts
import { Coss } from "coss";

const coss = new Coss({
  apiKey: process.env.COSS_API_KEY,
  baseUrl: "https://api.coss.com",
});

const { data, error } = await coss.billing.usage();
```

HTTP:

```sh
curl -X GET "https://api.coss.com/v1/billing/usage" \
  -H "Authorization: Bearer $COSS_API_KEY"
```

Python:

```python
from coss import Coss

client = Coss()  # api_key= or COSS_API_KEY

client.billing.usage()
```

Go:

```go
import (
	"context"

	coss "github.com/cosscom/coss-go"
	cossclient "github.com/cosscom/coss-go/client"
)

client := cossclient.NewClient() // option.WithAPIKey(…) or COSS_API_KEY

request := &coss.UsageBillingRequest{}
client.Billing.Usage(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

client = Coss::Client.new # api_key: or COSS_API_KEY

client.billing.usage
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\Billing\Requests\UsageBillingRequest;

$client = new Coss(); // apiKey: or COSS_API_KEY

$client->billing->usage(
    new UsageBillingRequest([]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.billing.requests.UsageBillingRequest;

Coss client = Coss.builder().build(); // .apiKey(…) or COSS_API_KEY

client.billing().usage(
    UsageBillingRequest
        .builder()
        .build()
);
```

.NET:

```csharp
using Coss;

var client = new CossClient(); // apiKey: or COSS_API_KEY

await client.Billing.UsageAsync(new UsageBillingRequest());
```

## Response 200

Usage, oldest first.

- `object` ("list", required)
- `data` (object[], required)
  - `object` ("usage", required)
  - `meter` (string, required, one of "email.recipients", "email.dedicated_ip", "email.attachment_data", "email.received", "email.received_data", "email.inboxes", "sms.segments", "sms.received_segments", "sms.numbers", "sms.registrations", "sign.completed_requests", "risk.phone_checks", "risk.assessments", "risk.content_checks", "verify.verifications", "verify.sms", "forms.submissions", "forms.file_uploads", "scheduling.bookings", "scheduling.hosts", "hooks.messages"): What is counted, e.g. `email.recipients`.
  - `dimension` (string | null, required): e.g. `country=US` for SMS; `null` for none.
  - `environment_id` (string | null, required): Set with `group_by=environment`; `null` there for organization-wide usage (SMS numbers and registration fees).
  - `project_id` (string | null, required): Set with `group_by=project` (`null`: organization-wide usage, or usage recorded before projects were).
  - `api_key_id` (string | null, required): Set with `group_by=api_key` (`null`: the dashboard, or usage recorded before keys were).
  - `user_id` (string | null, required): Set with `group_by=user`: the member whose personal API key caused it (`null`: organization keys and the dashboard).
  - `start` (string, required, date-time): When this bucket starts (inclusive).
  - `end` (string, required, date-time): When this bucket ends (exclusive).
  - `quantity` (integer, required, at least 0): Units used in this bucket.
- `has_more` (false, required)

Example:

```json
{
  "object": "list",
  "data": [
    {
      "object": "usage",
      "meter": "email.recipients",
      "dimension": null,
      "environment_id": null,
      "project_id": null,
      "api_key_id": null,
      "user_id": null,
      "start": "2026-10-12T00:00:00.000Z",
      "end": "2026-10-13T00:00:00.000Z",
      "quantity": 4200
    }
  ],
  "has_more": false
}
```

## Errors

- `400`: The `Coss-Version` header names an unknown API version (`invalid_api_version`).
- `401`: The API key is missing, invalid, revoked or expired (`authentication_error`).
- `403`: The API key lacks the permission this endpoint needs (`permission_error`), or its organization is suspended (`organization_suspended`).
- `422`: A query parameter failed validation (`validation_error`), or the range is empty or too long (`invalid_range`: at most 400 days, 7 by hour).
- `429`: Too many requests with this API key (`rate_limited`), or too many requests with invalid keys from this address (`too_many_failed_authentications`). Retry after `Retry-After` seconds. Successful responses carry `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` (seconds until the limit is fully restored).
- `500`: Unexpected server error (`api_error` / `internal_error`).
- `503`: The API key could not be verified right now; retry (`service_unavailable`).