# Create index

URL: https://docs.hanzo.ai/docs/openapi/code/post-code-index

> (re)indexes a repository for the caller's org, incrementally: files whose content hash is unchanged are skipped, so re-sending a whole tree is cheap.

`POST /v1/code/index`

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

|               |                                        |
| ------------- | -------------------------------------- |
| **Address**   | `https://api.hanzo.ai/v1/code/index`   |
| **Method**    | `POST`                                 |
| **Operation** | `post_code_index`                      |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY` |

(re)indexes a repository for the caller's org, incrementally: files whose
content hash is unchanged are skipped, so re-sending a whole tree is cheap.
Each file is parsed for symbols, split at AST boundaries and — when the
semantic tier is available — embedded, which is what makes it searchable across
all three retrieval tiers. Pass `prune` to also DELETE indexed files absent
from the request, which turns the call into a full sync; without it the call is
an upsert. The index is written to the caller org's own physically separate
database.

## Request

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

| Field             | In   | Type              | Required | Description                                                                                                                    |
| ----------------- | ---- | ----------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `files`           | body | code.fileInput\[] | —        | Files is the full set of files to index.                                                                                       |
| `files[].content` | body | string            | —        | Content is the file's full text.                                                                                               |
| `files[].path`    | body | string            | —        | Path is the file's repo-relative path, e.g. "internal/store/db.go".                                                            |
| `prune`           | body | boolean           | —        | Prune deletes indexed files that are NOT in this request — which makes the call a full sync of the repo rather than an upsert. |
| `repo`            | body | string            | —        | Repo is the repository label to index under.                                                                                   |

## Response

| Status    | Body             | Meaning |
| --------- | ---------------- | ------- |
| `200`     | code.indexResult | ok      |
| `default` | problem-details  | refused |

`200` body — 9 fields.

| Field      | In   | Type            | Always | Description                                                                                               |
| ---------- | ---- | --------------- | ------ | --------------------------------------------------------------------------------------------------------- |
| `chunks`   | body | integer (int64) | —      | Chunks is how many AST-boundary chunks the repo holds after this pass.                                    |
| `files`    | body | integer (int64) | —      | Files is how many files the repo holds after this pass.                                                   |
| `indexed`  | body | integer (int64) | —      | Indexed is how many files were parsed and written on this pass.                                           |
| `pruned`   | body | integer (int64) | —      | Pruned is how many stored files were deleted because prune was set and they were absent from the request. |
| `repo`     | body | string          | —      | Repo is the repository that was indexed.                                                                  |
| `semantic` | body | boolean         | —      | Semantic reports whether the semantic tier was available for this pass.                                   |
| `skipped`  | body | integer (int64) | —      | Skipped is how many files were unchanged by content hash and left alone.                                  |
| `symbols`  | body | integer (int64) | —      | Symbols is how many symbol definitions the repo holds after this pass.                                    |
| `vectors`  | body | integer (int64) | —      | Vectors is how many of those chunks carry an embedding.                                                   |

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

## Examples

**CLI**

```bash
hanzo code index
```

**SDK**

**.ts**

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

const api = new CodeApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.postCodeIndex({ files: [{"content":"<content>","path":"<path>"}], prune: false });
```

**.py**

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

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = CodeApi(client).post_code_index(files=[{"content":"<content>","path":"<path>"}], prune=False)
```

**.go**

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

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

**.rs**

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

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

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

**.java**

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

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

var result = new CodeApi(client).postCodeIndex();
```

**HTTP**

```bash
curl -X POST https://api.hanzo.ai/v1/code/index \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "files": [
         {
           "content": "<content>",
           "path": "<path>"
         }
       ],
       "prune": false
     }'
```

**MCP**

MCP reaches **code** through the `code` tool, which names its 7 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": "get_code_ask"
         }
       }
     }'
```

---

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