|
from flask import Flask, request, jsonify |
|
import os |
|
import requests |
|
|
|
app = Flask(__name__) |
|
|
|
|
|
API_KEY = os.getenv("OPENAI_API_KEY") |
|
FAKE_KEY = os.getenv("FAKE_KEY", "fake-key") |
|
BASE_URL = "https://api.typegpt.net" |
|
|
|
|
|
@app.route("/<path:endpoint>", methods=["POST"]) |
|
def proxy(endpoint): |
|
|
|
client_key = request.headers.get("Authorization") |
|
if client_key != f"Bearer {FAKE_KEY}": |
|
return jsonify({"error": "Unauthorized"}), 401 |
|
|
|
|
|
headers = { |
|
"Authorization": f"Bearer {API_KEY}", |
|
"Content-Type": "application/json" |
|
} |
|
data = request.get_json() |
|
response = requests.post(f"{BASE_URL}/{endpoint}", headers=headers, json=data) |
|
|
|
|
|
return jsonify(response.json()), response.status_code |
|
|
|
if __name__ == "__main__": |
|
app.run(host="0.0.0.0", port=5000) |
|
|