Script PiG with JSON mode

Run one prompt headless and read the events as JSON lines, for CI and scripts.

Guides / Embed PiG

Tested · 2026-11-07

Recording: watch the json-mode demo

JSON mode runs one prompt and prints every event as a JSON line, then exits. Use it in scripts and CI where you want the result without a terminal UI.

Prerequisites: pig 0.7.0 or later and a configured model.

Step 1: print mode, plain text

pig -p "Say hello"

-p runs the prompt once and prints the final reply.

Step 2: JSON mode, events

pig --mode json -p "Say hello"

The first line is the session header with the session id and working directory. Then each event is one line: agent_start, turn_start, message_start and message_end for the system, user and assistant messages, message_update while the reply streams, tool events when a tool runs, and the end of the turn.

Verify

Both commands exit with status 0. The first prints the reply. The second prints one JSON object per line, starting with {"type":"session",...}. The screenshot below is that run with pig 0.7.0 and a scripted model (2026-11-07). The event types and shapes are documented in JSON event stream mode.

Terminal: pig -p and pig --mode json -p
pig 0.7.0 print mode and JSON mode with a scripted model.

Test record

Tested 2026-11-07 with pig 0.7.0 on Linux amd64, using a local scripted model so no key is needed. Where a step needs a real model or a published artifact that we did not use, the guide says so.