# List spend

URL: https://docs.hanzo.ai/docs/openapi/agent/get-agent-by-ref-spend

> Answers what one of your org's agents has spent, in integer micro-USD.

`GET /v1/agent/{ref}/spend`

> [Agent →](https://docs.hanzo.ai/docs/openapi/agent) · [All API references →](https://docs.hanzo.ai/docs/openapi) · [Get started →](https://docs.hanzo.ai/docs/guides)

|               |                                             |
| ------------- | ------------------------------------------- |
| **Address**   | `https://api.hanzo.ai/v1/agent/{ref}/spend` |
| **Method**    | `GET`                                       |
| **Operation** | `get_agent_by_ref_spend`                    |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`      |

Answers what one of your org's agents has spent, in integer micro-USD.

It answers the agent's budget — `cap_micro_usd` per `period`,
`max_task_micro_usd` per run — with what the current period has consumed,
what remains, and `by_component`: the spend attributed to `model` (every
completion the agent bought), `computer` (the runtime it was resident for)
and `tool`. A component with no spend is absent, not zero. Every amount is an
integer number of micro-USD (1,000,000 = $1); 11902000 is $11.902. Pass
`by=component` to ask for the breakdown by name — it is the one grouping, and
the default.

## Request

2 fields.

| Field | In    | Type   | Required | Description                                                   |
| ----- | ----- | ------ | -------- | ------------------------------------------------------------- |
| `ref` | path  | string | yes      | Ref is the agent's public id or its org-unique name.          |
| `by`  | query | string | —        | By groups the answer: "component" is the only grouping today. |

## Response

| Status    | Body            | Meaning |
| --------- | --------------- | ------- |
| `200`     | agent.spendView | ok      |
| `default` | problem-details | refused |

`200` body — 9 fields.

| Field                 | In   | Type            | Always | Description                                                                                                          |
| --------------------- | ---- | --------------- | ------ | -------------------------------------------------------------------------------------------------------------------- |
| `by_component`        | body | object          | —      | ByComponent holds only the components with spend.                                                                    |
| `by_component.*`      | body | integer (int64) | —      |                                                                                                                      |
| `cap_micro_usd`       | body | integer (int64) | —      | CapMicroUSD is the total this agent may spend within one Period, as an integer number of micro-USD (1,000,000 = $1). |
| `consumed_micro_usd`  | body | integer (int64) | —      | ConsumedMicroUSD is what has been spent in the current period, in micro-USD.                                         |
| `max_task_micro_usd`  | body | integer (int64) | —      | MaxTaskMicroUSD is the ceiling for a single run, in micro-USD.                                                       |
| `period`              | body | string          | —      | Period is the window the cap resets on: day, week or month.                                                          |
| `period_started_at`   | body | integer (int64) | —      | PeriodStartedAt is when the current period began, as a Unix second.                                                  |
| `ref`                 | body | string          | —      | Ref names the agent this spend belongs to.                                                                           |
| `remaining_micro_usd` | body | integer (int64) | —      | RemainingMicroUSD is what the cap still allows this period, in micro-USD.                                            |

Failure carries the platform error shape — see [Errors](https://docs.hanzo.ai/docs/errors).

## Examples

**CLI**

```bash
hanzo agent spend <ref>
```

**SDK**

**.ts**

```ts
import { Configuration, AgentApi } from 'hanzoai';

const api = new AgentApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.getAgentByRefSpend({ ref: 'ref' });
```

**.py**

```python
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import AgentApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = AgentApi(client).get_agent_by_ref_spend(ref='ref')
```

**.go**

```go
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.AgentAPI.GetAgentByRefSpend(context.Background()).Execute()
if err != nil {
	return err
}
```

**.rs**

```rust
use hanzo_client::apis::{configuration::Configuration, agent_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = agent_api::get_agent_by_ref_spend(&cfg, Default::default()).await?;
```

**.java**

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.AgentApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new AgentApi(client).getAgentByRefSpend();
```

**HTTP**

```bash
curl https://api.hanzo.ai/v1/agent/<ref>/spend \
  -H "Authorization: Bearer $HANZO_API_KEY"
```

**MCP**

MCP reaches **agent** through the `agent` tool, which names its 38 operations with its own verbs — this one among them, under a name only MCP declares. `describe` explains any of them:

```bash
curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "describe",
         "arguments": {
           "op": "list_agents"
         }
       }
     }'
```

---

[Agent API](https://docs.hanzo.ai/docs/openapi/agent) · [All Hanzo APIs](https://docs.hanzo.ai/docs/openapi) · [Interactive reference](https://docs.hanzo.ai/docs/openapi/reference)
