A lightweight, modern AI chatbot built with PHP and powered by the OpenAI API. Create your own AI assistant with a responsive chat interface, conversation memory, and simple deployment.
- 🤖 AI-powered conversations using OpenAI API
- 💬 Modern ChatGPT-inspired chat interface
- 🧠 Session-based conversation memory
- 📱 Responsive mobile-friendly design
- ⚡ Lightweight PHP backend
- 🔄 Start a new conversation anytime
- 🌐 Supports multiple languages
- 🎨 Modern dark-themed UI
- 🔐 Server-side API key configuration
- 🚀 Easy installation and deployment
| Technology | Purpose |
|---|---|
| PHP 8.2+ | Backend |
| OpenAI API | AI responses |
| HTML5 | Structure |
| CSS3 | Interface design |
| JavaScript | Chat functionality |
| PHP Sessions | Conversation history |
Before installation, make sure you have:
- PHP 8.2 or newer
- PHP cURL extension enabled
- OpenAI API key
- Web hosting with PHP support
git clone https://github.com/Mojib-rsm/ai-agent.gitcd php-ai-agentSet the following environment variables on your server:
OPENAI_API_KEY=your_openai_api_key
OPENAI_MODEL=gpt-4.1-miniNever expose your API key in frontend JavaScript or commit it to GitHub.
php -S localhost:8000http://localhost:8000
Your AI Agent is ready!
You can customize the AI model through the environment variable:
OPENAI_MODEL=gpt-4.1-miniThe default assistant instruction is:
You are a helpful, accurate AI assistant.
Respond in the language used by the user.
You can customize this instruction inside index.php.
php-ai-agent/
│
├── index.php
├── README.md
├── LICENSE
└── .gitignore
- Keep your OpenAI API key private.
- Use server-side environment variables.
- Add authentication before public deployment.
- Implement rate limiting to prevent API abuse.
- Add CSRF protection for production environments.
- Monitor API usage and costs.
PHP AI Agent, PHP AI Chatbot, OpenAI PHP Integration, PHP Chatbot Source Code, AI Assistant PHP, OpenAI API Chatbot, Lightweight AI Chatbot, PHP Artificial Intelligence.
- OpenAI API integration
- Responsive chat interface
- Session-based conversation memory
- New chat functionality
- User authentication
- MySQL conversation storage
- Admin dashboard
- File upload and document analysis
- Web search integration
- AI tool calling
- Multiple AI models
Contributions, suggestions, and improvements are welcome!
- Fork this repository.
- Create a new branch.
- Make your changes.
- Submit a pull request.
This project is intended to use the MIT License. Add a LICENSE file before publishing under that license.
Mojib Rsm
- GitHub: @Moiib-Rsm
⭐ If you find this project useful, consider giving it a star!
Built with ❤️ using PHP and OpenAI API.