> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eigenai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Image

> Generate or edit images depending on the selected model.

`POST /api/v1/generate`

**Content-Type:** `application/json` for text-to-image · `multipart/form-data` for image editing

<Warning>
  Parameter support can differ depending on the model used to generate the response. Check the Model Library for model-specific compatibility. [Open Model Library](https://app.eigenai.com/model-library).
</Warning>

## Authentication

Send your API key in the `Authorization` header as a Bearer token.

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

## Parameters

### Common

| Name     | Type     | Required | Description                                                                                                     |
| -------- | -------- | -------- | --------------------------------------------------------------------------------------------------------------- |
| `model`  | `string` | Required | The model ID to used to generate the response, like flux-1-kontext. Find supported models in the Model Library. |
| `prompt` | `string` | Required | Text prompt describing what to generate.                                                                        |

### Conditional

The following parameters are not supported by every model. Check the [Model Library](https://api-web.eigenai.com/model-library) for model-specific compatibility.

#### Image Generation (Text Prompt)

Generate an image from a text prompt.

| Name             | Type      | Required | Description                                                                                                                       |
| ---------------- | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `seed`           | `integer` | Optional | Random seed for reproducible results. If not provided, a random seed will be used.                                                |
| `mode`           | `string`  | Optional | Generation mode: "text-to-image" (default) for generating images from text prompts, or "image-editing" for editing source images. |
| `real_time`      | `boolean` | Optional | Enable real-time web search mode for current references. Text to Image mode only. Defaults to false.                              |
| `width`          | `integer` | Optional | Output width in pixels, t2i mode only (default: 1024, range: 512–2048).                                                           |
| `height`         | `integer` | Optional | Output height in pixels, t2i mode only (default: 1024, range: 512–2048).                                                          |
| `guidance_scale` | `number`  | Optional | Classifier-free guidance scale (default: 1.0).                                                                                    |

#### Image Editing (Upload or URL)

Transform the source image using an instruction prompt.

| Name                  | Type      | Required | Description                                                                                                                                |
| --------------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `image_file`          | `file`    | Optional | Upload the source image file.                                                                                                              |
| `image`               | `file`    | Optional | Some request types use `image` instead of `image_file` for uploading source images.                                                        |
| `image_path`          | `string`  | Optional | Reference to the source image (often an HTTPS URL or an internal path).                                                                    |
| `num_inference_steps` | `number`  | Optional | Number of inference/denoising steps. Defaults to 30.                                                                                       |
| `binary_response`     | `boolean` | Optional | Whether to return binary image data directly instead of JSON.                                                                              |
| `output_format`       | `string`  | Optional | Output image format (jpg or png).                                                                                                          |
| `downsizing_mp`       | `number`  | Optional | Downsample large images for faster processing.                                                                                             |
| `lora_strength`       | `number`  | Optional | a numerical multiplier that controls the intensity of the applied Low-Rank Adaptation (LoRA) on the base model's weights. Defaults to 0.8. |
| `rank`                | `number`  | Optional | Edit complexity/strength knob. Defaults to 32.                                                                                             |
| `offloading`          | `boolean` | Optional | Enable CPU offloading in constrained environments.                                                                                         |
| `weight`              | `string`  | Optional | Select an editing profile (lightning or vanilla).                                                                                          |
| `true_cfg_scale`      | `number`  | Optional | Guidance scale controlling how strongly the prompt is applied..                                                                            |
| `sample_steps`        | `number`  | Optional | Sampling steps.                                                                                                                            |
| `sample_guide_scale`  | `number`  | Optional | Sampling guidance scale.                                                                                                                   |
| `negative_prompt`     | `string`  | Optional | What to avoid in the output.                                                                                                               |
| `s3_output_path`      | `string`  | Optional | Destination bucket/key for the output image (e.g. s3://chatbot-images-eigenai/banana\_example.png).                                        |

## Examples

### Image generation (JSON)

Generate an image from a text prompt using a JSON request body.

<CodeGroup>
  ```bash cURL theme={null}
  # Select a model in the Model Library: https://api-web.eigenai.com/model-library

  curl -X POST https://api-web.eigenai.com/api/v1/generate \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "YOUR_MODEL",
      "prompt": "A fluffy orange tabby cat in a sunlit garden"
    }'
  ```

  ```python Python theme={null}
  # Select a model in the Model Library: https://api-web.eigenai.com/model-library

  import base64
  import requests

  url = "https://api-web.eigenai.com/api/v1/generate"
  headers = {
      "Authorization": "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
  }
  payload = {
      "model": "YOUR_MODEL",
      "prompt": "A fluffy orange tabby cat in a sunlit garden",
  }

  response = requests.post(url, headers=headers, json=payload, timeout=120)
  response.raise_for_status()
  result = response.json()

  # Some models return base64-encoded images in JSON.
  if "image_base64" in result:
      with open("output.png", "wb") as f:
          f.write(base64.b64decode(result["image_base64"]))
      print("Saved output.png")
  else:
      print(result)
  ```

  ```javascript JavaScript theme={null}
  // Select a model in the Model Library: https://api-web.eigenai.com/model-library

  const response = await fetch("https://api-web.eigenai.com/api/v1/generate", {
    method: "POST",
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "YOUR_MODEL",
      prompt: "A fluffy orange tabby cat in a sunlit garden",
    }),
  });

  if (!response.ok) {
    throw new Error(`Request failed: ${response.status} ${await response.text()}`);
  }

  const result = await response.json();
  console.log(result);
  ```
</CodeGroup>

### Image editing (multipart upload)

Upload an image file and apply an edit instruction prompt.

<CodeGroup>
  ```bash cURL theme={null}
  # Select a model in the Model Library: https://api-web.eigenai.com/model-library

  curl -X POST https://api-web.eigenai.com/api/v1/generate \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -F "model=YOUR_MODEL" \
    -F "prompt=Replace the bag with a laptop" \
    -F "image_file=@/path/to/source.png" \
    -F "num_inference_steps=15" \
    -F "binary_response=true" \
    --output edited.png
  ```

  ```python Python theme={null}
  # Select a model in the Model Library: https://api-web.eigenai.com/model-library

  import requests

  url = "https://api-web.eigenai.com/api/v1/generate"
  headers = {"Authorization": "Bearer YOUR_API_KEY"}

  with open("source.png", "rb") as f:
      files = {"image_file": ("source.png", f, "image/png")}
      data = {
          "model": "YOUR_MODEL",
          "prompt": "Replace the bag with a laptop",
          "num_inference_steps": "15",
          "binary_response": "true",
      }

      response = requests.post(url, headers=headers, data=data, files=files, timeout=120)
      response.raise_for_status()

      # If binary_response=true, the response may be raw image bytes.
      with open("edited.png", "wb") as out:
          out.write(response.content)
  ```

  ```javascript JavaScript theme={null}
  // Select a model in the Model Library: https://api-web.eigenai.com/model-library

  import fs from "node:fs";

  const form = new FormData();
  form.append("model", "YOUR_MODEL");
  form.append("prompt", "Replace the bag with a laptop");
  form.append("image_file", fs.createReadStream("source.png"));
  form.append("num_inference_steps", "15");
  form.append("binary_response", "true");

  const response = await fetch("https://api-web.eigenai.com/api/v1/generate", {
    method: "POST",
    headers: {
      Authorization: "Bearer YOUR_API_KEY",
    },
    body: form,
  });

  if (!response.ok) {
    throw new Error(`Request failed: ${response.status} ${await response.text()}`);
  }

  const buffer = Buffer.from(await response.arrayBuffer());
  fs.writeFileSync("edited.png", buffer);
  ```
</CodeGroup>
