#!/bin/bash # Run as "GROQ_API_KEY=gsk_... ./groq.sh 'Your query'", or set GROQ_API_KEY in # .bashrc # 1. Encode arguments into a JSON string PAYLOAD=$(jq -n --arg prompt "$*" '{ messages: [{role: "system", content: "Output raw, plain text or markdown only."}, { role: "user", content: $prompt }], model: "openai/gpt-oss-20b", temperature: 1, max_completion_tokens: 2048, top_p: 1, stream: true, reasoning_effort: "medium", stop: null }') # 2. Post the query, and fetch the response curl -s "https://api.groq.com/openai/v1/chat/completions" \ -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${GROQ_API_KEY}" \ -d "$PAYLOAD" | \ grep --line-buffered '^data: {' | \ sed -u 's/^data: //' | \ jq -j --unbuffered '.choices[0].delta.content // empty' echo "" # Add final newline