> For the complete documentation index, see [llms.txt](https://docs.viralapi.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.viralapi.ai/guides/getting-started.md).

# Getting Started

This guide walks you through making your first image generation request with ViralAPI.

## Prerequisites

* A ViralAPI account with an active API Key ([get one here](https://viralapi.ai/api-key))

## Step 1: Create a Task

Send a POST request to create an image generation task:

```bash
curl -X POST https://viralapi.ai/v1/task/create \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gemini-2.5-flash-image",
    "task_type": "image",
    "input": {
      "prompt": "A serene mountain landscape at sunset with vibrant colors",
      "aspect_ratio": "16:9"
    }
  }'
```

Response:

```json
{
  "code": 200,
  "msg": "success",
  "data": {
    "task_id": "task_nanobanana_1765178625768"
  }
}
```

## Step 2: Poll for Results

Use the `task_id` to check the task status:

```bash
curl -X GET "https://viralapi.ai/v1/task/query?task_id=task_nanobanana_1765178625768" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

Response (completed):

```json
{
  "create_time": 1756817821,
  "complete_time": 1763088308,
  "task_type": "image",
  "task_id": "task_nanobanana_1765178625768",
  "progress": 100,
  "model": "gemini-2.5-flash-image",
  "status": "completed",
  "results": [
    "https://cdn.viralapi.ai/outputs/generated-image-1.png"
  ]
}
```

## Step 3: Download the Image

When `status` is `completed`, the `results` array contains the generated image URLs. Download them before they expire (24-hour validity).

## Using NanoBanana Pro

For higher quality output, switch to the Pro model:

```bash
curl -X POST https://viralapi.ai/v1/task/create \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gemini-3-pro-image-preview",
    "task_type": "image",
    "input": {
      "prompt": "A futuristic city with neon lights",
      "image_size": "2K",
      "aspect_ratio": "9:16"
    }
  }'
```

The Pro model additionally supports `image_size` parameter (`1K`, `2K`, `4K`).

## Image Editing

To edit an existing image, add `image_urls` to the input:

```bash
curl -X POST https://viralapi.ai/v1/task/create \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "gemini-2.5-flash-image",
    "task_type": "image",
    "input": {
      "prompt": "Transform this into a watercolor painting style",
      "image_urls": ["https://example.com/your-image.jpg"],
      "aspect_ratio": "1:1"
    }
  }'
```

The presence of `image_urls` switches the operation from text-to-image to image editing. Up to 10 images are supported.

## Next Steps

* [Authentication](/guides/authentication.md) — Token management and security
* [Async Workflow](/guides/async-workflow.md) — Polling strategies and best practices


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.viralapi.ai/guides/getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
