import os import requests from flask import Flask, request, Response app = Flask(__name__) GEMINI_BASE_URL = "https://text.pollinations.ai/openai" @app.route("/", methods=["GET"]) def home(): return {"status": "ok", "message": "Gemini proxy is working :3"} @app.route("/", methods=["GET", "POST", "PUT", "PATCH", "DELETE"]) def proxy(endpoint): url = f"{GEMINI_BASE_URL}/{endpoint}" # Копируем все заголовки, кроме host и content-length headers = {k: v for k, v in request.headers if k.lower() not in ["host", "content-length"]} try: resp = requests.request( method=request.method, url=url, headers=headers, params=request.args, data=request.get_data(), allow_redirects=False, stream=True, ) excluded_headers = ["content-encoding", "transfer-encoding", "connection"] response_headers = [(k, v) for k, v in resp.raw.headers.items() if k.lower() not in excluded_headers] return Response(resp.content, resp.status_code, response_headers) except Exception as e: return {"error": str(e)}, 500 if __name__ == "__main__": app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))