Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
@app.route('/proxy/anthropic', methods=['POST'])
|
| 7 |
+
def proxy():
|
| 8 |
+
api_key = request.headers.get('x-api-key')
|
| 9 |
+
|
| 10 |
+
response = requests.post(
|
| 11 |
+
'https://api.anthropic.com/v1/messages',
|
| 12 |
+
headers={
|
| 13 |
+
'Content-Type': 'application/json',
|
| 14 |
+
'x-api-key': api_key,
|
| 15 |
+
'anthropic-version': '2024-01-01'
|
| 16 |
+
},
|
| 17 |
+
json=request.json
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
return jsonify(response.json()), response.status_code
|
| 21 |
+
|
| 22 |
+
if __name__ == '__main__':
|
| 23 |
+
app.run(host='0.0.0.0', port=7860)
|