# Get function

URL: https://docs.hanzo.ai/docs/openapi/function/get-function-by-name

> One function with everything a detail page needs in one round-trip: its definition, its 7-day rollup, its trigger, its twenty most recent invocations and the NAMES of the secrets it mounts.

`GET /v1/function/{name}`

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

|               |                                           |
| ------------- | ----------------------------------------- |
| **Address**   | `https://api.hanzo.ai/v1/function/{name}` |
| **Method**    | `GET`                                     |
| **Operation** | `get_function_by_name`                    |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`    |

One function with everything a detail page needs in one round-trip: its
definition, its 7-day rollup, its trigger, its twenty most recent invocations
and the NAMES of the secrets it mounts.

Secret values are never read or returned. A name the caller's org does not hold
is 404, which is also what another tenant's function looks like from here.

## Request

1 field.

| Field  | In   | Type   | Required | Description                         |
| ------ | ---- | ------ | -------- | ----------------------------------- |
| `name` | path | string | yes      | Name is the function the URL names. |

## Response

| Status    | Body                    | Meaning |
| --------- | ----------------------- | ------- |
| `200`     | function.functionDetail | ok      |
| `default` | problem-details         | refused |

`200` body — 31 fields.

| Field                            | In   | Type                       | Always | Description                                                                                                                                          |
| -------------------------------- | ---- | -------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `avgDurationMs`                  | body | number (double)            | —      |                                                                                                                                                      |
| `createdAt`                      | body | string                     | —      |                                                                                                                                                      |
| `endpoint`                       | body | string                     | —      |                                                                                                                                                      |
| `envCount`                       | body | integer (int64)            | —      |                                                                                                                                                      |
| `environment`                    | body | string                     | —      |                                                                                                                                                      |
| `errors7d`                       | body | integer (int64)            | —      |                                                                                                                                                      |
| `image`                          | body | string                     | —      |                                                                                                                                                      |
| `invocations7d`                  | body | integer (int64)            | —      |                                                                                                                                                      |
| `lastDeployedAt`                 | body | string                     | —      |                                                                                                                                                      |
| `memoryLimit`                    | body | string                     | —      |                                                                                                                                                      |
| `name`                           | body | string                     | —      |                                                                                                                                                      |
| `namespace`                      | body | string                     | —      |                                                                                                                                                      |
| `recentInvocations`              | body | function.invocationView\[] | —      | RecentInvocations is its twenty most recent runs, newest first.                                                                                      |
| `recentInvocations[].durationMs` | body | integer (int64)            | —      | how long it took                                                                                                                                     |
| `recentInvocations[].id`         | body | string                     | —      | the invocation's handle                                                                                                                              |
| `recentInvocations[].method`     | body | string                     | —      | the HTTP method that triggered it                                                                                                                    |
| `recentInvocations[].status`     | body | string                     | —      | how the run ended: ok, error or timeout                                                                                                              |
| `recentInvocations[].statusCode` | body | integer (int64)            | —      | Code is the status the function's OWN code answered with, which is not the status of the reply — a program can answer 500 through a healthy sandbox. |
| `recentInvocations[].time`       | body | string                     | —      | when it ran, RFC3339                                                                                                                                 |
| `secrets`                        | body | string\[]                  | —      | Secrets are the NAMES it mounts.                                                                                                                     |
| `status`                         | body | string                     | —      |                                                                                                                                                      |
| `successRate`                    | body | number (double)            | —      |                                                                                                                                                      |
| `target`                         | body | string                     | —      |                                                                                                                                                      |
| `timeoutSec`                     | body | integer (int64)            | —      |                                                                                                                                                      |
| `triggers`                       | body | function.triggerView\[]    | —      | Triggers is how this function is reached.                                                                                                            |
| `triggers[].enabled`             | body | boolean                    | —      | whether it currently fires                                                                                                                           |
| `triggers[].functionName`        | body | string                     | —      | the function it calls                                                                                                                                |
| `triggers[].id`                  | body | string                     | —      | the trigger's handle                                                                                                                                 |
| `triggers[].name`                | body | string                     | —      | a human label for it                                                                                                                                 |
| `triggers[].target`              | body | string                     | —      | the path it calls                                                                                                                                    |
| `triggers[].type`                | body | string                     | —      | what kind of trigger it is; HTTP is the only one today                                                                                               |

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

## Examples

**CLI**

```bash
hanzo function get <name>
```

**SDK**

**.ts**

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

const api = new FunctionApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.getFunctionByName({ name: 'name' });
```

**.py**

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

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = FunctionApi(client).get_function_by_name(name='name')
```

**.go**

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

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

**.rs**

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

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

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

**.java**

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

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

var result = new FunctionApi(client).getFunctionByName();
```

**HTTP**

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

**MCP**

Tool `function`, op `get_function_by_name` — 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": "function",
         "arguments": {
           "op": "get_function_by_name",
           "input": {
             "name": "<name>"
           }
         }
       }
     }'
```

---

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