A FastAPI microservice for generating descriptive information from images using AI vision models. Images can either be supplied as file URIs or as file uploads.
- Python 3.10 or higher
- Virtual environment (venv)
cd boxctron-describespython3 -m venv venv
source venv/bin/activate # On macOS/Linux
# or
venv\Scripts\activate # On Windowspip install -r requirements.txtCopy the example environment file and update with your API keys:
cp .env.example .envEdit .env and add your API keys:
AZURE_OPENAI_API_KEY- Your Azure OpenAI API keyAZURE_OPENAI_ENDPOINT- Your Azure OpenAI endpoint URLGOOGLE_API_KEY- (Optional) Google Gemini API keyANTHROPIC_API_KEY- (Optional) Anthropic Claude API key
The service supports hybrid authentication with both API keys and HTTP Basic authentication.
Authentication Settings:
AUTH_ENABLED- Set totrueto enable authentication,falseto disable (default:true)API_KEYS- Comma-separated list of valid API keys for service-to-service communicationAUTH_USERNAME- Username for HTTP Basic authentication (for browser access)AUTH_PASSWORD- Password for HTTP Basic authentication
Generate secure API keys:
python -c "import secrets; print(secrets.token_urlsafe(32))"Example authentication configuration in .env:
# Enable authentication
AUTH_ENABLED=true
# API keys for applications (comma-separated)
API_KEYS=AbCdEf123456_SecureKey1,XyZ789_SecureKey2
# HTTP Basic auth for browser access
AUTH_USERNAME=admin
AUTH_PASSWORD=your-secure-passwordDevelopment/Testing: To disable authentication during development:
AUTH_ENABLED=falsepython main.pyOr using uvicorn directly:
uvicorn main:app --reload --host 0.0.0.0 --port 8000The API will be available at:
- API: http://localhost:8000
- Interactive docs (Swagger UI): http://localhost:8000/docs
- Alternative docs (ReDoc): http://localhost:8000/redoc
uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4GET /healthReturns the health status of the service.
### Upload Endpoint
POST /api/v1/describe/upload
Process an uploaded image file and return descriptive information.
**Parameters:**
- `file` (required): Uploaded image file (multipart/form-data)
- `context` (optional): Additional context to guide description
The filename and MIME type are automatically extracted from the uploaded file.
**Example with cURL (API Key):**
```bash
curl -X POST "http://localhost:8000/api/v1/describe/upload" \
-H "X-API-Key: your-api-key-here" \
-F "file=@/path/to/image.jpg" \
-F "context=Product photo"
Example with cURL (Basic Auth):
curl -X POST "http://localhost:8000/api/v1/describe/upload" \
-u username:password \
-F "file=@/path/to/image.jpg" \
-F "context=Product photo"POST /api/v1/describe/uri
Process an image from a URI (file://, http://, or https://) and return descriptive information.
Parameters:
uri(required): URI to the image filefilename(required): Name of the filemimetype(required): MIME type of the imagecontext(optional): Additional context to guide description
Example with cURL (API Key):
curl -X POST "http://localhost:8000/api/v1/describe/uri" \
-H "X-API-Key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"uri": "https://example.com/image.jpg",
"filename": "image.jpg",
"mimetype": "image/jpeg",
"context": "Product photo"
}'Example with cURL (Basic Auth):
curl -X POST "http://localhost:8000/api/v1/describe/uri" \
-u username:password \
-H "Content-Type: application/json" \
-d '{
"uri": "https://example.com/image.jpg",
"filename": "image.jpg",
"mimetype": "image/jpeg",
"context": "Product photo"
}'# Run all tests
pytest
# Run with coverage report
pytest --cov=app --cov-report=html
# Run specific test file
pytest tests/test_describe.py
# Run with verbose output
pytest -vTest coverage report will be generated in htmlcov/index.html.
Configuration is managed through environment variables using pydantic-settings. Key settings include:
- API Configuration: App name, version, debug mode
- Server Configuration: Host, port
- LLM Provider Keys: Azure OpenAI, Google, Anthropic
- LiteLLM Settings: Model selection, temperature, max tokens
- File Upload Settings: Max size, allowed MIME types
See .env.example for all available configuration options.
See LICENSE for details.