GemPix2 API Documentation

Complete API documentation for GemPix2 Image Generation Service using Google Gemini AI models

Get PriceView GemPix2 pricing plans

GemPix2 API Overview

The GemPix2 Image Generation API provides access to Google Gemini AI models for generating high-quality images from text prompts and reference images. Our GemPix2 service offers a simple RESTful interface with comprehensive task management and callback support.

GemPix2 Key Features

  • GemPix2 text-to-image generation using Google Gemini AI models
  • GemPix2 support for reference images (up to 4 images)
  • GemPix2 asynchronous task processing with status tracking
  • GemPix2 webhook callback support for real-time notifications
  • GemPix2 RESTful API with JSON responses
  • GemPix2 Bearer token authentication

overview.base_url

https://api.defapi.org

overview.api_version

v1.0.0

GemPix2 Getting Started

  1. 1. Sign up for a GemPix2 API key at our production server
  2. 2. Include your GemPix2 API key in the Authorization header
  3. 3. Send a POST request to the GemPix2 image generation endpoint
  4. 4. Use the returned GemPix2 task_id to check generation status
  5. 5. Retrieve your GemPix2 generated images when the task is complete

Authentication

All API requests must be authenticated using Bearer token authentication. Include your API key in the Authorization header of every request.

Authentication Method

Use HTTP Bearer token authentication by including your API key in the Authorization header:

Authorization: Bearer <your-api-key>

Example API Key Format

Authorization: Bearer dk-1234567890abcdef

Request Example

curl -X POST "https://api.defapi.org/api/image/gen" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your-api-key-here" \
  -d '{
    "model": "google/gempix2",
    "prompt": "A beautiful landscape"
  }'

Valid Authentication

  • API key is valid
  • User account is active
  • Sufficient credits available

Common Errors

  • Missing API key
  • Invalid API key format
  • Expired or inactive account

GemPix2 Image Generation API

Generate images using GemPix2 with Google Gemini AI models and customizable prompts and reference images.

Endpoint

POST /api/image/gen

Request Parameters

ParameterTypeRequiredDescription
modelstringYesModel identifier (e.g., "google/gempix2")
promptstringYesText prompt describing the image
imagesarrayNoReference image URLs (max 4)
callback_urlstringNoWebhook URL for completion notifications

Request Examples

Basic GemPix2 Image Generation

{
  "model": "google/gempix2",
  "prompt": "A beautiful girl dancing in a garden"
}

GemPix2 Image-based Generation with Reference Images

{
  "model": "google/gempix2",
  "prompt": "Put them in a basket",
  "images": [
    "https://cdn.openai.com/API/docs/images/body-lotion.png",
    "https://cdn.openai.com/API/docs/images/soap.png"
  ],
  "callback_url": "https://example.com/webhook/image-callback"
}

Response Format

{
  "code": 0,
  "message": "ok",
  "data": {
    "task_id": "ta12345678-1234-1234-1234-123456789abc"
  }
}

Error Responses

400 - Bad Request

{"code": 1, "message": "failed", "detail": "prompt is required"}

401 - Unauthorized

{"code": 1, "message": "Invalid API key"}

GemPix2 Task Query API

Query the status and results of GemPix2 image generation tasks using the task ID returned from the GemPix2 image generation endpoint.

Endpoint

GET /api/task/query?task_id=<task_id>

Query Parameters

ParameterTypeRequiredDescription
task_idstringYesUnique task identifier returned from generation endpoint

Request Example

curl -X GET "https://api.defapi.org/api/task/query?task_id=ta823dfb-eaac-44fd-aec2-3e2c7ba8e071" \
  -H "Authorization: Bearer your-api-key-here"

GemPix2 Task Status Values

pending - GemPix2 task has been created and is waiting to be processed
submitted - GemPix2 task has been submitted to the generation queue
in_progress - GemPix2 task is currently being processed
success - GemPix2 task completed successfully with generated images
failed - GemPix2 task failed due to an error

Error Responses

404 - Task Not Found

{"code": 1, "message": "task not found"}

401 - Unauthorized

{"code": 401, "message": "Invalid API key"}

GemPix2 Data Models

Complete reference for all GemPix2 data models and schemas used in the API responses and requests.

ImageGenResult

Represents a generated image result.

{
  "image": "https://google.datas.systems/fileSystem/response_images/287/2025/08/29/1756432513771985292_2989.png"
}
FieldTypeDescription
imagestringImage URL or base64 data URI

CallbackPayload

Payload sent to the callback_url when task status changes to final states.

{
  "result": [
    {
      "image": "https://google.datas.systems/fileSystem/response_images/287/2025/08/29/1756432513771985292_2989.png"
    }
  ],
  "status": "success",
  "task_id": "ta5c9705-b8ae-4cb9-aa6f-97c4fee88c8d",
  "consumed": "0.500000",
  "status_reason": {
    "message": null
  }
}
FieldTypeDescription
resultarrayArray of ImageGenResult objects (null if failed)
statusstringFinal task status (success/failed)
task_idstringUnique task identifier
consumedstringCredits consumed by the task
status_reasonobjectStatus details including error message if failed

GemPix2 Available Models

google/gempix2Nano Banana image generation model
google/gemini-2.5-flash-imageGemini 2.5 Flash image model

Error Handling

Comprehensive guide to handling errors and understanding API response codes. All error responses follow a consistent format to help you troubleshoot issues effectively.

HTTP Status Codes

200

OK

Request was successful

400

Bad Request

Invalid request parameters or malformed JSON

401

Unauthorized

Invalid, missing, or expired API key

404

Not Found

Task not found or endpoint doesn't exist

500

Internal Server Error

Server-side error occurred

Error Handling Best Practices

  1. 1. Always check HTTP status codes before processing response body:
  2. 2. Implement exponential backoff for retry logic on 500 errors:
  3. 3. Log error responses with detail information for debugging:
  4. 4. Validate inputs before sending requests to avoid 400 errors:
  5. 5. Handle authentication errors by prompting users to update API keys:
  6. 6. Monitor task status periodically instead of polling too frequently:
  7. 7. Use webhooks when possible to avoid polling for task completion:

Sample Error Handling (JavaScript)

async function generateImage(prompt, apiKey) {
  try {
    const response = await fetch('https://api.defapi.org/api/image/gen', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${apiKey}`
      },
      body: JSON.stringify({
        model: 'google/gempix2',
        prompt: prompt
      })
    });

    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(`API Error ${response.status}: ${errorData.message}`);
    }

    const data = await response.json();
    return data.data.task_id;

  } catch (error) {
    console.error('Image generation failed:', error.message);
    throw error;
  }
}