Skip to main content
Version: Next

Image Generation in ASI:One

Generate high-quality images from text descriptions using ASI:One's image generation API. This feature allows you to create custom images based on natural language prompts.


Overview

The image generation API accepts text prompts and returns generated images in various sizes. The API supports different image dimensions and uses advanced AI models to create realistic and creative images.

Endpoint: POST https://api.asi1.ai/v1/image/generate


Quick Start

curl -X POST https://api.asi1.ai/v1/image/generate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ASI_ONE_API_KEY" \
-d '{
"prompt": "A futuristic city skyline at sunset with flying cars",
"size": "1024x1024",
"model": "asi1-mini"
}'

API Reference

Request Parameters

ParameterTypeRequiredDescriptionDefault
promptstringYesText description of the image to generate-
sizestringNoImage dimensions"1024x1024"
modelstringNoImage generation model to use"asi1-mini"

Supported Image Sizes

SizeDescriptionUse Case
1024x1024Square imageGeneral purpose, avatars, icons
1792x1024Landscape imageWallpapers, banners, wide scenes
1024x1792Portrait imageMobile wallpapers, tall scenes

Response Format

The API returns a JSON response containing the generated image as a base64-encoded data URL.

Success Response:

  • Status Code: 200 OK
  • Content-Type: application/json
  • Body: JSON object with image data
{
"status": 1,
"message": "Success",
"created": 1753792957496,
"images": [
{
"url": "data:image/png;base64,iVBORw0KGgoAAA... (truncated)"
}
]
}

Examples

Basic Image Generation

curl -X POST https://api.asi1.ai/v1/image/generate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ASI_ONE_API_KEY" \
-d '{
"prompt": "A serene mountain landscape with snow-capped peaks and a crystal clear lake"
}'

Landscape Image Generation

curl -X POST https://api.asi1.ai/v1/image/generate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ASI_ONE_API_KEY" \
-d '{
"prompt": "A beautiful sunset over the ocean with palm trees silhouetted against the sky",
"size": "1792x1024"
}'

Portrait Image Generation

curl -X POST https://api.asi1.ai/v1/image/generate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ASI_ONE_API_KEY" \
-d '{
"prompt": "A majestic waterfall cascading down a cliff face with mist and rainbows",
"size": "1024x1792"
}'

Error Handling

Common Error Responses

Status CodeError TypeDescription
400Bad RequestInvalid parameters or malformed request
401UnauthorizedInvalid or missing API key
404Not FoundEndpoint not found
500Internal Server ErrorServer-side error

Example Error Response

{
"error": {
"message": "Invalid prompt provided",
"type": "invalid_request_error",
"code": 400
}
}

Best Practices

Writing Effective Prompts

  1. Be Specific: Include details about style, mood, lighting, and composition
  2. Use Descriptive Language: Mention colors, textures, and artistic styles
  3. Specify Perspective: Include camera angles and viewpoints
  4. Add Context: Provide background information and setting details

Example Prompts

CategoryGood PromptPoor Prompt
Landscape"A misty mountain valley at dawn with golden sunlight filtering through pine trees""mountains"
Portrait"A professional headshot of a confident businesswoman in a modern office setting""person"
Abstract"A vibrant abstract painting with swirling colors in the style of Van Gogh""abstract art"

Rate Limiting

  • The API applies rate limits based on your plan
  • Monitor your usage to avoid hitting limits
  • Implement exponential backoff for retries

Image Quality Tips

  1. Use High-Resolution Sizes: Choose larger sizes for better quality
  2. Provide Detailed Prompts: More specific prompts yield better results
  3. Experiment with Different Models: Try different models for various styles
  4. Consider Aspect Ratios: Choose appropriate sizes for your use case

Integration Examples

Web Application Integration

// Frontend image generation with loading states
async function generateImageWithUI(prompt) {
const loadingElement = document.getElementById('loading');
const resultElement = document.getElementById('result');

try {
loadingElement.textContent = 'Generating image...';

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

const result = await response.json();

if (result.images && result.images[0]) {
const img = document.createElement('img');
img.src = result.images[0].url;
img.alt = prompt;
resultElement.appendChild(img);
}
} catch (error) {
console.error('Error generating image:', error);
} finally {
loadingElement.textContent = '';
}
}

Batch Image Generation

import asyncio
import aiohttp

async def generate_multiple_images(prompts):
API_KEY = os.getenv("ASI_ONE_API_KEY")
headers = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}

async with aiohttp.ClientSession() as session:
tasks = []
for prompt in prompts:
payload = {"prompt": prompt, "size": "1024x1024"}
task = session.post(
"https://api.asi1.ai/v1/image/generate",
headers=headers,
json=payload
)
tasks.append(task)

responses = await asyncio.gather(*tasks)
return [await resp.json() for resp in responses]

# Generate multiple images concurrently
prompts = [
"A cyberpunk city street at night",
"A peaceful forest clearing with sunlight",
"A futuristic spaceship in orbit"
]

results = await generate_multiple_images(prompts)
for i, result in enumerate(results):
print(f"Image {i+1}: {result['images'][0]['url']}")