---
updatedAt: 2025-11-26T00:46:23.000Z
agentTools:
  projectIndex: https://docs.exh.ai/llms.txt
---

# Animate Image

```python Python
import requests
import base64
import time

# API Configuration
YOUR_API_KEY = "YOUR TOKEN HERE"
API_URL = "https://api.exh.ai/animations/v3/jobs"

# Animation settings
image_path = "test.jpg"
prompt = "She smiling, looking to camera."

# Convert image to base64
print("Reading and encoding image...")
with open(image_path, "rb") as image_file:
    image_b64 = base64.b64encode(image_file.read()).decode('utf-8')

# Prepare request
payload = {
    "animation_model": "basic",
    "duration": 5,
    "image_b64": image_b64,
    "prompt": prompt
}

headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "authorization": f"Bearer {YOUR_API_KEY}"
}

# Send animation request
print("Sending animation request...")
response = requests.post(API_URL, json=payload, headers=headers)
task_id = response.json()["task_id"]
print(f"Animation task created. Task ID: {task_id}")

# Poll for result (max 5 minutes)
print("Waiting for animation to complete...")
start_time = time.time()
max_wait_time = 5 * 60  # 5 minutes

while time.time() - start_time < max_wait_time:
    time.sleep(1)
    status_response = requests.get(f"{API_URL}/{task_id}", headers=headers)
    status_data = status_response.json()
    elapsed_time = int(time.time() - start_time)
    
    if status_data["status"] == "completed":
        video_url = status_data["video_url"]
        print(f"✅ Animation ready! Time taken: {elapsed_time} seconds")
        print(f"Download your video: {video_url}")
        break
    elif status_data["status"] == "error":
        print(f"❌ Error: {status_data.get('error_message', 'Unknown error')}")
        break
    else:
        print(f"⏳ Still processing... (Status: {status_data['status']}, Time: {elapsed_time}s)")
else:
    print("❌ Timeout: Animation took too long to complete")
```

# Set Configuration

<!-- python@6-12 -->



# Convert image to base64

<!-- python@13-17 -->



# Make request

<!-- python@18-36 -->



# Poll for result

<!-- python@38-60 -->