Spaces:
Sleeping
Sleeping
metadata
title: OpenAI Proxy Server
emoji: 🚀
colorFrom: blue
colorTo: green
sdk: docker
app_file: app.py
pinned: false
license: mit
OpenAI Format Proxy Server
This is a FastAPI proxy server designed to expose non-OpenAI standard endpoints (https://us.helicone.ai/api/llm for chat and https://openrouter.ai/api/v1/models for models) under the standard OpenAI API paths (/v1/chat/completions and /v1/models).
Features
- OpenAI Compatibility: Access the proxied endpoints using the standard OpenAI API structure.
- Streaming Support: Handles both streaming and non-streaming chat completion requests.
- Authentication: Protects the proxy server with Bearer token authentication (configure via
PROXY_API_KEYenvironment variable). - Asynchronous: Built with FastAPI for non-blocking, parallel request handling.
- Hugging Face Ready: Configured for easy deployment on Hugging Face Spaces using Docker.
Endpoints
GET /v1/models: Proxies requests tohttps://openrouter.ai/api/v1/models. RequiresAuthorization: Bearer <PROXY_API_KEY>.POST /v1/chat/completions: Proxies requests tohttps://us.helicone.ai/api/llm. RequiresAuthorization: Bearer <PROXY_API_KEY>. Supportsstream: true.GET /health: Health check endpoint.
Setup & Deployment (Hugging Face)
- Create a new Space on Hugging Face (https://huggingface.co/new-space).
- Choose Docker as the Space SDK.
- Select "Use existing Dockerfile".
- Upload the files from this repository (
app.py,requirements.txt,README.md,Dockerfile). - Go to the Settings tab of your Space.
- Under Secrets, add a new secret:
- Name:
PROXY_API_KEY - Value: Your desired secret API key for accessing this proxy.
- Name:
- The Space should build the Docker image and deploy automatically. The app will be available at port 7860 within the Space environment.
Local Development (using Docker Compose)
- Prerequisites: Ensure you have Docker and Docker Compose installed.
- Clone the repository.
- Configure API Key: Open the
docker-compose.ymlfile and replace'your_secret_key'in theenvironmentsection with your desired secret API key for the proxy. - Build and Run: Open a terminal in the project root directory and run:
docker-compose up --build - Access: The proxy server will be running and accessible at
http://localhost:8000. UseAuthorization: Bearer <your_configured_key>in your requests. - Stop: Press
Ctrl+Cin the terminal wheredocker-composeis running, and then rundocker-compose downto stop and remove the container.