Tutorial6 min read
Deploy a Python Flask App with OpenClaw
Build and deploy a Python Flask web app with OpenClaw. Includes async support and health check configuration.
This guide shows how to deploy a Python Flask app with OpenClaw. Flask's simplicity makes it excellent for AI backends.
The Flask App
# app.py
from flask import Flask, jsonify, request
import os
app = Flask(__name__)
@app.get('/health')
def health():
return jsonify({'status': 'ok'})
@app.post('/chat')
def chat():
data = request.get_json()
message = data.get('message')
# OpenClaw handles AI routing
response = openclaw.chat(message)
return jsonify({'response': response})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.getenv('PORT', 3000)))
Dependencies
# requirements.txt
flask==3.0.0
gunicorn==21.2.0
openai==1.3.0
Deploy
fly launch --no-deploy
fly secrets set OPENAI_API_KEY=sk-...
fly deploy
Production Server
Use Gunicorn in production:
gunicorn app:app --bind 0.0.0.0:8080 --workers 2