Hanzo
OpenapiCode

Packs the most relevant code for a query into a token budget — THE primitive…

Packs the most relevant code for a query into a token budget — THE primitive for a coding agent that has to decide what to put in a prompt.

POST /v1/code/context

Addresshttps://api.hanzo.ai/v1/code/context
MethodPOST
Operationpost_code_context
AuthAuthorization: Bearer $HANZO_API_KEY

Packs the most relevant code for a query into a token budget — THE primitive for a coding agent that has to decide what to put in a prompt. It retrieves seed spans, expands each with the definitions it calls and its key callers, then greedily fills the budget, so the answer is a coherent slice of the codebase rather than a list of disconnected matches. The top match is always included, truncated if it alone overflows, so a matched query never comes back empty. A retrieval outage answers 200 with an empty bundle rather than a 5xx.

Request

3 fields, body application/json (required).

FieldInTypeRequiredDescription
budgetTokensbodyintegerBudgetTokens caps the bundle's size.
querybodystringQuery is what to retrieve context for.
repobodystringRepo narrows retrieval to one repository.

Response

StatusBodyMeaning
200ContextBundleok

200 body — 15 fields.

FieldInTypeAlwaysDescription
budgetTokensbodyintegerBudgetTokens is the ceiling the caller asked for.
querybodystringQuery is the ask this bundle was packed for, echoed back so a cached or forwarded bundle still says what it answers.
repobodystringRepo narrows the retrieval to one repository.
spansbodySpan[]Spans are the packed chunks, most relevant first, each expanded with the definitions it calls and its notable callers.
spans[].endLinebodyintegerEndLine is the last line of the span, inclusive.
spans[].filebodystringFile is the path inside the repo, relative to its root and never absolute.
spans[].kindbodystringKind is what the indexer decided this chunk IS — "func", "method", "type", "struct", "interface", "var", "const", or "block" for a run of code that declares…
spans[].linebodyintegerLine is where the span starts, 1-based, as an editor counts.
spans[].repobodystringRepo is the indexed repository the span was found in, as it was indexed ("owner/name").
spans[].rolebodystringcontext: match | definition | caller
spans[].scorebodynumberScore ranks this span against the OTHERS IN THE SAME RESPONSE and means nothing across responses or between tiers: the hybrid tier's number is a…
spans[].snippetbodystringSnippet is the code itself: a bounded excerpt on /search, the whole chunk on /context — which is why the same type serves both and why a /context span is the…
spans[].symbolbodystringSymbol is the declared name, when the span declares one.
spans[].tierbodystringTier is which retrieval produced the span: "hybrid" (the default — all three fused), "text" (trigram/FTS), "regex", "semantic" (vector), or "symbol".
usedTokensbodyintegerUsedTokens is what the returned spans actually cost, by the same estimate the packer used (roughly one token per four characters — an estimate, not a…

Failure carries the platform error shape — see Errors.

Examples

hanzo code context

Code API · All Hanzo APIs · Interactive reference

How is this guide?

On this page