You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP

github.com/tmc/misc/ssecat

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/tmc/misc/ssecat

v0.0.0-20250526065813-6901bcf3e562
Version published
Created

ssecat

Go Reference

Command ssecat processes Server-Sent Events (SSE) streams and extracts data based on JSON paths.

This tool reads SSE streams from files or stdin, parses JSON data within events, and extracts values based on specified JSON paths. It's particularly useful for processing streaming API responses from services like OpenAI, Anthropic, and other LLM providers. The tool also supports structured output of content blocks including text and tool use blocks from Claude API responses.

Usage:

ssecat [flags] [files...]

Flags:

-f file      Input file (default: "-" for stdin)
-delay dur   Delay between processing chunks
-path paths  Space-separated JSON path patterns to extract
-w           Run HTTP server that streams output
-port n      HTTP server port when using -w (default: 8072)
-m           Include metadata (tokens, stop reason) in output
-v           Verbose output (print formatted JSON)
-vv          Very verbose output (print raw lines and formatted JSON)
-fail-on-error  Exit with error on JSON parsing failures (default: true)
-cat-non-sse Output raw content for non-SSE input instead of error (default: true)
-progress    Show content block progress on stderr during streaming
-omit-message-start  Omit message_start events from output

Examples:

# Process SSE stream from stdin
curl -N https://api.example.com/stream | ssecat

# Extract specific JSON paths from Claude API responses
ssecat -path "type=content_block_delta,delta.text" claude-response.txt

# Run as HTTP server streaming responses
ssecat -w -port 8080 &
curl http://localhost:8080/

# Process with metadata output
ssecat -m stream.txt

# Show streaming progress on stderr
ssecat -progress stream.txt

# Process without message_start events
ssecat -omit-message-start stream.txt

The tool supports complex JSON path patterns for extracting nested data from streaming responses. Multiple paths can be specified and will be processed in order. When processing Claude API responses, the tool automatically handles content blocks, outputting text blocks as plain text and tool use blocks as JSON.

Test ssecat using script testing.

Installation

Prerequisites: Go Installation

You'll need Go 1.21 or later. Install Go if you haven't already.

Setting up your PATH

After installing Go, ensure that $HOME/go/bin is in your PATH:

For bash users

Add to ~/.bashrc or ~/.bash_profile:

export PATH="$PATH:$HOME/go/bin"

Then reload your configuration:

source ~/.bashrc
For zsh users

Add to ~/.zshrc:

export PATH="$PATH:$HOME/go/bin"

Then reload your configuration:

source ~/.zshrc

Install

go install github.com/tmc/misc/ssecat@latest

Run directly

go run github.com/tmc/misc/ssecat@latest [arguments]

FAQs

Package last updated on 26 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts