# Get a user's usage

> One end user's sessions and AI credits in this billing period.

<Endpoint method="GET" path="/v1/users/{id}/usage" />

<CodeTabs>

```bash tab="cURL"
curl https://api.muzekit.com/v1/users/user_42/usage \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY"
```

```javascript tab="Node"
const res = await fetch("https://api.muzekit.com/v1/users/user_42/usage", {
  headers: { Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}` },
});
const usage = await res.json();
```

```python tab="Python"
import os
import requests

usage = requests.get(
    "https://api.muzekit.com/v1/users/user_42/usage",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
).json()
```

</CodeTabs>

`{id}` is the user's `usr_…` id or your own id for them, URL-encoded, as in [Get a user](/docs/api-reference/users-get).

The counts are for the editor's current billing period (`period`), in this key's environment:

- `sessions`: editor sessions the user opened, each counted once however often they reloaded it, plus the sessions their [AI app](/docs/mcp#let-your-users-connect-their-ai-app) worked in.
- `ai_credits_used`: AI credits their AI actions spent. `ai_credits_limit` is what one user may spend a period (50 by default); past it their AI actions are refused with `402 ai_user_limit_reached`.

Renders aren't counted per user. For the whole editor's use, read [Get the workspace](/docs/api-reference/workspace-get) (this period's pools) and [Get usage](/docs/api-reference/usage-get) (per day).

## Examples

### Warn a user before their AI credits run out

Check what is left before you show your own upgrade prompt, or turn AI features off in their next [session](/docs/api-reference/sessions-create)'s `features`.

<CodeTabs>

```bash tab="cURL"
curl -s https://api.muzekit.com/v1/users/user_42/usage \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  | jq '.ai_credits_limit - .ai_credits_used'
```

```javascript tab="Node"
const res = await fetch("https://api.muzekit.com/v1/users/user_42/usage", {
  headers: { Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}` },
});
const usage = await res.json();
const left = usage.ai_credits_limit - usage.ai_credits_used;
if (left < 10) {
  // Show your own notice, or open the next session with
  // features: { aiImages: false, agent: false }
}
```

```python tab="Python"
import os
import requests

usage = requests.get(
    "https://api.muzekit.com/v1/users/user_42/usage",
    headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
).json()
left = usage["ai_credits_limit"] - usage["ai_credits_used"]
```

</CodeTabs>

### Bill your heaviest users

Read each user's sessions at the end of the period, for example to charge per seat or per session in your own pricing. Use `period.end` to know when the counts start again.

<CodeTabs>

```bash tab="cURL"
for id in user_42 user_43; do
  curl -s "https://api.muzekit.com/v1/users/$id/usage" \
    -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
    | jq -r '[.external_id, .sessions] | @tsv'
done
```

```javascript tab="Node"
for (const id of ["user_42", "user_43"]) {
  const res = await fetch(`https://api.muzekit.com/v1/users/${id}/usage`, {
    headers: { Authorization: `Bearer ${process.env.MUZEKIT_SECRET_KEY}` },
  });
  const { external_id, sessions } = await res.json();
  console.log(external_id, sessions);
}
```

```python tab="Python"
import os
import requests

for user_id in ["user_42", "user_43"]:
    u = requests.get(
        f"https://api.muzekit.com/v1/users/{user_id}/usage",
        headers={"Authorization": f"Bearer {os.environ['MUZEKIT_SECRET_KEY']}"},
    ).json()
    print(u["external_id"], u["sessions"])
```

</CodeTabs>

## Response

```json
{
  "object": "user_usage",
  "user": "usr_8fK2mQ1xZpR",
  "external_id": "user_42",
  "environment": "live",
  "period": {
    "start": "2026-11-01T00:00:00.000Z",
    "end": "2026-12-01T00:00:00.000Z"
  },
  "sessions": 14,
  "ai_credits_used": 32,
  "ai_credits_limit": 50
}
```

`period.end` is `null` when the editor has no billing period yet; the counts then start on the first of the month (UTC).
