A fast, simple command-line interface for Kagi FastGPT - AI-powered search with web context.
- Simple Interface: Just type your query and get AI-powered answers
- Multiple Output Formats: Plain text, Markdown, or JSON
- Smart Color Output: Automatically detects terminals and pipes
- Web References: Includes sources with every response
- Flexible Input: Accept queries from arguments or stdin
- AI Agent Friendly: Clean output formats for automation
brew tap grantcarthew/tap
brew install grantcarthew/tap/kagigo install github.com/grantcarthew/kagi@latestgit clone https://github.com/grantcarthew/kagi.git
cd kagi
go build- Sign up at kagi.com
- Visit Account Settings > API
- Generate a FastGPT API key
export KAGI_API_KEY='your-api-key-here'Add this to your ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish to make it permanent.
kagi golang best practiceskagi [options] <query...>
# Simple query
kagi what is kubernetes
# Multiple words automatically joined
kagi golang concurrency patterns
# With quotes (optional)
kagi "explain docker containers"Clean, readable output with numbered references:
$ kagi what is open source
**Open source** refers to software with source code that is freely available for anyone to inspect, modify, and enhance 【1】. With open source software (OSS), users may view, modify, adopt, and share the source code 【2】. Open source emphasizes collaboration and transparency, allowing users to view, modify, and share the software 【1】.
References:
1. What is open source? - https://opensource.com/resources/what-open-source - Open source software is software with source code that anyone can inspect, modify, and enhance. "Source code" is the part of software that most computer users ...
2. What is Open Source Software (OSS)? - https://github.com/resources/articles/what-is-open-source-software - Open source software (OSS) refers to software that features freely available source code, which users may view, modify, adopt, and share for ...Perfect for documentation or README files:
$ kagi --format md what is open source
# what is open source
**Open source** refers to software with source code that is freely available for anyone to inspect, modify, and enhance 【1】. With open source software (OSS), users may view, modify, adopt, and share the source code 【2】. Open source emphasizes collaboration and transparency, allowing users to view, modify, and share the software 【1】.
## References
1. [What is open source?](https://opensource.com/resources/what-open-source)
> Open source software is software with source code that anyone can inspect, modify, and enhance. "Source code" is the part of software that most computer users ...
2. [What is Open Source Software (OSS)?](https://github.com/resources/articles/what-is-open-source-software)
> Open source software (OSS) refers to software that features freely available source code, which users may view, modify, adopt, and share for ...For scripting and automation:
$ kagi --format json what is open source
{
"meta": {
"id": "d598ad3c4d62f8a1319f999babff2c3e",
"node": "australia-southeast1",
"ms": 5
},
"data": {
"output": "**Open source** refers to software with source code that is freely available for anyone to inspect, modify, and enhance 【1】. With open source software (OSS), users may view, modify, adopt, and share the source code 【2】. Open source emphasizes collaboration and transparency, allowing users to view, modify, and share the software 【1】.",
"tokens": 0,
"references": [
{
"title": "What is open source?",
"snippet": "Open source software is software with source code that anyone can inspect, modify, and enhance. \"Source code\" is the part of software that most computer users ...",
"url": "https://opensource.com/resources/what-open-source"
},
{
"title": "What is Open Source Software (OSS)?",
"snippet": "Open source software (OSS) refers to software that features freely available source code, which users may view, modify, adopt, and share for ...",
"url": "https://github.com/resources/articles/what-is-open-source-software"
}
]
}
}Read queries from pipes or redirects:
# From echo
echo "explain kubernetes pods" | kagi
# From file
cat questions.txt | kagi
# From here-doc
kagi << EOF
What are the benefits of using Go for
backend development?
EOF
# In scripts
QUERY="golang vs rust performance"
echo "$QUERY" | kagi -f md > comparison.md# Quiet mode (output body only, no references)
kagi -q golang channels
# With heading (text format only)
kagi --heading golang best practices
# Markdown with quiet mode
kagi -f md -q golang testing > testing.md
# Increase timeout for complex queries
kagi --timeout 60 "comprehensive guide to kubernetes"
# Force color output in pipes
kagi --color always golang patterns | less -R
# Disable colors
kagi --color never golang patterns
# Debug mode
kagi --debug golang generics# Save JSON response
kagi -f json "golang concurrency" > response.json
# Extract just the answer
kagi -q "what is docker" > answer.txt
# Generate markdown documentation
kagi -f md "golang error handling best practices" > errors.md
# Batch processing
cat topics.txt | while read topic; do
kagi -f md -q "$topic" > "docs/${topic}.md"
done
# CI/CD usage
if kagi -q "is golang 1.23 stable"; then
echo "Proceeding with upgrade"
fi| Flag | Short | Default | Description |
|---|---|---|---|
--api-key |
$KAGI_API_KEY |
Kagi API key (overrides environment variable) | |
--format |
-f |
text |
Output format: text, txt, md, markdown, json |
--quiet |
-q |
false |
Output only response body (no heading or references) |
--heading |
false |
Include query as heading in text format | |
--timeout |
-t |
30 |
HTTP request timeout in seconds |
--color |
-c |
auto |
Color output: auto, always, never |
--verbose |
false |
Output process information to stderr | |
--debug |
false |
Output detailed debug information to stderr | |
--version |
-v |
Display version information | |
--help |
-h |
Display help message |
| Variable | Description |
|---|---|
KAGI_API_KEY |
Your Kagi API key (required unless using --api-key) |
| Code | Meaning |
|---|---|
0 |
Success |
1 |
Error (API error, network error, validation error) |
130 |
Interrupted (Ctrl+C) |
The CLI automatically detects whether output is going to a terminal or pipe:
# Colored output (terminal)
kagi golang patterns
# No colors (piped)
kagi golang patterns | less
# Force colors in pipe
kagi --color always golang patterns | less -R
# Disable colors
kagi --color never golang patternsMissing API Key:
$ kagi test
Error: API key required. Set KAGI_API_KEY environment variable or use --api-key flagEmpty Query:
$ kagi
Error: query cannot be emptyInvalid Format:
$ kagi -f xml test
Error: invalid format 'xml'. Valid formats: text, txt, md, markdown, jsonAPI Error:
$ kagi test
Error: API error (401): Invalid or missing API keyNetwork Timeout:
$ kagi --timeout 1 test
Error: request timeout after 1sUse --verbose to see what's happening:
$ kagi --verbose golang channels
Querying Kagi FastGPT API...
Response received (1234ms)
[output...]Use --debug for detailed information:
$ kagi --debug golang channels
Debug: API Key: ***
Debug: Query: golang channels
Debug: Format: text
Debug: Timeout: 30
Querying Kagi FastGPT API...
Response received (5ms)
[output...]Make sure your API key is set:
echo $KAGI_API_KEYIf empty, add to your shell config:
# Bash/Zsh
echo 'export KAGI_API_KEY="your-key"' >> ~/.bashrc
# Fish
set -Ux KAGI_API_KEY "your-key"Increase timeout for complex queries:
kagi --timeout 60 "your long query"If colors appear broken:
# Disable colors
kagi --color never queryKagi API has rate limits. If you receive a 429 error:
Error: API error (429): Rate limit exceeded. Please try again later.
Wait a few moments before retrying.
git clone https://github.com/grantcarthew/kagi.git
cd kagi
go build# Run all tests
go test ./...
# With coverage
go test -cover ./...
# Verbose
go test -v ./...kagi/
├── AGENTS.md # AI agent context and development guide
├── CHANGELOG.md # Version history and changes
├── CODE_OF_CONDUCT.md # Community guidelines
├── CONTRIBUTING.md # Contribution guidelines
├── LICENSE # Mozilla Public License 2.0
├── README.md # This file
├── ROLE.md # Role definition for AI agents
├── docs/ # Design decisions and task documentation
├── go.mod # Go module definition
├── go.sum # Dependency checksums
├── main.go # All code (types, API client, CLI, formatting)
├── main_test.go # Comprehensive test suite (83 tests)
└── test-interactive # Interactive CLI testing script
The project follows the KISS principle with a flat structure - all code in a single main.go file.
Contributions are welcome! Please feel free to submit issues or pull requests.
- Follow Go conventions (
gofmt,golint) - Add tests for new features
- Update documentation
- Keep it simple (KISS principle)
Please include:
- Operating system and version
- Go version (
go version) - Full command and error output
- Expected vs actual behavior
Report issues at: https://github.com/grantcarthew/kagi/issues
Mozilla Public License 2.0 (MPL-2.0)
See LICENSE file for details.
- Built with Cobra CLI framework
- Powered by Kagi FastGPT
- Repository: https://github.com/grantcarthew/kagi
- Issues: https://github.com/grantcarthew/kagi/issues
- Kagi: https://kagi.com
- Kagi API Docs: https://help.kagi.com/kagi/api/fastgpt.html
Note: This is an unofficial tool and is not affiliated with or endorsed by Kagi.