Launch a scan
const url = 'https://zkao.io/api/v1/projects/example/scans';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"repositoryId":"example","creditBudget":1,"presetRef":"example","branch":"example","commitHash":"example","commitMessage":"example","baseCommit":"example","auditAreaKeys":["example"],"guidance":"example"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://zkao.io/api/v1/projects/example/scans \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "repositoryId": "example", "creditBudget": 1, "presetRef": "example", "branch": "example", "commitHash": "example", "commitMessage": "example", "baseCommit": "example", "auditAreaKeys": [ "example" ], "guidance": "example" }'Requires scope: scans:launch. Reserves creditBudget credits from the
project balance. The repo must be in the token’s allowlist (when set) and
ACTIVE. Discover valid presetRef values via /scan-presets. Each scan
type runs a fixed set of flows. Per-token spend limits are enforced, and
the project must have enough prepaid credits to cover the budget
(otherwise 402).
A repository added moments ago may still be analyzing, in which case
this returns 409 repository_initializing. Wait for its readiness to
be ready in GET /repositories and launch again.
A diff scan preset audits only the change from baseCommit to the
scanned commit, and requires baseCommit. Every other preset refuses
it. A malformed, unknown, or misplaced base is a 400 with code
diff_base_required, diff_base_not_allowed, or diff_base_invalid.
A diff scan also needs a change to audit (otherwise 422).
Authorizations
Section titled “Authorizations”Parameters
Section titled “ Parameters ”Path Parameters
Section titled “Path Parameters”Request Bodyrequired
Section titled “Request Bodyrequired”object
Max budget for the scan, in credits. Reserved at launch. Omit it to launch at the budget zkao recommends for this scan type and scope on this repository: sized from what past scans of it spent, half again the last budget when that scan ran short of it, or the scan type’s minimum on the first.
A preset ref from /scan-presets. Defaults to the first active preset.
Branch to scan (resolved to its head commit server-side). Ignored if commitHash is set.
Pin a specific commit SHA (7-40 hex chars).
What a diff scan’s change is measured from: a commit SHA, branch, or tag. Required by a diff scan preset and refused by every other. The scan records the merge base of this and the scanned commit.
Area keys from /audit-areas to scope this scan to. Omit or send an empty array to scan the whole repository. A key the repository’s current map no longer names fails the launch rather than being dropped, so a scan budgeted for one subsystem never silently runs against everything.
Guidance for this scan only, replacing the repository’s configured guidance layer (it is still layered over any committed zkao.md). Omit the field to inherit the repository’s guidance; send null to scan with no guidance layer.
Examplegenerated
{ "repositoryId": "example", "creditBudget": 1, "presetRef": "example", "branch": "example", "commitHash": "example", "commitMessage": "example", "baseCommit": "example", "auditAreaKeys": [ "example" ], "guidance": "example"}Responses
Section titled “ Responses ”Scan accepted (queued)
object
The budget the scan was launched with, in credits.
Examplegenerated
{ "scanId": "example", "queued": true, "creditBudget": 1}Invalid request
object
object
Example
{ "error": { "code": "unauthorized" }}Missing, malformed, expired, or revoked token
object
object
Example
{ "error": { "code": "unauthorized" }}The project does not have enough prepaid credits to cover the scan budget. Top up credits and retry. (code insufficient_credits)
object
object
Example
{ "error": { "code": "unauthorized" }}The token lacks the required scope
object
object
Example
{ "error": { "code": "unauthorized" }}Resource not in this token’s project or repo allowlist
object
object
Example
{ "error": { "code": "unauthorized" }}The repository is still being analyzed and cannot be scanned yet. The same request succeeds once GET /repositories reports its readiness as ready. (code repository_initializing)
object
object
Example
{ "error": { "code": "unauthorized" }}The diff scan has nothing to audit. Code diff_empty: the base and the scanned commit have no change between them.
object
object
Example
{ "error": { "code": "unauthorized" }}Rate limited. Either the token’s spend limit for the current period is reached (on launch), or the token is sending too many requests. Wait the number of seconds in the Retry-After header before retrying.
object
object
Example
{ "error": { "code": "unauthorized" }}Headers
Section titled “Headers”Seconds to wait before retrying.

