AVATAR API Endpoint

Version 2.197 (Release Notes ↗)

Description

Generate a 100x75px thumbnail perfectly suited to use as avatar. This API endpoint is a just wrapper around thumbnail with width & height set respectively to 100 and 75.

HTTP Methods

GET, POST

HTTP Parameters

Required

Fields Type Description
img URL Input media URL. If uploading directly from your app, submit a multipart/form-data POST request.
key String Your PixLab API Key ↗. Alternatively, embed it in the WWW-Authenticate: header and omit this parameter.

Optional

Fields Type Description
blob Boolean Returns JSON with output image link by default. Set to true to receive binary media content instead.

POST Request Body

This section details the requirements for using a POST request instead of a simple GET request.

Allowed Content-Types:

multipart/form-data
application/json

Use multipart/form-data for direct file uploads (see examples). For JSON, ensure the media is already hosted elsewhere. Upload images via store before invoking this endpoint if needed.

HTTP Response

Fields Type Description
status Integer Status code 200 indicates success, any other code indicates failure.
link URL Link to the image output which is usually stored on the pixlab.xyz storage server unless you set your own S3 keys (refer to your dashboard ↗ on how to do that).
id String Unique media ID.
error String Error message if status != 200.

The endpoint returns application/json if the optional blob parameter is not set.

This API endpoint returns a JSON Object after each call only if the optional blob parameter is omitted. Otherwise, the image binary content is returned directly. The JSON response contains the following fields:

Code Samples


import requests


def generate_avatar(image_url: str, api_key: str) -> str:
    """Generate an avatar from an image using PixLab API.
    
    Args:
        image_url: URL of the source image
        api_key: PixLab API key
        
    Returns:
        URL of the generated avatar
        
    Raises:
        requests.exceptions.RequestException: If API request fails
        ValueError: If API returns an error
    """
    try:
        response = requests.get(
            'https://api.pixlab.io/avatar',
            params={
                'img': image_url,
                'key': api_key
            },
            timeout=10
        )
        response.raise_for_status()
        data = response.json()
        
        if data.get('status') != 200:
            raise ValueError(data.get('error', 'Unknown error from API'))
            
        return data['link']
        
    except requests.exceptions.RequestException as e:
        raise requests.exceptions.RequestException(f"API request failed: {e}")
    except json.JSONDecodeError:
        raise ValueError("Invalid JSON response from API")


if __name__ == "__main__":
    try:
        avatar_url = generate_avatar(
            image_url='http://www.drodd.com/images15/nature31.jpg',
            api_key='My_PIXLAB_API_KEY'
        )
        print(f"Avatar location: {avatar_url}")
    except Exception as e:
        print(f"Error generating avatar: {e}")
← Return to API Endpoint Listing