Skip to content

Microck/kagi-cli

kagi cli

release badge ci badge license badge


kagi is a terminal CLI for Kagi that gives you command-line access to search, lenses, assistant, summarization, feeds, and paid API commands. it is built for people who want one command surface for interactive use, shell workflows, and structured JSON output.

the main setup path is your existing Kagi session-link URL. paste it into kagi auth set --session-token and the CLI extracts the token for you. if you also use Kagi's paid API, add KAGI_API_TOKEN and the public API commands are available too.

documentation | npm | github

search demo

why

if you already use Kagi and want to access it from scripts, shell workflows, or small tools, this CLI gives you a practical path without making the paid API flow the starting point.

  • use your existing session-link URL for subscriber features
  • get structured JSON for scripts, agents, and other tooling
  • use one CLI for search, assistant, summarization, and feeds
  • add KAGI_API_TOKEN only when you want the paid public API commands

quickstart

Linux or macOS

curl -fsSL https://raw.githubusercontent.com/Microck/kagi-cli/main/scripts/install.sh | sh
kagi --help

Windows

irm https://raw.githubusercontent.com/Microck/kagi-cli/main/scripts/install.ps1 | iex
kagi --help

using a package manager

npm install -g kagi-cli
pnpm add -g kagi-cli
bun add -g kagi-cli

brew tap Microck/kagi
brew install kagi

scoop bucket add kagi https://github.com/Microck/scoop-kagi
scoop install kagi

auth

add your subscriber session token:

how to get it:

  1. click the top-right menu icon
  2. go into Settings
  3. click Account in the left sidebar
  4. in Session Link, click Copy

session-link tutorial

kagi auth set --session-token 'https://kagi.com/search?token=...'
kagi auth check

add an api token when you want the paid public api commands:

how to get it:

  1. click the top-right menu icon
  2. go into Settings
  3. click Advanced in the left sidebar
  4. go into Open API Portal
  5. under API Token, click Generate New Token

api token tutorial

export KAGI_API_TOKEN='...'

auth model

credential what it unlocks
KAGI_SESSION_TOKEN base search, search --lens, assistant, summarize --subscriber
KAGI_API_TOKEN public summarize, fastgpt, enrich web, enrich news
none news, smallweb, auth status, --help

example config:

[auth]
# Full Kagi session-link URL or just the raw token value.
session_token = "https://kagi.com/search?token=kagi_session_demo_1234567890abcdef"

# Paid API token for summarize, fastgpt, and enrich commands.
api_token = "kagi_api_demo_abcdef1234567890"

# Base `kagi search` auth preference: "session" or "api".
preferred_auth = "api"

notes:

  • kagi auth set --session-token accepts either the raw token or the full session-link URL
  • environment variables override .kagi.toml
  • base kagi search defaults to the session-token path when both credentials are present
  • set [auth] preferred_auth = "api" if you want base search to prefer the API path instead
  • search --lens always requires KAGI_SESSION_TOKEN
  • auth check validates the selected primary credential without using search fallback logic

for the full command-to-token matrix, use the auth-matrix docs page.

command surface

command purpose
kagi search search Kagi with JSON by default or --format pretty for terminal output
kagi batch run multiple searches in parallel with JSON, compact, pretty, markdown, or csv output
kagi auth inspect, validate, and save credentials
kagi summarize use the paid public summarizer API or the subscriber summarizer with --subscriber
kagi news read Kagi News from public JSON endpoints
kagi assistant prompt Kagi Assistant with a subscriber session token
kagi fastgpt query FastGPT through the paid API
kagi enrich query Kagi's web and news enrichment indexes
kagi smallweb fetch the Kagi Small Web feed

for automation, stdout stays JSON by default. --format pretty only changes rendering for humans.

shell completion

generate a completion script and install it with your shell of choice:

# bash
kagi --generate-completion bash > ~/.local/share/bash-completion/completions/kagi

# zsh
kagi --generate-completion zsh > ~/.zsh/completion/_kagi

# fish
kagi --generate-completion fish > ~/.config/fish/completions/kagi.fish

see the installation guide for platform-specific setup details.

examples

use search as part of a shell pipeline:

kagi search "what is mullvad"

switch the same command to terminal-readable output:

kagi search --format pretty "how do i exit vim"

scope search to one of your lenses:

kagi search --lens 2 "developer documentation"

run a few searches in parallel:

kagi batch "rust programming" "python tutorial" "go language"

change batch output format for shell pipelines:

kagi batch "rust" "python" "go" --format compact

continue research with assistant:

kagi assistant "plan a focused research session in the terminal"

use the subscriber summarizer:

kagi summarize --subscriber --url https://kagi.com --summary-type keypoints --length digest

use the paid api summarizer:

kagi summarize --url https://example.com --engine cecil

get a faster factual answer through the paid api:

kagi fastgpt "what changed in rust 1.86?"

query enrichment indexes:

kagi enrich web "local-first software"
kagi enrich news "browser privacy"

what it looks like

if you want a quick feel for the cli before installing it, this is the kind of output you get from the subscriber summarizer, assistant, and public news feed:

summarize demo

assistant demo

news demo

building from source

if you are working on the cli itself, build from a local checkout:

git clone https://github.com/Microck/kagi-cli.git
cd kagi-cli
cargo build --release
./target/release/kagi --help

for the fuller install matrix and platform-specific setup, use the installation guide.

documentation

license

mit license

todo

About

terminal CLI for Kagi that gives you command-line access to search, lenses, assistant, summarization, feeds, and paid API commands.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors