Skip to content
/ selfAPI Public

πŸ”„ cURL to OpenRouter Server Converter Python utility that converts cURL commands into Node.js servers with OpenRouter API integration. Creates OpenAI-compatible endpoints with streaming support and error handling. ⚑️ Features: - Interactive CLI interface - Streaming response support - Comprehensive error handling - OpenAI-compatible endpoint πŸ› 

Notifications You must be signed in to change notification settings

rafsid/selfAPI

Repository files navigation

cURL to OpenRouter Server Converter

Overview

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.

Features

  • 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

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/selfAPI.git
cd selfAPI
  1. Install Python dependencies:
pip install readchar
  1. For the generated server, install Node.js dependencies:
npm install express body-parser axios

Usage

  1. Run the converter script:
python sergen.py
  1. 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'
  1. Enter the desired output filename (e.g., server.js)

  2. The script will generate a Node.js server file with:

  • Express server setup
  • Request handling
  • Error management
  • Streaming support
  • OpenRouter API integration

Generated Server Features

  • OpenAI-compatible /v1/chat/completions endpoint
  • Support for streaming responses
  • Comprehensive error handling
  • Request validation
  • Detailed logging

Configuration

The generated server includes:

  • Port configuration (default: 3000)
  • Headers from original cURL command
  • Error logging system
  • Response formatting

Example Usage of Generated Server

  1. Start the server:
node server.js
  1. 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
  }'

Error Handling

The generated server includes robust error handling:

  • API communication errors
  • Request validation
  • Response parsing
  • Stream processing
  • Detailed error logging

Security Notes

  • Review and sanitize headers before deployment
  • Secure API keys and sensitive information
  • Consider adding rate limiting
  • Implement proper authentication

Contributing

Contributions are welcome! Please read our Contributing Guidelines for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • OpenRouter API team for the API service
  • Express.js team for the web framework
  • Axios team for the HTTP client

About

πŸ”„ cURL to OpenRouter Server Converter Python utility that converts cURL commands into Node.js servers with OpenRouter API integration. Creates OpenAI-compatible endpoints with streaming support and error handling. ⚑️ Features: - Interactive CLI interface - Streaming response support - Comprehensive error handling - OpenAI-compatible endpoint πŸ› 

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published