Output Contract
This page documents the current CLI output behavior as implemented in the repo.Core Rules
- Most commands print pretty-formatted JSON to stdout on success.
kagi search,kagi batch,kagi quick, andkagi assistantsupport alternate output via format flags, includingtoonfor token-efficient structured context.- Errors are plain text on stderr and exit with status code
1by default. Use global--error-format jsonorKAGI_ERROR_FORMAT=jsonfor a structured stderr envelope. - Output shapes differ by command. There is no single universal response envelope.
Success Shapes
kagi search
kagi search --news
The News tab vertical returns a different shape — clusters of articles:
time_relative is preserved verbatim from Kagi’s page (the News tab does not expose absolute timestamps). Single-item clusters represent ungrouped articles at the top of the results page.
kagi batch
Default JSON output uses a structured envelope:
kagi summarize
Public API mode:
kagi extract
Single-URL extract prints markdown by default, or the full Extract API envelope with --format json:
kagi extract --filter prints compact JSONL, one record per stdin URL:
kagi news
kagi news --list-categories and kagi news --chaos return different JSON shapes with category metadata or chaos metadata.
kagi assistant
kagi assistant --stream writes incremental markdown deltas to stdout and flushes after each update. kagi assistant --stream --stream-output json writes the same stream as newline-delimited compact JSON events with an md_delta field plus the current meta, thread, and message snapshot.
kagi assistant --contract <NAME> and kagi assistant --contract-file <PATH> print only the validated contract JSON. Contract mode supports --format json and --format compact.
kagi assistant custom
list returns an array of assistant summaries:
get, create, and update return assistant details:
kagi lens
kagi bang custom
kagi redirect
kagi quick
kagi translate
kagi ask-page
kagi fastgpt
kagi enrich
kagi smallweb
Pretty Search Output
kagi search --format pretty renders results like this:
Pretty Quick Output
kagi quick --format pretty renders:
Pretty Assistant Output
kagi assistant --format pretty renders:
Error Behavior
Errors are plain text on stderr. Typical examples:--error-format json or KAGI_ERROR_FORMAT=json. The envelope is compact JSON on stderr: