Skip to main content

Universal AI: Image Features

Process and analyze images using the Universal AI endpoint.

Available Image Features

SubfeatureModel String PatternDescription
Generationimage/generation/provider/modelCreate AI-generated images
Object Detectionimage/object_detection/providerIdentify objects in images
Face Detectionimage/face_detection/providerDetect faces in images
Face Comparisonimage/face_comparison/providerCompare face similarity
Background Removalimage/background_removal/providerRemove image backgrounds
Explicit Content Detectionimage/explicit_content/providerDetect NSFW content
AI Detectionimage/ai_detection/providerDetect AI-generated images

Image Generation

Generate images from text descriptions:
import requests

url = "https://api.edenai.run/v3/universal-ai"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}

payload = {
    "model": "image/generation/openai/dall-e-3",
    "input": {
        "text": "A serene mountain landscape at sunset with a crystal clear lake",
        "resolution": "1024x1024",
        "num_images": 1
    }
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()

image_url = result["output"]["items"][0]["image_url"]
print(f"Generated image: {image_url}")

Object Detection

Detect and identify objects in images:
import requests
# Upload image
upload_url = "https://api.edenai.run/v3/upload"
upload_headers = {"Authorization": "Bearer YOUR_API_KEY"}
    
files = {"file": open("photo.jpg", "rb")}
upload_response = requests.post(upload_url, headers=upload_headers, files=files)
file_id = upload_response.json()["file_id"]

# Detect objects
payload = {
    "model": "image/object_detection/google",
    "input": {
        "file": file_id
    }
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()

for obj in result["output"]["items"]:
    print(f"Object: {obj['label']} (confidence: {obj['confidence']})")

Face Detection

Detect faces and facial attributes:
import requests
# Upload image
files = {"file": open("people.jpg", "rb")}
upload_response = requests.post(upload_url, headers=upload_headers, files=files)
file_id = upload_response.json()["file_id"]

# Detect faces
payload = {
    "model": "image/face_detection/amazon",
    "input": {
        "file": file_id
    }
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()

for face in result["output"]["items"]:
    print(f"Face detected at: {face['bounding_box']}")
    print(f"  Age: {face.get('age')}")
    print(f"  Gender: {face.get('gender')}")
    print(f"  Emotions: {face.get('emotions')}")

Background Removal

Remove backgrounds from images:
import requests
# Upload image
files = {"file": open("product.jpg", "rb")}
upload_response = requests.post(upload_url, headers=upload_headers, files=files)
file_id = upload_response.json()["file_id"]

# Remove background
payload = {
    "model": "image/background_removal/photoroom",
    "input": {
        "file": file_id
    }
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()

# Download the result
processed_url = result["output"]["image_url"]
print(f"Background removed image: {processed_url}")

Using Image URLs

You can also provide image URLs instead of uploading:
import requests
payload = {
    "model": "image/object_detection/google",
    "input": {
        "file": "https://example.com/image.jpg"
    }
}

response = requests.post(url, headers=headers, json=payload)
result = response.json()

Next Steps