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

# Images

> Examples of image generation, editing, and analysis with SynapsAI Cloud

Our image endpoints are compatible with the OpenAI API, supporting the same `v1/images/generations` and `v1/images/edits` formats, plus additional analysis capabilities.

## Image generation

Here is an example of image generation:

**Parameters:**

* `model`: The model ID of the model you want to use
* `prompt`: The text description of the image to generate
* `n`: The number of images to generate (default: 1, range: 1-10)
* `quality`: The quality of the generated image (default: "standard", options: "standard", "hd")
* `response_format`: The format of the returned image (default: "url", options: "url", "b64\_json")
* `size`: The size of the generated image (default: "1024x1024", options: "256x256", "512x512", "1024x1024", "1792x1024", "1024x1792")
* `style`: The style of the generated image (default: "vivid", options: "vivid", "natural")

<CodeGroup>
  ```python title="Python" theme={null}
  from synapsai import SynapsAI
  import base64

  model = SynapsAI("your-api-key")

  response = model.images.generate(
      model="model-id",
      prompt="A beautiful sunset over a mountain lake",
      n=1,
      quality="hd",
      response_format="b64_json",
      size="1024x1024",
      style="vivid"
  )

  with open("image.jpg", "wb") as f:
      f.write(base64.b64decode(response.data[0].b64_json))
  ```

  ```curl title="cURL" theme={null}
  curl -X POST https://api.synapsai.cloud/v1/images/generations \
    -H "Authorization: Bearer $SYNAPSAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
          "model": "model-id",
          "prompt": "A beautiful sunset over a mountain lake",
          "n": 1,
          "quality": "hd",
          "response_format": "url",
          "size": "1024x1024",
          "style": "vivid"
      }'
  ```
</CodeGroup>

## Image editing

Here is an example of image editing:

**Parameters:**

* `model`: The model ID of the model you want to use
* `image`: The image to edit (base64 encoded, URL, or file)
* `prompt`: The text description of the changes to make
* `mask`: The mask image indicating areas to edit (optional)
* `n`: The number of edited images to generate (default: 1, range: 1-10)
* `size`: The size of the edited image (default: "1024x1024")
* `response_format`: The format of the returned image (default: "url", options: "url", "b64\_json")

<CodeGroup>
  ```python title="Python" theme={null}
  from synapsai import SynapsAI
  import base64

  model = SynapsAI("your-api-key")

  response = model.images.edit(
      image="path/to/image.jpg",
      model="model-id",
      prompt="Add a rainbow in the sky",
      mask="path/to/mask.png",
      n=1,
      size="1024x1024",
      response_format="b64_json"
  )

  with open("edited_image.jpg", "wb") as f:
      f.write(base64.b64decode(response.data[0].b64_json))
  ```

  ```curl title="cURL" theme={null}
  curl -X POST https://api.synapsai.cloud/v1/images/edits \
    -H "Authorization: Bearer $SYNAPSAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
          "model": "model-id",
          "image": "path/to/image.jpg",
          "prompt": "Add a rainbow in the sky",
          "mask": "path/to/mask.png",
          "n": 1,
          "size": "1024x1024",
          "response_format": "url"
      }'
  ```
</CodeGroup>

## Image to text

Here is an example of image analysis to extract text descriptions:

**Parameters:**

* `model`: The model ID of the model you want to use
* `inputs`: The image to analyze (base64 encoded, URL, or file)
* `max_new_tokens`: Maximum number of tokens to generate (default: 300)
* `generate_kwargs`: Additional generation parameters (optional)

<CodeGroup>
  ```python title="Python" theme={null}
  from synapsai import SynapsAI

  model = SynapsAI("your-api-key")

  response = model.images.to_text(
      model="model-id",
      inputs="https://example.com/image.jpg",
      max_new_tokens=300,
      generate_kwargs={"temperature": 0.7}
  )

  for result in response.data:
      print("Analysis:", result)
  ```

  ```curl title="cURL" theme={null}
  curl -X POST https://api.synapsai.cloud/v1/images/to-text \
    -H "Authorization: Bearer $SYNAPSAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
          "model": "model-id",
          "inputs": "https://example.com/image.jpg",
          "max_new_tokens": 300,
          "generate_kwargs": {"temperature": 0.7}
      }'
  ```
</CodeGroup>

## Image feature extraction

Here is an example of extracting features from images:

**Parameters:**

* `model`: The model ID of the model you want to use
* `inputs`: The image to extract features from (base64 encoded, URL, or file)

<CodeGroup>
  ```python title="Python" theme={null}
  from synapsai import SynapsAI

  model = SynapsAI("your-api-key")

  response = model.images.feature_extraction(
      model="model-id",
      inputs="https://example.com/image.jpg"
  )

  for features in response.data:
      print("Features:", features)
  ```

  ```curl title="cURL" theme={null}
  curl -X POST https://api.synapsai.cloud/v1/images/feature-extraction \
    -H "Authorization: Bearer $SYNAPSAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
          "model": "model-id",
          "inputs": "https://example.com/image.jpg"
      }'
  ```
</CodeGroup>

## Image segmentation

Here is an example of image segmentation:

**Parameters:**

* `model`: The model ID of the model you want to use
* `inputs`: The image to analyze (base64 encoded, URL, or file)
* `subtask`: The segmentation subtask (default: "panoptic")
* `threshold`: The confidence threshold (default: 0.9)
* `mask_threshold`: The mask threshold (default: 0.5)
* `overlap_mask_area_threshold`: The overlap mask area threshold (default: 0.5)

<CodeGroup>
  ```python title="Python" theme={null}
  from synapsai import SynapsAI

  model = SynapsAI("your-api-key")

  response = model.images.segmentation(
      model="model-id",
      inputs="https://example.com/image.jpg",
      subtask="panoptic",
      threshold=0.9,
      mask_threshold=0.5,
      overlap_mask_area_threshold=0.5
  )

  for result in response.data:
      print("Segmentation:", result)
  ```

  ```curl title="cURL" theme={null}
  curl -X POST https://api.synapsai.cloud/v1/images/segmentation \
    -H "Authorization: Bearer $SYNAPSAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
          "model": "model-id",
          "inputs": "https://example.com/image.jpg",
          "subtask": "panoptic",
          "threshold": 0.9,
          "mask_threshold": 0.5,
          "overlap_mask_area_threshold": 0.5
      }'
  ```
</CodeGroup>

## Depth estimation

Here is an example of depth estimation:

**Parameters:**

* `model`: The model ID of the model you want to use
* `inputs`: The image to analyze (base64 encoded, URL, or file)
* `parameters`: Additional parameters for depth estimation (optional)

<CodeGroup>
  ```python title="Python" theme={null}
  from synapsai import SynapsAI

  model = SynapsAI("your-api-key")

  response = model.images.depth_estimation(
      model="model-id",
      inputs="https://example.com/image.jpg",
      parameters={"output_format": "numpy"}
  )

  for result in response.data:
      print("Depth map:", result)
  ```

  ```curl title="cURL" theme={null}
  curl -X POST https://api.synapsai.cloud/v1/images/depth-estimation \
    -H "Authorization: Bearer $SYNAPSAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
          "model": "model-id",
          "inputs": "https://example.com/image.jpg",
          "parameters": {"output_format": "numpy"}
      }'
  ```
</CodeGroup>

## Object detection

Here is an example of object detection:

**Parameters:**

* `model`: The model ID of the model you want to use
* `inputs`: The image to analyze (base64 encoded, URL, or file)
* `threshold`: The confidence threshold for detections (default: 0.5)

<CodeGroup>
  ```python title="Python" theme={null}
  from synapsai import SynapsAI

  model = SynapsAI("your-api-key")

  response = model.images.object_detection(
      model="model-id",
      inputs="https://example.com/image.jpg",
      threshold=0.5
  )

  for detection in response.data:
      print("Detected objects:", detection)
  ```

  ```curl title="cURL" theme={null}
  curl -X POST https://api.synapsai.cloud/v1/images/object-detection \
    -H "Authorization: Bearer $SYNAPSAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
          "model": "model-id",
          "inputs": "https://example.com/image.jpg",
          "threshold": 0.5
      }'
  ```
</CodeGroup>

## Mask Generation

Here is an example of mask generation:

**Parameters:**

* `image`: The image to generate masks for (base64 encoded, URL, or file)
* `mask_threshold`: The threshold for mask generation (default: 0.0)
* `pred_iou_thresh`: The threshold for prediction IOU (default: 0.88)
* `stability_score_thresh`: The threshold for stability score (default: 0.95)
* `stability_score_offset`: The offset for stability score (default: 1)
* `crops_nms_thresh`: The threshold for crops NMS (default: 0.7)
* `crops_n_layers`: The number of crops layers (default: 0)
* `crop_overlap_ratio`: The overlap ratio for crops (default: 0.3413)
* `crop_n_points_downscale_factor`: The number of points to downscale for crops (default: 1)

<CodeGroup>
  ```python title="Python" theme={null}
  from synapsai import SynapsAI

  model = SynapsAI("your-api-key")

  response = model.images.mask_generation(
      model="model-id",
      image="https://example.com/image.jpg",
      mask_threshold=0.5
  )

  for mask in response.data:
      print("Mask:", mask)
  ```

  ```curl title="cURL" theme={null}
  curl -X POST https://api.synapsai.cloud/v1/images/mask-generation \
    -H "Authorization: Bearer $SYNAPSAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
          "model": "model-id",
          "image": "https://example.com/image.jpg",
          "mask_threshold": 0.5
      }'
  ```
</CodeGroup>

You can also try image generation and editing using the [Playground](https://platform.synapsai.cloud/playground). For deeper insights into the image endpoints, see our [API reference](https://docs.synapsai.cloud/api-reference/generate-images-from-prompts).
