clip2ai is a small local tool that sends clipboard text or images to the OpenAI API and copies the response back to the clipboard.
It provides two endpoints:
/api/generate-code— returns code without explanations or Markdown./api/test— returns a direct answer for text questions, screenshots, multiple-choice tasks, and code exercises.
Clone the repository:
git clone https://github.com/dariiahacker1/clip2ai.git
cd clip2aiInstall dependencies:
pip install -r requirements.txtCreate a .env file:
OPENAI_API_KEY=sk-your-key
OPENAI_MODEL=gpt-4oStart the server:
python app.pyThe API runs at:
http://127.0.0.1:5000
POST /api/generate-codeRequest:
{
"prompt": "Write a Python function that returns True."
}Example:
curl -sS -X POST http://127.0.0.1:5000/api/generate-code \
-H "Content-Type: application/json" \
-d '{"prompt":"Write a Bash command that prints ping"}'Response:
{
"response": "echo ping",
"message": "Copied to clipboard"
}POST /api/testText request:
{
"text": "What is the capital of France?"
}Image request:
curl -sS -X POST http://127.0.0.1:5000/api/test \
-F "images=@screenshot.png"The endpoint returns plain text containing only the answer.
send_prompt.sh reads the current clipboard content and sends either text or an image to the selected endpoint.
On macOS, install the required utilities:
brew install pngpaste jqYou can add aliases to ~/.zshrc:
alias send="/path/to/send_prompt.sh"
alias toggle_endpoint="/path/to/toggle_endpoint.sh"Reload the shell configuration:
source ~/.zshrcRun:
sendSwitch between /api/generate-code and /api/test:
toggle_endpointTo run the script with a keyboard shortcut:
- Open the Shortcuts app.
- Create a shortcut with the Run Shell Script action.
- Run
/path/to/send_prompt.sh. - Assign a keyboard shortcut.
The generated response will be copied to the clipboard automatically.
- Clipboard images require
pngpaste. - JSON requests are processed with
jq. - Image input requires a model that supports vision.
- Clipboard content is processed locally, but requests are sent to the configured OpenAI model.