# Get agent

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

> Returns one agent with its system prompt and its 20 most recent runs.

`GET /v1/agent/{ref}`

> [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}`  |
| **Method**    | `GET`                                  |
| **Operation** | `get_agent_by_ref`                     |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY` |

Returns one agent with its system prompt and its 20 most recent runs.
The ref is the agent's public id or its org-unique name — a created agent is
immediately gettable by whatever create handed back.

## Request

1 field.

| Field | In   | Type   | Required | Description                                                                                                      |
| ----- | ---- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------- |
| `ref` | path | string | yes      | Ref is the agent's public id (the agent\_… handle create and list return) or its org-unique name, from the path. |

## Response

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

`200` body — 38 fields.

| Field                           | In   | Type                  | Always | Description                                                                                                                                                                                                      |
| ------------------------------- | ---- | --------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `avatar`                        | body | string                | —      |                                                                                                                                                                                                                  |
| `cap_micro_usd`                 | body | integer (int64)       | —      |                                                                                                                                                                                                                  |
| `computeRef`                    | body | string                | —      |                                                                                                                                                                                                                  |
| `consumed_micro_usd`            | body | integer (int64)       | —      |                                                                                                                                                                                                                  |
| `createdAt`                     | body | string                | —      |                                                                                                                                                                                                                  |
| `description`                   | body | string                | —      |                                                                                                                                                                                                                  |
| `emoji`                         | body | string                | —      |                                                                                                                                                                                                                  |
| `executionMode`                 | body | string                | —      |                                                                                                                                                                                                                  |
| `id`                            | body | string                | —      |                                                                                                                                                                                                                  |
| `instructions`                  | body | string                | —      | Instructions is the agent's system prompt, verbatim, up to 32 KiB.                                                                                                                                               |
| `lineage`                       | body | string\[]             | —      |                                                                                                                                                                                                                  |
| `max_task_micro_usd`            | body | integer (int64)       | —      |                                                                                                                                                                                                                  |
| `model`                         | body | string                | —      |                                                                                                                                                                                                                  |
| `name`                          | body | string                | —      |                                                                                                                                                                                                                  |
| `parent`                        | body | string                | —      |                                                                                                                                                                                                                  |
| `period`                        | body | string                | —      |                                                                                                                                                                                                                  |
| `recentRuns`                    | body | agent.agentRunView\[] | —      | RecentRuns is the agent's 20 most recent executions, newest first.                                                                                                                                               |
| `recentRuns[].actor`            | body | string                | —      | Actor is the "org/sub" identity the run was executed and billed AS.                                                                                                                                              |
| `recentRuns[].agent`            | body | string                | —      | What an operator needs to answer "what ran, for whom, and what did it do" — and, through traceId, to leave this record for the waterfall of the very same run rather than a search that hopefully lands near it. |
| `recentRuns[].completionTokens` | body | integer (int64)       | —      | CompletionTokens is the same measurement for what the model produced, on the same final completion.                                                                                                              |
| `recentRuns[].createdAt`        | body | string                | —      | CreatedAt is when the run finished, RFC 3339 in UTC to the second — the duration above already says how long it had been going.                                                                                  |
| `recentRuns[].durationMs`       | body | integer (int64)       | —      | DurationMs is wall-clock milliseconds around the completion, including a failover's retries.                                                                                                                     |
| `recentRuns[].error`            | body | string                | —      | Error is why an "ok"-less run failed, as the failing call reported it.                                                                                                                                           |
| `recentRuns[].id`               | body | string                | —      | ID is the run's handle, minted as "run\_" + 32 hex characters.                                                                                                                                                   |
| `recentRuns[].input`            | body | string                | —      | Input is the text the run was given, verbatim.                                                                                                                                                                   |
| `recentRuns[].micro_usd`        | body | integer (int64)       | —      | MicroUSD is what the run spent, integer micro-USD.                                                                                                                                                               |
| `recentRuns[].model`            | body | string                | —      | Model is the model that actually SERVED this run, which is not always the one the agent is defined on — a failover records what answered.                                                                        |
| `recentRuns[].output`           | body | string                | —      | Output is what the model produced.                                                                                                                                                                               |
| `recentRuns[].promptTokens`     | body | integer (int64)       | —      | PromptTokens is what the gateway reported for the run's FINAL completion, and only that one — a tool loop's earlier rounds are the metering ledger's account, joined by this run's id.                           |
| `recentRuns[].status`           | body | string                | —      | Status is the run's outcome, and there are exactly two: "ok" when the model answered, "error" when it did not.                                                                                                   |
| `recentRuns[].toolCalls`        | body | integer (int64)       | —      | ToolCalls is how many tool dispatches the run made — a count of ACTIONS, which is a different measurement from the token counts above and from the turns a build reports.                                        |
| `recentRuns[].traceId`          | body | string                | —      | TraceID is the trace this run IS, so the record and its spans are one thing to move between: it opens the waterfall for THIS run rather than a search that lands near it.                                        |
| `runs`                          | body | integer (int64)       | —      |                                                                                                                                                                                                                  |
| `schedule`                      | body | string                | —      |                                                                                                                                                                                                                  |
| `serviceAccountId`              | body | string                | —      |                                                                                                                                                                                                                  |
| `status`                        | body | string                | —      |                                                                                                                                                                                                                  |
| `tools`                         | body | string\[]             | —      |                                                                                                                                                                                                                  |
| `updatedAt`                     | body | string                | —      |                                                                                                                                                                                                                  |

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

## Examples

**CLI**

```bash
hanzo agent get <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.getAgentByRef({ 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(ref='ref')
```

**.go**

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

resp, _, err := client.AgentAPI.GetAgentByRef(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(&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).getAgentByRef();
```

**HTTP**

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

**MCP**

Tool `agent`, op `get_agent_by_ref` — POST the JSON-RPC envelope to `https://api.hanzo.ai/v1/mcp`.

```bash
curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "agent",
         "arguments": {
           "op": "get_agent_by_ref",
           "input": {
             "ref": "<ref>"
           }
         }
       }
     }'
```

---

[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)
