Skip to main content

Output Contract

This page documents the current CLI output behavior as implemented in the repo.

Core Rules

  1. Most commands print pretty-formatted JSON to stdout on success.
  2. kagi search, kagi batch, kagi quick, and kagi assistant support alternate output via format flags, including toon for token-efficient structured context.
  3. Errors are plain text on stderr and exit with status code 1 by default. Use global --error-format json or KAGI_ERROR_FORMAT=json for a structured stderr envelope.
  4. Output shapes differ by command. There is no single universal response envelope.

Success Shapes

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:
Subscriber 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:
If the result set is empty, the CLI prints:

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:
Opt into JSON errors with global --error-format json or KAGI_ERROR_FORMAT=json. The envelope is compact JSON on stderr:

jq Examples