JSON Output

# JSON Output Use the `--json` flag to get structured output for scripting and automation: ```bash kit "Explain main.go" --json --quiet --no-session ``` ## Response format ```json { "response": "Final assistant response text", "model": "anthropic/claude-haiku-latest", "stop_reason": "end_turn", "session_id": "a1b2c3d4e5f6", "usage": { "input_tokens": 1024, "output_tokens": 512, "total_tokens": 1536, "cache_read_tokens": 0, "cache_creation_tokens": 0 }, "messages": [ { "role": "assistant", "parts": [ {"type": "text", "data": "..."}, {"type": "tool_call", "data": {"name": "...", "args": "..."}}, {"type": "tool_result", "data": {"name": "...", "result": "..."}} ] } ] } ``` ## Fields ### Top-level | Field | Type | Description | |-------|------|-------------| | `response` | string | The final assistant response text | | `model` | string | The model that was used | | `stop_reason` | string | Why the model stopped (e.g., `end_turn`) | | `session_id` | string | Session identifier (omitted in `--no-session` mode) | | `usage` | object | Token usage statistics | | `messages` | array | Full conversation history | ### Usage | Field | Type | Description | |-------|------|-------------| | `input_tokens` | int | Tokens sent to the model | | `output_tokens` | int | Tokens generated by the model | | `total_tokens` | int | Sum of input and output tokens | | `cache_read_tokens` | int | Tokens read from prompt cache | | `cache_creation_tokens` | int | Tokens written to prompt cache | ### Message parts Each message contains a `parts` array with typed entries: | Type | Description | |------|-------------| | `text` | Assistant text content | | `tool_call` | Tool invocation with name and args | | `tool_result` | Tool execution result | | `reasoning` | Extended thinking content | | `finish` | End-of-turn marker | ## Parsing in scripts ### bash + jq ```bash result=$(kit "Count files" --json --quiet --no-session) response=$(echo "$result" | jq -r '.response') tokens=$(echo "$result" | jq '.usage.total_tokens') ``` ### Go SDK For Go programs, use the SDK's `PromptResult` method instead of parsing JSON: ```go result, err := host.PromptResult(ctx, "Count files") fmt.Println(result.Response) fmt.Println(result.Usage.TotalTokens) ```