This project is an API router that intercepts multimodal requests (Image/Video), even when the multimodal data is a link in the text body of the request. It intelligently processes requests that include image or video links, logs all activity, tracks costs, and routes requests to appropriate models via OpenRouter.
-
Clone the repository:
git clone https://github.com/dsetareh/OpenRouter-MultiModal-Proxy cd OpenRouter-MultiModal-Proxy -
Configure environment variables:
- Copy
.env.exampleto.envin the root of the project:cp .env.example .env
- Edit the
.envfile and add yourOPENROUTER_API_KEYand any other configurations. Thedocker-compose.ymlfile is set up to pass these variables to the container.
- Copy
-
Build and run the application using Docker Compose: Open your terminal in the project root directory and run:
docker-compose up -d --build
- The application will be available at
http://<docker_host>:8000.
- OpenAI API Compatibility:
- Supports
POST /v1/chat/completionsfor chat-based interactions. - Supports
POST /v1/completionsfor legacy text completion.
- Supports
- Intelligent Media Processing:
- Detects image and video URLs within request payloads.
- Processes images (downloads and converts to base64 if necessary).
- Processes videos by downloading, extracting audio, transcribing audio (using a configurable
faster-whispermodel and device), and extracting keyframes. - Transforms requests with media content into a format suitable for multimodal models on OpenRouter.
- OpenRouter Integration:
- Routes requests to specified or default models on OpenRouter.
- Utilizes
OPENROUTER_API_KEYfor authentication. - Allows configuration of
HTTP-RefererandX-Titlefor OpenRouter requests.
- Comprehensive Logging:
- Logs full request and response bodies in structured JSON format to
router.log.json. - Includes timestamps, unique request IDs, endpoint details, and processing durations.
- Implements log rotation.
- Logs full request and response bodies in structured JSON format to
- Cost Tracking & Analytics:
- Stores detailed request information in a local SQLite database (
.db). - Tracks model usage, tokens, costs (as reported by OpenRouter), latencies, and potential errors.
- Stores detailed request information in a local SQLite database (
- Web UI for Tracking:
- Provides a web interface at
/ui/trackingto view and filter logged API requests. - Allows pagination, sorting, and searching of request data.
- Provides a web interface at
POST /v1/chat/completionsPOST /v1/completions
GET /ui/tracking_dataGET /ui/tracking