Reference Image API Reference

    Use the Gate.AI image-to-image endpoint to upload a reference image and generate or edit an image. This endpoint uses multipart/form-data and synchronously returns image URLs and billing details; usage.input_tokens includes image_tokens counted from the reference image.

    FieldValue
    Base URLhttps://api.gate.ai/openai/v1
    AuthAuthorization: Bearer <API_KEY>
    FormatOpenAI-compatible; uses a multipart/form-data request body

    Image endpoints live under /openai/v1. Generated data\[\].url values are short-lived S3 presigned URLs, so download or persist them promptly. Stored objects have a 30-day TTL.

    Generate Images from a Reference Image

    POST/images/edits

    Upload a reference image with multipart/form-data to synchronously generate or edit an image. usage.input_tokens includes image_tokens counted from the reference image.

    Request Parameters

    NameInTypeRequiredDescription
    AuthorizationheaderstringYesGate.AI API Key. Format: Bearer <API_KEY>
    Content-TypeheaderstringYesRequest body format: multipart/form-data

    Request Body

    NameTypeRequiredDescription
    modelstringYesImage model ID, such as gpt-image-1, qwen-image-2.0-pro, or seedream-4.0. Missing model returns 400 model is required
    imagefileYesReference image file. gpt-image-1 requires PNG, under 4 MB, square; without mask, it must include an alpha channel as the mask
    maskfileNoPNG mask. Transparent areas are edited, and dimensions must match image
    promptstringYesEdit prompt, up to 1000 characters
    nintegerNoNumber of images to generate, 1-10, default 1. Multiple images are billed per image
    sizestringNoOutput size. gpt-image-1 supports 256x256, 512x512, or 1024x1024, and this is used for cost estimation
    response_formatstringNourl or b64_json. gpt-image-1 does not support this parameter and may reject it upstream

    Example

    text
    1model=gpt-image-12prompt=Add a yellow border and a small sun in the corner3size=1024x10244image=@./input.png

    Response Fields

    NameTypeDescription
    createdintegerGeneration timestamp in seconds
    dataarrayResult array, length equals n
    data\[\].urlstringImage S3 presigned URL, short-lived, with a 30-day stored object TTL
    usageobjectUsage. OpenAI models return token details; Qwen models return width, height, and image_count
    model_extend.coststringActual billed amount in USD; billing is based on this value
    model_extend.line_itemsarrayBilling line items. Token billing includes input/output/cache; per-image billing includes billing_unit, rate_usd_per_image, and resolution_tier
    model_extend.providerstringActual upstream provider, such as openai or qwen
    size / quality / output_format / backgroundstringInput fields echoed by some models
    modelstringOnly echoed at the top level for Qwen models

    Response Example

    json
    1{2  "created": 1781604390,3  "data": [4    {5      "url": "https://ai-gateway-file.s3.ap-northeast-1.amazonaws.com/multimodal/image/2026/06/16/example-edit-0.png?X-Amz-Expires=600&X-Amz-Signature=..."6    }7  ],8  "size": "1024x1024",9  "quality": "low",10  "output_format": "png",11  "usage": {12    "input_tokens": 220,13    "input_tokens_details": {14      "image_tokens": 194,15      "text_tokens": 2616    },17    "output_tokens": 272,18    "total_tokens": 49219  },20  "model_extend": {21    "cost": "0.009804",22    "provider": "openai",23    "total_tokens": "492"24  }25}

    Response

    StatusMeaningDescriptionSchema
    200OKSuccess. Returns image results and billing information synchronously.ImageResponse
    400Bad RequestMalformed request body, invalid JSON, or missing model / prompt.OpenAIErrorResponse
    401UnauthorizedAPI key is invalid or missing.OpenAIErrorResponse
    402Payment RequiredInsufficient balance. Response includes current balance and estimated cost.InsufficientBalanceResponse
    404Not FoundModel not found, or the image endpoint is not enabled.OpenAIErrorResponse
    413Payload Too LargeRequest body too large. Default limit is 8 MiB.OpenAIErrorResponse
    429Too Many RequestsToo many requests. Please slow down.OpenAIErrorResponse
    500Internal Server ErrorInternal server error.OpenAIErrorResponse
    502Bad GatewayUpstream image service failed.OpenAIErrorResponse