sjq Brings Debugging Clarity to AI Streaming Responses

A new Rust CLI tool reduces the overhead of parsing OpenAI-compatible chat completion streams.

GeoDetect PipelineOctober 16, 2026
Share
Article cover image

Overview

A new open-source tool called sjq is emerging as a practical solution for developers struggling with the opaque nature of AI streaming responses. As large language models become more complex, the data transmitted over the wire has grown increasingly verbose, making it difficult to inspect what is actually happening in real-time.

sjq processes these streams to filter out noise, delivering only the meaningful tokens and timing data to the user. By treating the stream differently than standard JSON processing tools, it offers clarity that was previously unavailable to engineers debugging AI integrations.

The Problem with Streaming Envelopes

Modern LLM APIs do not send a single, clean JSON object when streaming. Instead, they transmit a series of Server-Sent Events (SSE). Each event contains a substantial metadata envelope surrounding a tiny fragment of the actual response.

For a simple chat completion with a short answer, approximately 99.1% of the data transmitted is envelope rather than content. When reasoning models are involved, this ratio shifts only slightly, with roughly 98.6% of the bandwidth consumed by repetitive structural data.

Standard tools like jq fail in this context because they expect complete, standalone JSON documents. Piping a raw stream into jq results in parse errors, as the tool encounters partial data lines and HTTP headers that violate its parsing assumptions.

Similarly, using grep to extract text is insufficient. It cannot distinguish between different types of content, such as separating reasoning tokens from final answer tokens, which are often housed in different fields within the same stream.

How sjq Works

sjq addresses these limitations by reading the stream incrementally and tracking only what changes with each event. It understands the structure of SSE and filters out the repetitive metadata.

The tool outputs a simplified, line-by-line representation of the stream. For instance, while a raw chunk might contain dozens of null values, sjq extracts only the relevant delta, such as the specific text token being generated.

It also preserves critical context by printing a meta line once per stream, capturing the ID, creation timestamp, and model name. This allows developers to correlate output with the specific request without being drowned in redundant data.

Furthermore, sjq handles reasoning content flexibly. It maintains the field name provided by the server, whether it is reasoning_content, reasoning, or another provider-specific variant. This ensures compatibility across different AI vendors without requiring tool updates.

Timing and Performance Insights

Beyond text extraction, sjq provides valuable performance metrics automatically. The final output includes a summary line detailing connection time, time to first byte, time to first token, and overall speed.

This information is crucial for diagnosing latency issues in AI applications. Developers can quickly identify whether delays are occurring during network connection, TLS negotiation, or the model's initial processing phase.

The tool also prints token usage statistics, dropping zero-value counters to keep the output clean. This gives immediate visibility into cost and efficiency without requiring additional API calls or log parsing.

Usage and Installation

sjq is designed to be a drop-in replacement for jq in many workflows, but it also integrates directly with curl. Users can pipe a streaming response into sjq and receive cleaned output instantly.

For those who prefer not to manage raw piping, sjq can run curl itself, automatically handling headers and formatting. This makes it easier to debug requests without writing complex shell scripts.

The tool is distributed as a single binary with minimal dependencies, specifically requiring only serde_json and a recent stable version of Rust. Installation is straightforward via Homebrew for macOS users or by building from source on other platforms.

brew tap vivgrid/tap
brew install sjq

The output is formatted for readability, with text quoted and escaped so that leading spaces, empty deltas, and newlines are visible. This attention to detail helps developers spot subtle issues in model output that might otherwise go unnoticed.

Why It Matters

As AI applications become more prevalent in production environments, the need for effective debugging tools grows. The current trend toward longer reasoning chains and more complex streaming protocols exacerbates the difficulty of monitoring these systems.

sjq offers a lightweight, efficient way to gain transparency into these processes. By stripping away the overwhelming volume of envelope data, it allows engineers to focus on what matters: the actual content and performance of their AI models.

This tool represents a small but significant step toward better observability in the rapidly evolving landscape of generative AI development.

Share

Sources

Tools mentioned