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

# Usage by key

> Track spend per user, customer or app when you resell or embed Wally Cloud

If you build a platform on Wally Cloud, give each of your users, customers or apps its own Cloud
key. Every request settles against the key that made it, so the usage export can be split by key
and you can bill or cap each one yourself.

## 1. One key per user

Create keys on the console's Cloud keys page. Name each key after the user or customer it belongs
to (up to 120 characters), since the name is what you will see in the console later. The plaintext
shows once, so store it in your secret manager next to your own user id.

Keep the keys on your servers. Any live key on the account can read the account's usage export
below, so a key handed to an end user would let them see every key's token counts and spend. It
never exposes prompts, completions or key material.

The OpenAI `user` field is accepted but not recorded, so it cannot be used to split usage. Use a
key per user instead.

## 2. Find each key's id

Export rows carry `api_key_id`, a UUID, not the key name. To learn a key's id, send one request
with it and look that request up by the `x-request-id` the response carried:

```bash theme={"theme":"css-variables"}
curl -s -D - https://inference.runanywhere.ai/v1/chat/completions \
  -H "Authorization: Bearer $USER_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"model":"<model-id>","max_tokens":5,"messages":[{"role":"user","content":"hi"}]}' \
  | grep -i x-request-id
```

A request takes about a minute to appear in the export. Then:

```bash theme={"theme":"css-variables"}
curl -s "https://inference.runanywhere.ai/v1/cli/usage/requests?since=2026-11-09T00:00:00Z&until=2026-11-10T00:00:00Z&response_request_id=<x-request-id>" \
  -H "Authorization: Bearer $RUNA_CLOUD_KEY" | jq -r '.requests[0].api_key_id'
```

Save that id with the key's owner. It does not change for the life of the key.

## 3. Export usage

```text theme={"theme":"css-variables"}
GET https://inference.runanywhere.ai/v1/cli/usage/requests
Authorization: Bearer sk-runa-…
```

It returns the account's settled requests, newest first, one page per call.

**since** `string` *required*

Start of the window, inclusive. An ISO 8601 time with a UTC offset, such as
`2026-11-01T00:00:00Z`.

**until** `string` *required*

End of the window, exclusive. At most 31 days after `since`. Export longer periods in parts.

**api\_key\_id** `string`

Only requests made with this key.

**model** `string`

Only this model id.

**status\_code** `integer`

Only this HTTP status.

**response\_request\_id** `string`

Only the rows for this `x-request-id`. It can match more than one row.

**limit** `integer` (default: 100)

Rows per page, 1 to 200.

**cursor** `string`

The previous page's `next_cursor`. Send it with the same window and filters; changing either
returns `400`.

The response:

```json theme={"theme":"css-variables"}
{
  "as_of": "2026-11-09T21:01:12.072455Z",
  "totals": {
    "requests": 1,
    "prompt_tokens": 31,
    "cached_tokens": 0,
    "noncached_prompt_tokens": 31,
    "completion_tokens": 5,
    "reasoning_tokens": 5,
    "cost_micros": 15
  },
  "requests": [
    {
      "request_id": "e30aaf1d-eed5-5f30-81cc-ff167371a9f5",
      "response_request_id": "b05f50b5-0554-4a26-8903-1a60b8e0fd5e",
      "api_key_id": "0446bb91-1a66-4521-83a2-a3a2da33b5c7",
      "model": "deepseek-v4.1-flash",
      "status_code": 200,
      "finish_reason": "length",
      "stream": false,
      "ts_start": "2026-11-09T20:58:44.736862Z",
      "prompt_tokens": 31,
      "cached_tokens": 0,
      "noncached_prompt_tokens": 31,
      "completion_tokens": 5,
      "reasoning_tokens": 5,
      "ttft_ms": 10059,
      "cost_micros": 15,
      "pricing_version": "2026-11-06.1"
    }
  ],
  "next_cursor": null
}
```

Rows also carry `provider`, `error_code`, `ts_end`, `recorded_at`, `max_tokens_requested`,
`max_tokens_granted` and `tpot_ms`, trimmed above. A few things to know when you reconcile:

* `cost_micros` is what was charged, in millionths of a dollar. `15` is \$0.000015.
* `totals` covers every page of the export, not just this one, and respects your filters. Query
  with `api_key_id` to get one key's total in a single call.
* `cached_tokens` is part of `prompt_tokens`, billed at the cached rate.
  `noncached_prompt_tokens` is the rest, billed at the input rate.
* Only settled requests appear. A request still running, or one refused before it reached a
  model, has no row.
* `as_of` is about a minute behind real time. A request newer than that shows up in the next
  export.

## Per-key totals for a month

```bash theme={"theme":"css-variables"}
#!/usr/bin/env bash
# Spend per key over one window (at most 31 days), every page.
set -euo pipefail
SINCE=${SINCE:-2026-10-01T00:00:00Z}
UNTIL=${UNTIL:-2026-11-01T00:00:00Z}
cursor=''
: > rows.jsonl
while :; do
  page=$(curl -sfG https://inference.runanywhere.ai/v1/cli/usage/requests \
    -H "Authorization: Bearer $RUNA_CLOUD_KEY" \
    --data-urlencode "since=$SINCE" --data-urlencode "until=$UNTIL" -d limit=200 \
    ${cursor:+--data-urlencode "cursor=$cursor"})
  jq -c '.requests[]' <<< "$page" >> rows.jsonl
  cursor=$(jq -r '.next_cursor // empty' <<< "$page")
  [ -z "$cursor" ] && break
done
jq -s 'group_by(.api_key_id) | map({
  api_key_id: .[0].api_key_id,
  requests: length,
  input_tokens: (map(.prompt_tokens) | add),
  output_tokens: (map(.completion_tokens) | add),
  usd: ((map(.cost_micros) | add) / 1000000)
})' rows.jsonl
```

The defaults cover October 2026, which is 31 days, the most one window allows. Set `SINCE` and
`UNTIL` for another period.

## From the CLI

`wally account usage --requests` reads the same export for the signed-in account. Add `--json` to
get `api_key_id` on every row:

```bash theme={"theme":"css-variables"}
wally account usage --requests --days 7 --follow --json
```

## Coming next

Showing key ids on the Cloud keys page, a `--key` filter in the CLI, and per-key spend limits are
not available yet. Email [support@runanywhere.ai](mailto:support@runanywhere.ai) if your platform
needs one of them.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.