Code Examples
Ready-to-use examples for integrating the SmileGeni 2D API in various programming languages. Replace YOUR_API_KEY with your actual API key in all examples.
Base URL
All examples use the production endpoint: https://eu.api.smilegeni.ai
Default Enhancement
Basic image processing using the default enhancement workflow (AI face restoration with sharpening):
1curl -X POST "https://eu.api.smilegeni.ai/process_image" \
2 -H "Authorization: Bearer YOUR_API_KEY" \
3 -F "image=@photo.jpg" \
4 -F "AI-Strength=3" \
5 --output result.jpg
Enhancement with Whitening
Full processing pipeline with both enhancement and teeth whitening enabled:
1curl -X POST "https://eu.api.smilegeni.ai/process_image" \
2 -H "Authorization: Bearer YOUR_API_KEY" \
3 -F "image=@photo.jpg" \
4 -F "AI-Strength=3" \
5 -F "enhancement=true" \
6 -F "whitening=true" \
7 --output result.jpg
Whitening Only
Apply teeth whitening without the enhancement pipeline:
1curl -X POST "https://eu.api.smilegeni.ai/process_image" \
2 -H "Authorization: Bearer YOUR_API_KEY" \
3 -F "image=@photo.jpg" \
4 -F "enhancement=false" \
5 -F "whitening=true" \
6 -F "whitening_strength=0.9" \
7 --output result.jpg
Custom Whitening Parameters
Fine-tune whitening with custom strength, brightness, and yellow reduction:
1curl -X POST "https://eu.api.smilegeni.ai/process_image" \
2 -H "Authorization: Bearer YOUR_API_KEY" \
3 -F "image=@photo.jpg" \
4 -F "whitening=true" \
5 -F "whitening_strength=0.7" \
6 -F "whitening_brightness_boost=1.3" \
7 -F "whitening_yellow_reduction=0.6" \
8 --output result.jpg
Error Handling
A robust integration should handle errors gracefully. Here is a comprehensive example with retry logic:
1import requests
2import time
3
4API_KEY = "YOUR_API_KEY"
5BASE_URL = "https://eu.api.smilegeni.ai"
6
7def process_with_retry(image_path, max_retries=3, **params):
8 """Process an image with automatic retry on failure."""
9 headers = {"Authorization": f"Bearer {API_KEY}"}
10
11 for attempt in range(max_retries):
12 try:
13 with open(image_path, "rb") as img:
14 files = {"image": img}
15 response = requests.post(
16 f"{BASE_URL}/process_image",
17 headers=headers,
18 files=files,
19 data=params,
20 timeout=60,
21 )
22
23 if response.status_code == 200:
24 return response.content
25
26 if response.status_code == 429:
27 wait = 2 ** attempt
28 print(f"Rate limited. Retrying in {wait}s...")
29 time.sleep(wait)
30 continue
31
32 if response.status_code == 401:
33 raise Exception("Invalid API key")
34
35 response.raise_for_status()
36
37 except requests.exceptions.Timeout:
38 if attempt < max_retries - 1:
39 print(f"Timeout. Retrying ({attempt + 1}/{max_retries})...")
40 continue
41 raise
42
43 raise Exception("Max retries exceeded")
44
45# Usage
46try:
47 result = process_with_retry(
48 "photo.jpg",
49 max_retries=3,
50 **{"AI-Strength": "3", "whitening": "true"},
51 )
52 with open("result.jpg", "wb") as f:
53 f.write(result)
54 print("Success!")
55except Exception as e:
56 print(f"Error: {e}")