How would you feel if you could have access to AI models, many of which are free, directly from the comfort of your terminal?
In this article, we will explore how you can achieve this using the OpenRouter.ai platform and a simple script I’ve prepared, called ai.sh (… very original… I know).
Free AI in your Terminal with OpenRouter and ai.sh
ai.sh is a simple terminal app to use OpenRouter.ai with your personal API keys. Ask questions directly from your terminal and get AI responses instantly.
Features of ai.sh
- ๐ Simple command-line interface
- ๐ Secure API key and model management with
.envfile - ๐ฏ 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)
Important Note
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.
Prerequisites
curl(usually pre-installed on most systems)jqfor JSON parsing
Installing jq
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
Installation
- 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
.envfile 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=
Usage
Basic Usage
./ai.sh your question here
Examples
# 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"
Sample Output
$ ./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."
Creating a Terminal Alias (Recommended)
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
~/.bashrcor~/.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
Configuration
Changing the AI Model
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:freedeepseek/deepseek-r1-0528:freegoogle/gemini-2.0-flash-exp:free
Note: If OPENROUTER_MODEL is not set or left empty, the script will use the default Mistral model.
License
This project is licensed under the Apache-2.0 license – see the LICENSE file for details.
Support
If you encounter any issues or have questions, please open an issue on GitHub.
Check also, my other projects in the download page

Leave a Reply