A Symfony-based microservice for generating images from text prompts using OpenAI's DALL-E model.
- Generate images from text descriptions
- Input validation and error handling
- Standardized JSON response format
- Type-safe DTOs and responses
- RESTful API endpoint
- PHP 8.2 or higher
- Symfony 7.2
- OpenAI API key
- Composer
- Clone the repository:
git clone https://github.com/Dovbenko/symfony-microservices.git
cd symfony-microservices
- Install dependencies:
composer install
- Configure environment variables:
Edit .env
and set your OpenAI API key:
APP_OPENAI_API_KEY=your_api_key_here
Generates an image from a text prompt using DALL-E.
Endpoint: POST /api/generate-image
Content-Type: application/json
Request Body:
{
"prompt": "A serene landscape with mountains and a lake at sunset"
}
Success Response:
{
"status": "success",
"data": {
"image_url": "https://example.com/generated-image.jpg"
}
}
Error Response:
{
"status": "error",
"message": "Error message here"
}
Validation Rules:
- Prompt must be between 3 and 1000 characters
- Prompt cannot be empty
- Content-Type must be application/json
src/
├── Controller/
│ └── ImageController.php # Handles image generation requests
├── DTO/
│ └── Prompt.php # Data Transfer Object for prompts
├── Response/
│ └── JsonResponse.php # Standardized JSON response format
└── Service/
└── GenerationImage.php # Handles image generation logic
└── GenerationChat.php # Handles chat generation logic
The service provides standardized error responses with appropriate HTTP status codes:
- 400 Bad Request: Invalid input or validation errors
- 500 Internal Server Error: Server-side errors or API failures
- API key is stored in environment variables
- Input validation to prevent malicious requests
- Content-Type validation
- Error messages are sanitized
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request