Simple terminal app to use OpenRouter.ai with your personal API keys. Ask questions directly from your terminal and get AI responses instantly.
- 🚀 Simple command-line interface
- 🔑 Secure API key and model management with
.env
file - 🎯 Clean output (only the AI response, no JSON clutter)
- 💬 Natural language queries
- 🆓 Uses free Mistral model by default
- ⚡ Stateless design - each query is independent (no conversation history)
This tool is designed for single-question interactions. Each time you run the script, it sends an independent query to the AI model without any memory of previous conversations. If you need multi-turn conversations with context retention, consider using the OpenRouter web interface or building a more advanced wrapper that maintains conversation history.
curl
(usually pre-installed on most systems)jq
for JSON parsing
Ubuntu/Debian:
sudo apt install jq
CentOS/RHEL/Fedora:
sudo yum install jq
# or for newer versions:
sudo dnf install jq
macOS:
brew install jq
Windows (WSL):
sudo apt install jq
-
Clone or download this repository:
git clone https://github.com/SynergOps/openrouter.ai cd openrouter.ai
-
Ensure the script is executable:
chmod +x ai.sh
-
Get your OpenRouter API key:
- Go to OpenRouter.ai
- Sign up with your Github account for a free account
- Navigate to models and then the Mistral Small 3.2 24B (free)
- Click API keys section
- Generate a new API key
-
Configure your API key and model:
- while you are in the openrouter folder, edit the
.env
file template and add your API key:
vim .env
- Add your API key and optionally configure the model:
# OpenRouter API Configuration OPENROUTER_API_KEY=sk-or-v1-your-actual-api-key-here # OpenRouter Model Configuration (optional - leave empty for default) OPENROUTER_MODEL=
- while you are in the openrouter folder, edit the
./ai.sh your question here
# Ask a simple question
./ai.sh what is the meaning of life
# Ask for coding help
./ai.sh how do I create a function in Python
# Ask for a definition
./ai.sh define recursion
# Ask for a summary
./ai.sh summarize the plot of "The Hitchhiker's Guide to the Galaxy"
$ ./ai.sh what is the meaning of 42
The number 42 is famously known as "The Answer to the Ultimate Question of Life, the Universe, and Everything" from Douglas Adams' science fiction series "The Hitchhiker's Guide to the Galaxy."
For easier access, you can create an alias so you can use the script from anywhere without typing the full path:
Option 1: Temporary alias (current session only)
alias ai='/path/to/your/openrouter.ai/ai.sh'
Option 2: Permanent alias (recommended)
-
For Bash users - Add to your
~/.bashrc
or~/.bash_profile
:cd /path/to/your/openrouter.ai echo "alias ai='$(pwd)/ai.sh'" >> ~/.bashrc source ~/.bashrc
-
For Zsh users - Add to your
~/.zshrc
:cd /path/to/your/openrouter.ai echo "alias ai='$(pwd)/ai.sh'" >> ~/.zshrc source ~/.zshrc
-
Manual method - Edit your shell config file:
# Open your shell config file nano ~/.bashrc # or ~/.zshrc for Zsh users # Add this line (replace with your actual path): alias ai='/full/path/to/openrouter.ai/ai.sh' # Reload your shell config source ~/.bashrc # or source ~/.zshrc
After setting up the alias, you can use it from anywhere:
# Instead of ./ai.sh question
# Works from any directory
cd ~/Documents
ai explain machine learning
You can change the AI model by editing the OPENROUTER_MODEL
variable in your .env
file:
# Leave empty or unset to use the default model
OPENROUTER_MODEL=
# Or specify a different model
OPENROUTER_MODEL=qwen/qwq-32b:free
Popular free models on OpenRouter include:
mistralai/mistral-small-3.2-24b-instruct:free
(default)qwen/qwq-32b:free
deepseek/deepseek-r1-0528:free
google/gemini-2.0-flash-exp:free
Note: If OPENROUTER_MODEL
is not set or left empty, the script will use the default Mistral model.
-
"jq: command not found"
- Install jq using the instructions above
-
"Error: .env file not found"
- Make sure you have a
.env
file in the same directory asai.sh
- Check that your API key is properly set in the
.env
file
- Make sure you have a
-
"Error: OPENROUTER_API_KEY is not set"
- Verify your
.env
file contains:OPENROUTER_API_KEY=your-actual-key
- Make sure there are no extra spaces around the
=
sign
- Verify your
-
Empty, Invalid model, or other errors
- Check that your
OPENROUTER_MODEL
setting in.env
is correct - Verify the model name is available on OpenRouter
- Leave
OPENROUTER_MODEL=
empty to use the default model
- Check that your
-
Empty or error responses
- Carefully read the message response and act accordingly
- Verify your API key is valid and active
- Check your internet connection
- Ensure you haven't exceeded any rate limits
The script automatically shows the full JSON response when it encounters errors or unexpected responses. If you need to see the raw API response for debugging purposes, the script will display it when:
- The API returns an error
- The response format is unexpected
- The content cannot be extracted properly
This provides all the debugging information you need without manually modifying the script.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to submit issues, fork the repository, and create pull requests for any improvements.
If you encounter any issues or have questions, please open an issue on GitHub.