Create 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

Addresshttps://api.hanzo.ai/v1/code/index
MethodPOST
Operationpost_code_index
AuthAuthorization: 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).

FieldInTypeRequiredDescription
filesbodycode.fileInput[]—Files is the full set of files to index.
files[].contentbodystring—Content is the file's full text.
files[].pathbodystring—Path is the file's repo-relative path, e.g. "internal/store/db.go".
prunebodyboolean—Prune deletes indexed files that are NOT in this request — which makes the call a full sync of the repo rather than an upsert.
repobodystring—Repo is the repository label to index under.

Response

StatusBodyMeaning
200code.indexResultok
defaultproblem-detailsrefused

200 body — 9 fields.

FieldInTypeAlwaysDescription
chunksbodyinteger (int64)—Chunks is how many AST-boundary chunks the repo holds after this pass.
filesbodyinteger (int64)—Files is how many files the repo holds after this pass.
indexedbodyinteger (int64)—Indexed is how many files were parsed and written on this pass.
prunedbodyinteger (int64)—Pruned is how many stored files were deleted because prune was set and they were absent from the request.
repobodystring—Repo is the repository that was indexed.
semanticbodyboolean—Semantic reports whether the semantic tier was available for this pass.
skippedbodyinteger (int64)—Skipped is how many files were unchanged by content hash and left alone.
symbolsbodyinteger (int64)—Symbols is how many symbol definitions the repo holds after this pass.
vectorsbodyinteger (int64)—Vectors is how many of those chunks carry an embedding.

Failure carries the platform error shape — see Errors.

Examples

hanzo code index
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 });
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)
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
}
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?;
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();
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 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:

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 · All Hanzo APIs · Interactive reference

Was this page useful?