This NovelAI Proxy Service is a Flask-based application that acts as an intermediary between clients and the NovelAI API. It provides a secure and efficient way to handle requests to NovelAI's image generation service, implementing features such as load balancing, automatic token refresh, and error handling.
Please consume it with NovelAI-API-Unoffical API
- Secure proxy for NovelAI API requests
- Load balancing across multiple API endpoints
- Automatic access token refresh on 403 errors
- Request queuing and multi-threaded processing
- Comprehensive logging
- Environment-based configuration
- Token-based authentication for incoming requests
- Python 3.7+
- pip (Python package manager)
novelai-proxy-service/
│
├── src/
│ ├── api/
│ │ └── routes.py
│ ├── core/
│ │ ├── config.py
│ │ └── logging.py
│ ├── models/
│ │ └── user.py
│ ├── services/
│ │ ├── api_client.py
│ │ └── worker.py
│ └── utils/
│ └── auth.py
├── logs/
├── .env.example
├── .gitignore
├── requirements.txt
├── setup.py
├── README.md
└── run.py
- Clone the repository:
git clone https://github.com/yourusername/novelai-proxy-service.git
cd novelai-proxy-service
- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows, use venv\Scripts\activate
- Install the required packages:
pip install -r requirements.txt
- Set up your environment variables by creating a
.env
file in the root directory:
NOVELAI_USERNAME=your_username
NOVELAI_PASSWORD=your_password
SERVER_TOKENS=token1,token2,token3
NOVEL_TOKEN=your_initial_token # Optional
- Start the server:
python run.py
- The server will start on
http://127.0.0.1:5000
by default. - To make a request to the NovelAI API through the proxy, send your request to
http://127.0.0.1:5000/ai/generate-image
- make sure to include your service authentication token in the
Authorization
header.
src/core/config.py
: Contains theConfig
class for managing environment variables and application settings..env
: Store your sensitive information and configuration here.
/ai/generate-image
: Proxies requests to NovelAI's image generation API.
- The service automatically handles 403 errors by refreshing the NovelAI access token.
- Other errors are logged and appropriate error responses are sent back to the client.
- Logs are stored in the
logs/
directory. - The default log file is
app.log
. - Log rotation is implemented to manage log file sizes.
- Incoming requests are authenticated using tokens defined in the
SERVER_TOKENS
environment variable. - NovelAI credentials are securely managed through environment variables.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
GNU General Public License v3.0
This project is not officially affiliated with NovelAI. Use at your own risk and ensure compliance with NovelAI's terms of service.