# End users

If your product serves many customers through one Exayard key, tell us which of your customers each call is for. Send
your own id for them in the `Exayard-End-User` header:

```bash
curl https://api.exayard.com/v1/projects \
  -H "Authorization: Bearer $EXAYARD_API_KEY" \
  -H "Exayard-End-User: customer-4821"
```

## The value

- 1 to 128 printable characters. Spaces are allowed.
- It is yours and opaque to us: an id from your own database works best.
- **Never send an email address** or anything else that identifies a person.

A value that breaks these rules is refused with 400 [`invalid_end_user`](https://developers.exayard.com/concepts/errors.md#invalid_end_user). Leave
the header out when a call is not for any one customer.

## With the SDK

Set it for the whole client, or for one call:

```typescript
import { Exayard } from '@exayard/sdk'

const exa = new Exayard({ endUser: 'customer-4821' })
await exa.projects.list({})

// This call is for another customer.
await exa.projects.create({ name: 'Harbor Glass fit-out' }, { endUser: 'customer-77' })
```

The SDK checks the value before sending and throws a `TypeError` for a bad one.

## Where it shows

Each call is logged with its end user. On the Developer page, **Logs** can be filtered by app, key and end user.

AI usage is booked with its end user too. On the **Usage** page in Exayard, **Spending by app** shows each app's top
end users.

The header is read on the REST API only. The MCP server ignores it.

## Read usage by end user

`GET /v1/usage` reads the company's AI usage, in credits and in money. Group it by end user:

```bash
curl "https://api.exayard.com/v1/usage?groupBy=end_user" \
  -H "Authorization: Bearer $EXAYARD_API_KEY"
```

Or read one end user's usage, split by operation:

```bash
curl "https://api.exayard.com/v1/usage?groupBy=operation&endUser=customer-4821" \
  -H "Authorization: Bearer $EXAYARD_API_KEY"
```

With the SDK:

```typescript
const usage = await exa.api.getUsage({ groupBy: 'operation', endUser: 'customer-4821' })
```

The window is this billing month unless you pass `dateFrom` and `dateTo` (epoch milliseconds). Usage with no end user
comes back in a group whose `key` is `null`. It needs the `read:usage` scope. A key's app reads only its own usage: the answer is narrowed to that app, you can
still group and filter by key, end user and operation, and naming another app's `appId` gets 403 `forbidden`. An
admin's sign-in, or a key set to work in **This company** that holds `admin:org` or `*`, reads every app's usage. See [Pricing](https://developers.exayard.com/pricing.md#usage-by-app-key-or-end-user) for every parameter and the answer.
