Skip to content

Image Generation API

This page separates image generation into two real calling flows: image2 uses the synchronous Images API and returns image data directly; nano_banana* and gpt-image-2* use asynchronous tasks, submitted through /v1/videos and then queried by task ID.

Images / Videos

This page documents image generation. For video generation, see Video Generation API. You can also compare against the online goswitch API docs.

Base Variables

All examples use BASE_URL as the site root. Do not include /v1 in this value. When you switch to another site, only change this variable.

bash
BASE_URL="https://goswitcher.com"
API_KEY="YOUR_API_KEY"

Which Endpoint To Use

ScenarioModeModelEndpointResult
image2 generation / reference generationSyncimage2POST /v1/images/generationsReturns data[0].b64_json directly
image2 image editSyncimage2POST /v1/images/editsReturns data[0].b64_json directly
nano_banana text-to-image / image-to-imageAsyncnano_banana_2, nano_banana_pro-1K, nano_banana_pro-2K, nano_banana_pro-4KPOST /v1/videosReturns a task ID, then use task query at the end
gpt-image-2 text-to-image / image-to-imageAsyncgpt-image-2, gpt-image-2-2K, gpt-image-2-4KPOST /v1/videosReturns a task ID, then use task query at the end
Async task queryShared queryTask IDGET /v1/videos/{task_id}Returns task status and result URLs

Core Difference

The asynchronous submit response is only task state. It does not mean the image has finished. Read images only after the task query returns completed, from url, urls, or data[].url. image2 synchronous endpoints do not need task polling because the response contains b64_json.

Authentication

HeaderRequiredNotes
AuthorizationYesBearer YOUR_API_KEY
Content-TypeYesUse application/json for JSON requests; use multipart/form-data for file upload requests

Base URL

BASE_URL is the site root, for example https://goswitcher.com. Do not set it to https://goswitcher.com/v1 and then append /v1/videos, or the path will contain /v1 twice.

Endpoint Details

image2 Sync Generation

image2 uses OpenAI-compatible Images API endpoints. It returns synchronously and does not need task polling.

ItemText-to-image / reference generationImage edit
MethodPOSTPOST
Path/v1/images/generations/v1/images/edits
JSON reference imagesimage supports a string or string arrayimage supports a string or string array
File uploadNot recommendedRecommended with multipart/form-data
Resultdata[0].b64_jsondata[0].b64_json

Request Parameters

ParameterTypeRequiredNotes
modelstringYesFixed as image2
promptstringYesImage description or edit instruction
sizestringNoFor example 1024x1024, 1024x1792, 1792x1024
imagestring or string[]NoReference image URL or full Data URL. Usually required for image edit
nintegerNoThe sync endpoint follows upstream capability. Requesting multiple images does not guarantee multiple images will be returned

Text-To-Image / Reference Generation

bash
curl -X POST "$BASE_URL/v1/images/generations" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "image2",
    "prompt": "Use two reference images to create an advertising hero image",
    "size": "1024x1792",
    "image": [
      "https://example.com/reference-1.jpg",
      "https://example.com/reference-2.png"
    ]
  }'

Image Edit / File Upload

bash
curl -X POST "$BASE_URL/v1/images/edits" \
  -H "Authorization: Bearer $API_KEY" \
  --form 'model="image2"' \
  --form 'prompt="Keep the subject and change the background to a light gray studio setup"' \
  --form 'size="1024x1024"' \
  --form 'image=@"/path/to/example.jpg"'
image2 synchronous response example
json
{
  "created": 1782108238,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSU..."
    }
  ],
  "usage": {
    "input_tokens": 4,
    "output_tokens": 1105,
    "total_tokens": 1109
  }
}

Task Query

ItemValue
MethodGET
Path/v1/videos/{task_id}
UseQuery Banana, GPT Image, video, and other asynchronous tasks

Path Parameters

ParameterTypeRequiredNotes
task_idstringYesThe id returned by the submit endpoint

Status Fields

statusClient behavior
queuedThe task is queued. Continue polling
processingThe task is processing. Continue polling
in_progressThe task is processing. Continue polling
completedThe task is complete. Read results from url, urls, or data[].url
failedThe task failed. Read error or error.message

Poll every 3 to 5 seconds to avoid sending too many query requests.

Call Examples

bash
TASK_ID="task_xxxxxxxxxxxxx"

curl -X GET "$BASE_URL/v1/videos/$TASK_ID" \
  -H "Authorization: Bearer $API_KEY"
Task response examples
json
{
  "id": "task_xxxxxxxxxxxxx",
  "object": "image",
  "model": "gpt-image-2",
  "status": "queued",
  "progress": 0,
  "created_at": 1709876543
}
json
{
  "id": "task_xxxxxxxxxxxxx",
  "object": "image",
  "model": "nano_banana_2",
  "status": "completed",
  "progress": 100,
  "created_at": 1709876543,
  "completed_at": 1709876580,
  "url": "https://example.com/images/result.jpg"
}
json
{
  "id": "task_batch_xxxxxxxxxxxxx",
  "object": "image_batch",
  "model": "gpt-image-2",
  "status": "completed",
  "progress": 100,
  "urls": ["https://example.com/images/result-1.jpg"],
  "data": [
    {
      "index": 0,
      "id": "task_a",
      "status": "completed",
      "url": "https://example.com/images/result-1.jpg",
      "image_url": "https://example.com/images/result-1.jpg",
      "error": null
    }
  ]
}
json
{
  "id": "task_xxxxxxxxxxxxx",
  "object": "image",
  "model": "gpt-image-2",
  "status": "failed",
  "progress": 100,
  "created_at": 1709876543,
  "completed_at": 1709876580,
  "error": {
    "message": "Upstream task failed",
    "code": "upstream_error"
  }
}

Common Notes

  • BASE_URL is the site root, for example https://goswitcher.com; do not set it to https://goswitcher.com/v1 before appending /v1/videos.
  • For asynchronous endpoints, continue polling until the task reaches completed or failed.
  • Reference image URLs must be directly reachable by the server. Intranet URLs and local file paths usually cannot be fetched by the server.
  • image2 synchronous endpoints return image data directly. nano_banana* and gpt-image-2* asynchronous endpoints return task state first.
  • n > 1 is a switcher local batch task. Query the batch task and read results from urls or data[].url.
  • Generated result URLs may expire. Download and store results soon after the task completes.

GoSwitcher documentation site.