ListenHubOpenAPI
API Reference

Image Generation

Generate AI images from text prompts via API, with optional reference images provided as URLs or base64-encoded inline data.

Generate Image

POST /v1/images/generation

Generate an AI image from a text prompt. Optionally supply reference images to guide the style or content of the output. The response streams the raw model output (JSON containing base64 image data).

Basic Generation

curl -X POST "https://api.marswave.ai/openapi/v1/images/generation" \
  -H "Authorization: Bearer $LISTENHUB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "google",
    "prompt": "A serene mountain landscape at sunset with a reflective lake",
    "imageConfig": {
      "aspectRatio": "16:9",
      "imageSize": "2K"
    }
  }'
const response = await fetch('https://api.marswave.ai/openapi/v1/images/generation', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.LISTENHUB_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    provider: 'google',
    prompt: 'A serene mountain landscape at sunset with a reflective lake',
    imageConfig: {
      aspectRatio: '16:9',
      imageSize: '2K',
    },
  }),
});
const data = await response.json();
// data.candidates[0].content.parts[0].inlineData contains the generated image
import os
import requests

response = requests.post(
    'https://api.marswave.ai/openapi/v1/images/generation',
    headers={'Authorization': f'Bearer {os.environ["LISTENHUB_API_KEY"]}'},
    json={
        'provider': 'google',
        'prompt': 'A serene mountain landscape at sunset with a reflective lake',
        'imageConfig': {
            'aspectRatio': '16:9',
            'imageSize': '2K',
        },
    }
)
data = response.json()
# data['candidates'][0]['content']['parts'][0]['inlineData'] contains the generated image

To use GPT-Image-2, set provider to "openai" and model to "gpt-image-2". The request and response format is the same — only provider, model, and the imageConfig differ. See the Model Comparison table for details.


Generation with Reference Images

Supply reference images to guide the output. Each reference image can be provided as either a URL (fileData) or base64-encoded inline data (inlineData). You can mix both formats in a single request.

Using Image URLs

curl -X POST "https://api.marswave.ai/openapi/v1/images/generation" \
  -H "Authorization: Bearer $LISTENHUB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "google",
    "prompt": "Transform this scene into a watercolor painting style",
    "referenceImages": [
      {
        "fileData": {
          "fileUri": "https://example.com/my-photo.jpg",
          "mimeType": "image/jpeg"
        }
      }
    ],
    "imageConfig": {
      "aspectRatio": "1:1",
      "imageSize": "2K"
    }
  }'
const response = await fetch('https://api.marswave.ai/openapi/v1/images/generation', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.LISTENHUB_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    provider: 'google',
    prompt: 'Transform this scene into a watercolor painting style',
    referenceImages: [
      {
        fileData: {
          fileUri: 'https://example.com/my-photo.jpg',
          mimeType: 'image/jpeg',
        },
      },
    ],
    imageConfig: {
      aspectRatio: '1:1',
      imageSize: '2K',
    },
  }),
});
const data = await response.json();
import os
import requests

response = requests.post(
    'https://api.marswave.ai/openapi/v1/images/generation',
    headers={'Authorization': f'Bearer {os.environ["LISTENHUB_API_KEY"]}'},
    json={
        'provider': 'google',
        'prompt': 'Transform this scene into a watercolor painting style',
        'referenceImages': [
            {
                'fileData': {
                    'fileUri': 'https://example.com/my-photo.jpg',
                    'mimeType': 'image/jpeg',
                }
            }
        ],
        'imageConfig': {
            'aspectRatio': '1:1',
            'imageSize': '2K',
        },
    }
)
data = response.json()

Using Base64 Inline Data

curl -X POST "https://api.marswave.ai/openapi/v1/images/generation" \
  -H "Authorization: Bearer $LISTENHUB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "google",
    "prompt": "Create a cartoon version of this portrait",
    "referenceImages": [
      {
        "inlineData": {
          "data": "<BASE64_ENCODED_IMAGE>",
          "mimeType": "image/png"
        }
      }
    ]
  }'
import { readFileSync } from 'fs';

const imageBase64 = readFileSync('reference.png').toString('base64');

const response = await fetch('https://api.marswave.ai/openapi/v1/images/generation', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.LISTENHUB_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    provider: 'google',
    prompt: 'Create a cartoon version of this portrait',
    referenceImages: [
      {
        inlineData: {
          data: imageBase64,
          mimeType: 'image/png',
        },
      },
    ],
  }),
});
const data = await response.json();
import os
import base64
import requests

with open('reference.png', 'rb') as f:
    image_base64 = base64.b64encode(f.read()).decode('utf-8')

response = requests.post(
    'https://api.marswave.ai/openapi/v1/images/generation',
    headers={'Authorization': f'Bearer {os.environ["LISTENHUB_API_KEY"]}'},
    json={
        'provider': 'google',
        'prompt': 'Create a cartoon version of this portrait',
        'referenceImages': [
            {
                'inlineData': {
                    'data': image_base64,
                    'mimeType': 'image/png',
                }
            }
        ],
    }
)
data = response.json()

Request Parameters

FieldTypeRequiredDescription
providerstringYesModel provider: google or openai
modelstringNoModel name: gemini-3-pro-image-preview (default), gemini-3.1-flash-image-preview, or gpt-image-2 (requires provider: "openai")
promptstringYesText description of the image to generate
referenceImagesarrayNoReference images to guide generation. Max 14 for Gemini models, max 4 for GPT-Image-2
referenceImages[].fileDataobjectNoReference image as a URL
referenceImages[].fileData.fileUristringYesImage URL (http, https, or gs scheme)
referenceImages[].fileData.mimeTypestringYesMIME type: image/png, image/jpeg, image/webp, image/heic, or image/heif
referenceImages[].inlineDataobjectNoReference image as base64-encoded data
referenceImages[].inlineData.datastringYesBase64-encoded image data
referenceImages[].inlineData.mimeTypestringYesMIME type: image/png, image/jpeg, image/webp, image/heic, or image/heif
imageConfigobjectNoImage output configuration
imageConfig.imageSizestringNoOutput resolution: 1K, 2K (default), or 4K. For GPT-Image-2 credit costs see the Image Size Tiers table
imageConfig.aspectRatiostringNoAspect ratio (see table below). Optional for GPT-Image-2 — omit to let the model choose automatically

Each item in referenceImages must contain exactly one of fileData or inlineData, not both.

Supported Aspect Ratios

RatioDescription
1:1Square
2:3Portrait
3:2Landscape
3:4Portrait
4:3Landscape
9:16Vertical / mobile
16:9Widescreen
21:9Ultra-wide

The gemini-3.1-flash-image-preview model supports additional aspect ratios (1:4, 4:1, 1:8, 8:1) that are not available with the default gemini-3-pro-image-preview model.

Image Size Tiers

GPT-Image-2 uses a tiered credit system based on output resolution:

SizeTierCreditsFree Trial
1KStandard4Yes (100 uses per user)
2KHD6Yes (100 uses per user)
4KUltra HD10No

Model Comparison

ModelStrengthsNotes
gemini-3-pro-image-previewHigher quality, more detailed outputDefault model
gemini-3.1-flash-image-previewFaster generation, supports extra aspect ratiosGood for iterative workflows
gpt-image-2OpenAI's latest image model, strong prompt followingMax 4 reference images, supports all standard aspect ratios, aspectRatio is optional (auto mode)

Response

The response streams the raw model output as JSON. A successful response contains the generated image as base64 data:

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": "<BASE64_ENCODED_IMAGE>"
            }
          }
        ]
      }
    }
  ]
}

Decode the data field from base64 to obtain the image file.


Rate Limiting and Reference Image Mode

Standard text-to-image requests are subject to per-user and global rate limits.

Reference image mode (referenceImages with inlineData) is subject to additional server-side resource constraints. During peak usage periods, requests may be throttled more aggressively. If you receive a 429 Too Many Requests response, wait a short period before retrying. We recommend implementing exponential backoff in your client.

Error Codes

HTTP StatusMeaning
400Invalid request parameters (e.g., unsupported aspect ratio for the selected model)
402Insufficient credits
429Rate limit exceeded — retry after a short wait
500Image generation failed — retry the request

On this page