A Python utility that converts cURL commands into a Node.js server implementation compatible with OpenRouter API. The generated server code provides an OpenAI-compatible endpoint that proxies requests to OpenRouter's API.
- Converts cURL commands to fully functional Node.js server code
- Parses and preserves headers and authentication details
- Supports streaming responses
- Handles error cases gracefully
- Interactive command-line interface
- Clone the repository:
git clone https://github.com/yourusername/selfAPI.git
cd selfAPI
- Install Python dependencies:
pip install readchar
- For the generated server, install Node.js dependencies:
npm install express body-parser axios
- Run the converter script:
python sergen.py
- When prompted, paste your cURL command. Example format:
curl 'https://openrouter.ai/api/v1/chat/completions' \
-H 'Authorization: Bearer your_token_here' \
-H 'Content-Type: application/json'
-
Enter the desired output filename (e.g.,
server.js
) -
The script will generate a Node.js server file with:
- Express server setup
- Request handling
- Error management
- Streaming support
- OpenRouter API integration
- OpenAI-compatible
/v1/chat/completions
endpoint - Support for streaming responses
- Comprehensive error handling
- Request validation
- Detailed logging
The generated server includes:
- Port configuration (default: 3000)
- Headers from original cURL command
- Error logging system
- Response formatting
- Start the server:
node server.js
- Make requests to the local endpoint:
curl http://localhost:3000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "deepseek_code",
"messages": [{"role": "user", "content": "Hello"}],
"stream": true
}'
The generated server includes robust error handling:
- API communication errors
- Request validation
- Response parsing
- Stream processing
- Detailed error logging
- Review and sanitize headers before deployment
- Secure API keys and sensitive information
- Consider adding rate limiting
- Implement proper authentication
Contributions are welcome! Please read our Contributing Guidelines for details.
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenRouter API team for the API service
- Express.js team for the web framework
- Axios team for the HTTP client