EccoAPIeccoapi
INFO/api/v1/nanobanana2/generate

Async Callbacks (2)

Use webhooks to receive results asynchronously. Ideal for high-quality 4K generations or when you want non-blocking requests.

Overview

When you include a callbackUrl in your request, the API returns a 202 Accepted response immediately with a job ID. Once the image is generated, the result is sent as a POST request to your callback URL. You can also poll the job status using the returned statusUrl.

Request Parameters

ParameterTypeRequiredDescription
callbackUrlstringYesYour webhook URL to receive results

Include callbackUrl alongside all other generation parameters (prompt, imageSize, etc.).

Example Request

bash
curl -X POST https://eccoapi.com/api/v1/nanobanana2/generate \
  -H "Authorization: Bearer nk_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Epic cinematic panorama of a dragon over a medieval castle",
    "aspectRatio": "21:9",
    "imageSize": "4K",
    "callbackUrl": "https://your-server.com/webhook"
  }'

Async Response (202 Accepted)

Returned immediately when a callbackUrl is provided. Use the jobId or statusUrl to track progress.

json
{
  "code": 202,
  "msg": "Job accepted",
  "jobId": "nb2_a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "statusUrl": "https://eccoapi.com/api/v1/jobs/nb2_a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "callbackUrl": "https://your-server.com/webhook"
}

Callback Payload (Success)

Sent as a POST request to your callbackUrl when the image is ready.

json
{
  "jobId": "nb2_a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "completed",
  "code": 200,
  "msg": "Success",
  "data": {
    "assetUrl": "https://<signed-url>",
    "candidates": [{
      "content": {
        "parts": [{
          "inlineData": {
            "mimeType": "image/png",
            "assetUrl": "https://<signed-url>",
            "assetKey": "user/<userId>/nanobanana2/....png"
          }
        }]
      }
    }]
  },
  "meta": {
    "model": "nanobanana2",
    "cost": 0.07,
    "remaining_credits": 9.93,
    "settings": {
      "aspectRatio": "21:9",
      "imageSize": "4K"
    }
  }
}

Callback Payload (Failure)

Sent when image generation fails. Check the error code and message for details.

json
{
  "jobId": "nb2_a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "failed",
  "code": 500,
  "msg": "Generation failed",
  "error": "The model was unable to generate an image for this prompt."
}

Example Flow

1.Client sends POST to /api/v1/nanobanana2/generate with callbackUrl
2.API responds with 202 Accepted and a jobId
3.Image generation runs in the background
4.On completion, API sends POST to your callbackUrl with the result payload
5.(Optional) Poll statusUrl anytime to check job progress