Simple terminal app to use OpenRouter.ai with your personal API keys. Ask questions directly from your terminal and get AI responses instantly.
Please note that free models on openrouter.ai (those with :free in their slug) are typically limited to 50 requests per day if you have not purchased credits. A request on OpenRouter.ai is defined as a single API call or message sent to the model—essentially, each question or prompt you send, regardless of its length or the number of tokens involved. For 99% of people using this script, is more that enough. These limits apply per account, not per model. Switching between free models does not reset your daily quota. Please read their documentation for more: https://openrouter.ai/settings/credits
- 🚀 Minimalist CLI interface — talk to AI directly from your terminal.
- 🔑 Secure API key & model config — stored in .env file (create it by copiing .env.example), no need to enter every time.
- 🔄 Easy update: Run
ai.sh --updateto get the latest version. - 📖 Built-in help: Run
ai.sh --helpfor usage instructions. - 🤖 Full session memory — ongoing conversations with proper context (stateful chat).
- 💬 Natural language queries — just type like you're talking to a buddy.
- 💾 Chat history saved — all conversations stored as timestamped .txt files inside
chat_sessions/. - 🧠 Dynamic AI name display — bot replies are labeled with the selected model (e.g. Mistral AI:).
- 👤 Personalized & interactive input — uses your system username in the prompt and supports arrow keys for editing your message like a real terminal app.
- 🧹 Clean output — only the answer, no JSON noise.
- 🆓 Uses a free model by default — no paid account required only your API key.
- 🔍 Smart package manager detection — if curl or jq is missing, the script tells you exactly how to install it (e.g.
sudo pacman -S jq). - 🧪 Works on Linux & macOS and Windows through WLS — tested on Arch-based, Debian-based and macOS (via brew).
- ✨ Zero dependencies beyond
curlandjq— no Python, no Node.js, no drama. - 🐞 Debug mode support — run with
DEBUG=true ai.shto see full raw API responses on errors in the terminal. - 🧼 Session history is always clean — error messages are never saved in the logs, whether debug mode is on or off (default).
This CLI tool now supports ongoing, contextual chat with the AI. Unlike the old one-shot version (ask once, get one reply), this new version maintains the full conversation history during a session — so you can chat back and forth naturally, with context.
curl(usually pre-installed on most systems)jqfor JSON parsing
Ubuntu/Debian based:
sudo apt install jqCentOS/RHEL/Fedora based:
sudo yum install jq
# or for newer versions:
sudo dnf install jqArch based (btw):
sudo pacman -S jqmacOS:
brew install jqWindows (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:
- Copy the example environment file and edit it:
cp .env.example .env 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=- See
.modelsfor a list of available models. Do not edit.modelsdirectly.
-
To update the script to the latest version:
./ai.sh --update
-
To show usage instructions:
./ai.sh --help
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$ ai
💬 Start a conversation! Type your message and press Enter (Ctrl+C to exit)
🧑 cerebrux: What's the capital of Greece?
🤖 Mistral AI:
Athens is both the historical heart and the modern capital of Greece
🧑 cerebrux: Did they have a co-capital there?
🤖 Mistral AI:
Thessaloniki is widely recognized as Greece's "second city" due to its size and economic
power.
The term "co-capital" (**συμπρωτεύουσα** - symprotévousa) when applied to Thessaloniki
is an honorary, historical, and cultural designation reflecting its immense importance.By default, the error messages are mostly, user friendly:
$ ai.sh
💬 Start a conversation! Type your message and press Enter (Ctrl+C for exit)
🧑 cerebrux: Hi!
❌ API Error: No auth credentials foundIf you encounter any kind of a similar problem you can enable the debugging mode to get a more verbose output that may help us pinpoint the problem and fix it. To enable raw API response output for troubleshooting, run the script with:
$ DEBUG=true ai
💬 Start a conversation! Type your message and press Enter (Ctrl+C for exit)
🧑 cerebrux: Hi!
❌ API Error: No auth credentials found
🔍 Full response for debugging:
{
"error": {
"message": "No auth credentials found",
"code": 401
}
}You can change the AI model by editing the OPENROUTER_MODEL variable in your .env file. For available models, refer to the .models file in the repository root. Copy the desired model slug from .models and set it in your .env:
# Leave empty or unset to use the default model
OPENROUTER_MODEL=
# Example:
OPENROUTER_MODEL=qwen/qwq-32b:freeNote: If OPENROUTER_MODEL is not set or left empty, the script will use the default Mistral model. Do not edit .models directly.
-
"jq: command not found"
- Install jq using the instructions above
-
"Error: .env file not found"
- Make sure you have a
.envfile in the same directory asai.sh - Check that your API key is properly set in the
.envfile
- Make sure you have a
-
"Error: OPENROUTER_API_KEY is not set"
- Verify your
.envfile 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_MODELsetting in.envis 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
This project is licensed under the Apache 2.0 - 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.