A REST API service for applying artistic styles to images using AI models via Replicate.
This service transforms images by applying artistic styles based on text prompts. It uses advanced AI models to generate stylized versions of your input images while maintaining the original content structure.
- Docker (for deployment)
- Replicate API token
REPLICATE_API_TOKEN=your_replicate_token_heredocker build -t ai-style-service .
docker run -p 80:80 -e REPLICATE_API_TOKEN=your_token ai-style-serviceTransforms an input image by applying an artistic style based on a text prompt using the standard model.
POST /api/styleContent-Type: multipart/form-data
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
file |
file | β | - | Input image file (JPEG, PNG, WebP) |
prompt |
string | β | - | Style description (e.g., "anime style", "oil painting") |
negative_prompt |
string | β | Auto-generated | What to avoid in the output |
strength |
float | β | 0.5 |
Style application strength (0.0-1.0) |
inference_steps |
integer | β | 30 |
Number of denoising steps (1-100) |
guidance_scale |
float | β | 7.5 |
How closely to follow the prompt (1.0-20.0) |
seed |
integer | β | Random | Random seed for reproducible results |
Transforms an input image using the Flux model with aspect ratio control and faster processing.
POST /api/style-fluxContent-Type: multipart/form-data
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
file |
file | β | - | Input image file (JPEG, PNG, WebP) |
prompt |
string | β | - | Style transformation description (e.g., "Make this a 90s cartoon") |
aspect_ratio |
string | β | 16:9 |
Output aspect ratio (e.g., "16:9", "1:1", "9:16", "4:3", "3:4" or "match_input_image") |
- file: Maximum recommended size 1024x1024px for Flux (higher than standard for better quality)
- prompt: Describe the desired transformation or style
- aspect_ratio: Controls the output image dimensions. Format: "width:height"
Success (200 OK)
Content-Type: image/jpeg
Content-Length: [file_size]
[Binary image data]Error Responses
// 400 Bad Request
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "Bad Request",
"status": 400,
"detail": "`file` and `prompt` are required"
}
// 500 Internal Server Error
{
"type": "https://tools.ietf.org/html/rfc7231#section-6.6.1",
"title": "Internal Server Error",
"status": 500,
"detail": "Prediction timed out after 180 seconds. The model may be experiencing high demand."
}curl -X POST http://localhost/api/style \
-F "[email protected]" \
-F "prompt=anime style" \
-o styled_output.jpgcurl -X POST http://localhost/api/style-flux \
-F "[email protected]" \
-F "prompt=Make this a 90s cartoon" \
-F "aspect_ratio=16:9" \
-o flux_styled_output.jpgcurl -X POST http://localhost/api/style \
-F "[email protected]" \
-F "prompt=impressionist oil painting in the style of Monet" \
-F "negative_prompt=blurry, low quality, distorted" \
-F "strength=0.7" \
-F "inference_steps=40" \
-F "guidance_scale=8.0" \
-F "seed=12345" \
-o monet_landscape.jpgconst formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('prompt', 'watercolor painting');
formData.append('strength', '0.6');
const response = await fetch('/api/style', {
method: 'POST',
body: formData
});
if (response.ok) {
const blob = await response.blob();
const imageUrl = URL.createObjectURL(blob);
// Use imageUrl to display the result
} else {
const error = await response.json();
console.error('Error:', error.detail);
}const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('prompt', 'Make this a 90s cartoon');
formData.append('aspect_ratio', '1:1');
const response = await fetch('/api/style-flux', {
method: 'POST',
body: formData
});
if (response.ok) {
const blob = await response.blob();
const imageUrl = URL.createObjectURL(blob);
// Use imageUrl to display the result
} else {
const error = await response.json();
console.error('Error:', error.detail);
}import requests
url = 'http://localhost/api/style'
files = {'file': open('input.jpg', 'rb')}
data = {
'prompt': 'cyberpunk digital art',
'strength': 0.8,
'inference_steps': 35,
'seed': 42
}
response = requests.post(url, files=files, data=data)
if response.status_code == 200:
with open('output.jpg', 'wb') as f:
f.write(response.content)
else:
print(f"Error: {response.json()}")import requests
url = 'http://localhost/api/style-flux'
files = {'file': open('input.jpg', 'rb')}
data = {
'prompt': 'Make this a 90s cartoon',
'aspect_ratio': '16:9'
}
response = requests.post(url, files=files, data=data)
if response.status_code == 200:
with open('flux_output.jpg', 'wb') as f:
f.write(response.content)
else:
print(f"Error: {response.json()}")- Best for: Fine-tuned artistic styles with precise control
- Parameters: Strength, inference steps, guidance scale, negative prompts, seed
- Use cases: Traditional art styles, detailed customization, reproducible results
- Processing time: 30-60 seconds
- Model: Stable Diffusion based
- Best for: Modern transformations and cartoon styles
- Parameters: Aspect ratio control, simplified interface
- Use cases: Cartoon conversion, modern art styles, aspect ratio changes
- Processing time: 20-40 seconds
- Model: Flux Kontext Pro
- Advantages: Faster processing, better cartoon/modern styles, aspect ratio control
- Use Flux model (
/api/style-flux) for cartoon/modern styles - Use images smaller than 768x768px for standard model
- Use images smaller than 1024x1024px for Flux model
- Reduce
inference_stepsto 20-25 (standard model only) - Use simpler, shorter prompts
- Use standard model (
/api/style) for traditional art styles - Increase
inference_stepsto 40-50 (standard model only) - Use detailed, specific prompts
- Adjust
strengthbased on desired effect (standard model only) - Experiment with different
guidance_scalevalues (standard model only)
| Style | Example Prompt |
|---|---|
| Anime | anime style, cel shading, vibrant colors |
| Oil Painting | oil painting, thick brushstrokes, classical art |
| Watercolor | watercolor painting, soft edges, flowing colors |
| Digital Art | digital art, concept art, detailed illustration |
| Sketch | pencil sketch, black and white, hand drawn |
| Photography | professional photography, cinematic lighting |
| Style | Example Prompt |
|---|---|
| Cartoon | Make this a 90s cartoon |
| Cyberpunk | Transform into cyberpunk style |
| Pixel Art | Convert to pixel art style |
| Comic Book | Make this look like a comic book |
| Vintage | Give this a vintage 80s look |
| Minimalist | Convert to minimalist art style |
| Ratio | Description | Use Case |
|---|---|---|
16:9 |
Widescreen | Landscape, cinematic |
1:1 |
Square | Social media, profile pics |
9:16 |
Vertical | Mobile, stories |
4:3 |
Traditional | Classic photography |
3:4 |
Portrait | Vertical photography |
The service returns standard HTTP status codes:
200- Success400- Bad Request (missing required parameters, invalid aspect ratio)422- Unprocessable Entity (invalid parameter values)500- Internal Server Error (processing failed or timeout)
All error responses follow RFC 7807 Problem Details format.
Processing time varies based on:
- Model choice (Flux is typically faster)
- Image complexity and size
- Model availability (cold start vs warm)
- Current service demand
- Parameter values (steps, guidance scale for standard model)
Typical processing time:
- Standard model: 30-60 seconds per image
- Flux model: 20-40 seconds per image
- Framework: ASP.NET Core 9.0
- Image Processing: SixLabors.ImageSharp
- AI Provider: Replicate API
- Models:
- Standard: Stable Diffusion based model
- Flux: Black Forest Labs Flux Kontext Pro
- Supported Formats: JPEG, PNG, WebP (input), JPEG (output)
- Max Timeout: 180 seconds
FROM mcr.microsoft.com/dotnet/aspnet:9.0
# ... (see Dockerfile for complete configuration)# Required
REPLICATE_API_TOKEN=r8_your_token_here
# Optional
ASPNETCORE_URLS=http://*:80
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false[Your License Here]
For issues and questions:
- Check the error response details
- Verify your Replicate API token
- Ensure image file is valid and not corrupted
- Try reducing image size or complexity
- For Flux model: ensure aspect ratio format is correct ("width:height")