Skip to main content

Image generation

Generate images from text prompts using Azerion Intelligence models.

Endpoint:

POST https://api.azerion.ai/v1/images/generations

Description

This endpoint generates images from text descriptions. It allows you to create high-quality images by providing detailed text prompts that describe what you want to see in the generated image.

Authentication

This endpoint requires authentication using an API key.

Request

{
"model": "stable-image-core-1.1",
"prompt": "cat",
"style": "vivid",
"response_format": "b64_json"
}

Request Parameters

  • model (string, required): ID of the model to use for image generation. You can use the List Models endpoint to see available models.
  • prompt (string, required): A text description of the desired image. The more detailed and specific the prompt, the better the generated image will match your vision. Maximum length is 4000 characters.
Writing Effective Prompts

For best results, be specific and descriptive in your prompts. Include details about style, lighting, composition, and any specific elements you want in the image. For example, instead of "a cat", try "a fluffy orange tabby cat sitting on a wooden windowsill with soft morning sunlight streaming through lace curtains".

Response

A successful request returns a 200 OK status code with a JSON response body.

Standard Response

{
"created": 1753000843,
"data": [
{
"b64_json": "/9j/4AAQS etc..."
}
],
"usage": {
"input_tokens": 0,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
},
"output_tokens": 0,
"total_tokens": 0
}
}

Response Fields

  • created (integer): Unix timestamp of when the image was created.
  • data (array): An array of generated image objects.
    • url (string): The URL of the generated image (when response_format is "url").
    • b64_json (string): The base64-encoded JSON of the generated image (when response_format is "b64_json").
    • revised_prompt (string): The prompt that was used to generate the image, if there were any revisions to the original prompt.
  • usage (object): Usage statistics for the request.
    • input_tokens (integer): Number of input tokens used.
    • input_tokens_details (object): Breakdown of input token usage.
      • image_tokens (integer): Number of tokens used for image processing.
      • text_tokens (integer): Number of tokens used for text processing.
    • output_tokens (integer): Number of output tokens generated.
    • total_tokens (integer): Total number of tokens used (input + output).

Response with Base64 Format

When response_format is set to "b64_json":

{
"created": 1753000843,
"data": [
{
"b64_json": "/9j/4AAQS etc..."
}
],
"usage": {
"input_tokens": 0,
"input_tokens_details": {
"image_tokens": 0,
"text_tokens": 0
},
"output_tokens": 0,
"total_tokens": 0
}
}

Example Request (cURL)

curl https://api.azerion.ai/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"model": "stable-image-core-1.1",
"prompt": "cat",
"style": "vivid",
"response_format": "b64_json"
}'
Replace Placeholder

Replace YOUR_ACCESS_TOKEN with your actual API key or access token. Refer to the Authentication guide for details on obtaining and using your credentials.

Example Request (Python)

import requests
import os

api_key = os.environ.get("AZERION_API_KEY") # Or AZERION_ACCESS_TOKEN
url = "https://api.azerion.ai/v1/images/generations" # Replace with your actual base URL if different

headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}

data = {
"model": "stable-image-core-1.1",
"prompt": "cat",
"style": "vivid",
"response_format": "b64_json"
}

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

# Get the base64 image data
image_data = result['data'][0]['b64_json']
print(f"Generated image data: {image_data[:50]}...") # Print first 50 characters
print(f"Usage: {result['usage']}")

Example Request (Node.js)

const fetch = require('node-fetch');

const apiKey = process.env.AZERION_API_KEY; // Or AZERION_ACCESS_TOKEN
const url = 'https://api.azerion.ai/v1/images/generations'; // Replace with your actual base URL if different

const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
};

const data = {
model: 'stable-image-core-1.1',
prompt: 'cat',
style: 'vivid',
response_format: 'b64_json'
};

fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
})
.then(response => response.json())
.then(result => {
const imageData = result.data[0].b64_json;
console.log('Generated image data:', imageData.substring(0, 50) + '...');
console.log('Usage:', result.usage);
})
.catch(error => console.error('Error:', error));