Skip to content

Instantly share code, notes, and snippets.

@maedoc
Last active October 3, 2025 12:23
Show Gist options
  • Save maedoc/4daedc3f5deaa1c24b631068fab48664 to your computer and use it in GitHub Desktop.
Save maedoc/4daedc3f5deaa1c24b631068fab48664 to your computer and use it in GitHub Desktop.
script for grabbing some search from cli
#!/usr/bin/env bash
# kagi-ask — tiny CLI for Kagi FastGPT
# usage: kagi-ask what is the integral of 'e^(-x^2)' from -inf to inf
set -euo pipefail
[[ -z "${KAGI_API_KEY:-}" ]] && { echo "KAGI_API_KEY not set" >&2; exit 1; }
QUERY="$*"
[[ -z "$QUERY" ]] && { echo "Usage: $0 <question>" >&2; exit 1; }
RESPONSE=$(
curl -sS \
-H "Authorization: Bot $KAGI_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"query\":\"$QUERY\"}" \
https://kagi.com/api/v0/fastgpt
)
# ---- tidy answer ----
jq -r '.data.output' <<<"$RESPONSE" \
| fold -sw80
# ---- sources ----
printf '\nSources\n'
jq -r '.data.references | to_entries[] | "\(.key+1). \(.value.url)"' <<<"$RESPONSE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment