Technical Reference
Headless mode is triggered when the CLI is run in a non-TTY environment or when providing a query as a positional argument without the interactive flag.Output Formats
You can specify the output format using the--output-format flag.
JSON Output
Returns a single JSON object containing the response and usage statistics. Schema:The model’s final answer.
Token usage and API latency metrics.
Error details if the request failed (optional).
Streaming JSON Output
Returns a stream of newline-delimited JSON (JSONL) events. Event types:Session metadata (session ID, model).
User and assistant message chunks.
Tool call requests with arguments.
Output from executed tools.
Non-fatal warnings and system errors.
Final outcome with aggregated statistics.
Exit Codes
The CLI returns standard exit codes to indicate the result of the headless execution:Success.
General error or API failure.
Input error (invalid prompt or arguments).
Turn limit exceeded.
Common Use Cases
CI/CD Integration
Automate code reviews, changelog generation, or test creation in your CI pipeline.
Batch Processing
Process multiple files or inputs in a loop for consistent analysis or transformation.
API Wrapper
Build custom APIs or services on top of Gemini CLI capabilities.
Monitoring & Alerts
Generate reports or summaries from logs and system data.
Next Steps
CLI Reference
See all available flags and options for headless mode