# Create communities

URL: https://docs.hanzo.ai/docs/openapi/graph/graphcommunities

> Partitions the edge graph into sets of entities more densely connected to each other than to the rest.

`POST /v1/graph/communities`

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

|               |                                             |
| ------------- | ------------------------------------------- |
| **Address**   | `https://api.hanzo.ai/v1/graph/communities` |
| **Method**    | `POST`                                      |
| **Operation** | `graphCommunities`                          |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`      |

Partitions the edge graph into sets of entities more densely
connected to each other than to the rest.

The graph is the one a walk reads, direction dropped, and the partition is
deterministic: the same graph at the same point numbers the same communities.

Time: as\_of and as\_known place the graph that is partitioned; either absent is
now.

## Request

4 fields, body `application/json` (required).

| Field      | In   | Type            | Required | Description                                                                                                                                      |
| ---------- | ---- | --------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `as_known` | body | string          | —        | AsKnown is how much this plane had heard, RFC 3339: the answer as it would have been given then, which is what makes a past answer reproducible. |
| `as_of`    | body | string          | —        | AsOf partitions the graph as it stood at an instant of the world, RFC 3339: the edges that held then.                                            |
| `level`    | body | integer (int64) | —        | Level is how fine a partition to answer with.                                                                                                    |
| `relation` | body | string          | —        | Relation narrows the graph to one edge relation, by its key.                                                                                     |

## Response

| Status    | Body                      | Meaning |
| --------- | ------------------------- | ------- |
| `200`     | graph.graphCommunitiesOut | ok      |
| `default` | problem-details           | refused |

`200` body — 14 fields.

| Field                   | In   | Type                    | Always | Description                                                                                                                                        |
| ----------------------- | ---- | ----------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `as_known`              | body | string                  | —      | AsKnown is the knowledge instant it was taken at, RFC 3339, the same way.                                                                          |
| `as_of`                 | body | string                  | —      | AsOf is the instant the graph was read at, RFC 3339: the one asked for, or the server's clock when none was.                                       |
| `bound`                 | body | integer (int64)         | —      | Bound is the most members listed in one answer.                                                                                                    |
| `ceiling`               | body | integer (int64)         | —      | Ceiling is the most edge assertions one partition reads — every row, so an edge three sources asserted counts three times.                         |
| `communities`           | body | graph.graphCommunity\[] | —      | Communities are the communities, largest first.                                                                                                    |
| `communities[].id`      | body | integer (int64)         | —      | ID numbers the community by size, largest first, then by its lowest key.                                                                           |
| `communities[].members` | body | string\[]               | —      | Members are the entities in it, in key order.                                                                                                      |
| `communities[].size`    | body | integer (int64)         | —      | Size is how many entities belong to it, whether or not all are listed.                                                                             |
| `edges`                 | body | integer (int64)         | —      | Edges is how many distinct undirected edges were partitioned.                                                                                      |
| `entities`              | body | integer (int64)         | —      | Entities is how many entities the edge graph holds.                                                                                                |
| `level`                 | body | integer (int64)         | —      | Level is the level answered.                                                                                                                       |
| `levels`                | body | integer (int64)         | —      | Levels is how many levels detection found.                                                                                                         |
| `modularity`            | body | number (double)         | —      | Modularity is Newman's Q of this level's partition, from -0.5 to 1: the share of edge weight inside communities, less what chance would put there. |
| `truncated`             | body | boolean                 | —      | Truncated says the member lists stop at Bound entities in all, filled in community order.                                                          |

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

## Examples

**CLI**

```bash
hanzo graph communities
```

**SDK**

**.ts**

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

const api = new GraphApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.graphCommunities({ as_known: "<as_known>", as_of: "<as_of>" });
```

**.py**

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

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = GraphApi(client).graph_communities(as_known="<as_known>", as_of="<as_of>")
```

**.go**

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

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

**.rs**

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

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

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

**.java**

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

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

var result = new GraphApi(client).graphCommunities();
```

**HTTP**

```bash
curl -X POST https://api.hanzo.ai/v1/graph/communities \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "as_known": "<as_known>",
       "as_of": "<as_of>"
     }'
```

**MCP**

Tool `graph`, op `graphCommunities` — 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": "graph",
         "arguments": {
           "op": "graphCommunities",
           "input": {
             "as_known": "<as_known>",
             "as_of": "<as_of>"
           }
         }
       }
     }'
```

---

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