home discord bot discord server
Menu

AI API Documentation

Image Generation

Description: After selecting a specific model and sampler, you can generate images using the PopCord API. To do this, you need to make a POST request and provide the necessary parameters.

Request Method and URL

POST     http://popcord.io-i.uk/image/generate

Parameters

Description: All available parameters

Parameter Description Type Constraints
model * Required: The model to be used for generation. string poli can accept only 1024x1024 size
prompt * Required: The text prompt for generation. string
size Optional: The dimensions of the image. string

GET /models

Description: Retrieve available models.

Response:
{
    "success": true,
    "models": 
        [
            "flux", "poli", "sdxl-turbo", "dalle3"
        ]
}

GET /sizes

Description: Retrieve available sizes.

Responses:

Response:
{
    "success": true,
    "sizes": 
        [ 
            "1024x1024", "1024x576", "1024x768", "512x512", "576x1024", "786x1024"
        ]
}

Responses Codes

Description: there is exemples of api responses the endpoint /image/generate

Example Responses:

Successful Response:
{
    "image_url": "https://image.link/image.png"
}
Error Response:
{
    "status_code": XXX
    "detail": [description of the error]
}

Usage Exemples

Description: there is some exemple to use the api

Python:
import aiohttp, asyncio

async def generate_image(api_url, data):
    error = False
    async with aiohttp.ClientSession() as session:
        async with session.post(f"{api_url}image/generate", json=data) as response:
            result = await response.json()
            try:
            	image_url = result["image_url"]
            except:
            	image_url = result["detail"]
            	error = True
            return error, image_url
            
async def main():
    api_url = "https://popcord.io-i.uk/"
    data = {
        'model': "sdxl-turbo",
        'prompt': "Beautiful landscape",
        'size': "1024x576"
    }
    
    error, image_url = await generate_image(api_url, data)
    if error:
    	print(f"Error: {image_url}")
    else:
    	print(f"Image URL: {image_url}")

if __name__ == "__main__":
    asyncio.run(main())
JavaScript:
const fetch = require('node-fetch');

async function generateImage(apiUrl, data) {
    let error = false;
    let imageUrl = '';

    try {
        const response = await fetch(`${apiUrl}image/generate`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(data),
        });

        const result = await response.json();

        if (response.ok) {
            imageUrl = result.image_url;
        } else {
            imageUrl = result.error;
            error = true;
        }
    } catch (err) {
        console.error('Request failed', err);
        error = true;
    }

    return { error, imageUrl };
}

async function main() {
    const apiUrl = "https://popcord.io-i.uk/";
    const data = {
        model: "sdxl-turbo",
        prompt: "Beautiful landscape",
        size: "1024x576"
    };

    const { error, imageUrl } = await generateImage(apiUrl, data);

    if (error) {
        console.log(`Error: ${imageUrl}`);
    } else {
        console.log(`Image URL: ${imageUrl}`);
    }
}

main();