A simple practice project for building AI-powered API endpoints using Python, FastAPI, and the OpenAI API.
This project exposes several AI endpoints for:
- Text summarization
- Translation
- Title generation
- Code explanation
- Create and activate a Python virtual environment.
- Install dependencies:
pip install -r requirements.txt- Create a
.envfile in the project root with your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key_here- Start the app:
uvicorn app.main:app --reload- Open the API docs in your browser:
http://127.0.0.1:8000/docs
Returns a simple health check message.
Request body:
{
"text": "Long text to summarize...",
"style": "simple"
}Response:
{
"summary": "A concise summary..."
}Request body:
{
"text": "Text to translate...",
"target_language": "French"
}Response:
{
"translation": "Texte traduit..."
}Request body:
{
"text": "Text to generate titles from...",
"count": 5
}Response:
{
"titles": "1. Title idea one\n2. Title idea two..."
}Request body:
{
"code": "print(\"Hello world\")",
"language": "python"
}Response:
{
"explaination": "Explanation of the code..."
}fastapi-ai-api/
│
├── app/
│ ├── main.py
│ ├── openai_service.py
│ └── schemas.py
│
├── .env
├── .gitignore
├── requirements.txt
└── README.md
- The project uses
openaiwith the responses API andgpt-4.1-mini. - Validation is handled by Pydantic models defined in
app/schemas.py. - If you update your
.env, restart the app to apply changes.