A lightweight, simple Python and Flask backend designed to handle OpenAI chat completions. This project is built for seamless "one-click" deployment on Render and serves as a flexible API endpoint for any custom frontend wrapper (whether built in TypeScript, HTML/JavaScript, or any other client framework).
- Simple API: Exposes a single
/chatPOST endpoint to process messaging arrays and handle conversation history. - OpenAI Integration: Utilizes the OpenAI Python SDK (v1.x) to generate responses via modern LLMs.
- CORS Enabled: Cross-Origin Resource Sharing is enabled globally, allowing frontend clients to communicate directly with the API without browser restrictions.
- Easily Customizable: Core AI behavior and model selection are controlled entirely via environment variables, requiring no code changes to update the bot's persona.
This backend is specifically designed as a one-click deployment for Render. Local development environments are not officially tested or supported.
-
Fork this repository to your GitHub account.
-
Connect the forked repository to Render.
-
The included
render.yamlconfiguration will automatically handle the build command (pip install -r requirements.txt) and the start command (python main.py). -
Configure Environment Variables in your Render dashboard:
OPENAI_API_KEY: Your required OpenAI API authorization key.SYSTEM_PROMPT: The custom instructions that define the AI's persona and specific job. Example: "You are a company onboarding bot named Atlas. Your job is to assist new hires with navigating HR policies and finding internal documentation."CHAT_MODEL: The specified AI model to utilize. Recommended models includeGPT-5.4-nanoorGPT-5.5, depending on the user's speed and reasoning requirements.
-
Once successfully deployed, Render will provide a live URL. Use this URL as the base for your frontend interface's API calls.
To connect your custom frontend, send a POST request to the /chat endpoint of your live Render URL.
The endpoint expects a JSON payload containing the current user message and an optional history array representing previous conversation turns.
{
"message": "Hello! How can you help me today?",
"history": [
{"sender": "user", "text": "Hi"},
{"sender": "assistant", "text": "Hello! I am ready to assist."}
]
}The server will process the context and return a JSON object containing the AI's generated reply.
{
"reply": "I can help you onboard to the company. What do you need to know?"
}This project is licensed under the MIT License.