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

# Usage

### Image Generation

The image generations endpoint allows you to create an original image given a text prompt.

{% code title="Generate an image" lineNumbers="true" fullWidth="false" %}

```python
from openai import OpenAI

# Load environment variables 
be_api_key= "BE_API_KEY"
base_url='http://0.0.0.0:1234/v1'
model="be-stable-diffusion-xl-base-1.0"

client = OpenAI(
    base_url=base_url,
    api_key=be_api_key
)

# We repurpose "n" as the seed for SDXL
response = client.images.generate(
  model=model,
  prompt="a photorealistic(1.5) image of a cat playing with a (ball)0.5 in a (forest)1.0",
  size="512x512",
  quality="standard",
  n=2,
  response_format="url" # This field is optional, the default value is url
)

image_url = response.data[0].url
```

{% endcode %}

Example Stable Diffusion XL  generations

<table><thead><tr><th>PROMPT</th><th>GENERATION</th></tr></thead><tbody><tr><td><p></p><pre data-overflow="wrap"><code><strong>A photorealistic image of a cat playing with a ball.
</strong></code></pre></td><td><img src="https://2308244557-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FM1RdX95Bq0gWD2lplhSA%2Fuploads%2FPOgzZ3H43mjPk4nFoSH2%2Fimage.png?alt=media&amp;token=c66b1328-13d0-45f2-9f1b-93c35dfba807" alt="" data-size="original"></td></tr></tbody></table>

Each image can be returned as either a URL or Base64 data, using the [response\_format](https://platform.openai.com/docs/api-reference/images/create#images/create-response_format) parameter. URLs will expire after an hour.

### Image Edits

Also known as "inpainting", the image edits endpoint allows you to edit or extend an image by uploading an image indicating which areas should be replaced.&#x20;

{% code title="Image edits " lineNumbers="true" fullWidth="false" %}

```python
from openai import OpenAI

# Load environment variables 
be_api_key= "BE_API_KEY"
base_url='https://api.blockentropy.ai/v1'
model="be-stable-diffusion-xl-base-1.0"

client = OpenAI(
    base_url=base_url,
    api_key=be_api_key
)

# We repurpose "n" as the seed for SDXL
response = client.images.edit(
  model=model,
  prompt="remove dog",
  size="512x512",
  image=Path("img.png"),
  n=1,
  response_format="url" # This field is optional, the default value is url
)

image_url = response.data[0].url
```

{% endcode %}

| IMAGE                                                                  | MASK                                                               | OUTPUT                                                               |
| ---------------------------------------------------------------------- | ------------------------------------------------------------------ | -------------------------------------------------------------------- |
| ![](https://cdn.openai.com/API/images/guides/image_edit_original.webp) | ![](https://cdn.openai.com/API/images/guides/image_edit_mask.webp) | ![](https://cdn.openai.com/API/images/guides/image_edit_output.webp) |

Prompt: a sunlit indoor lounge area with a pool containing a flamingo

The uploaded image and mask must both be square PNG images less than 4MB in size, and also must have the same dimensions as each other. The non-transparent areas of the mask are not used when generating the output, so they don’t necessarily need to match the original image like the example above.

### Controlnet with open pose

Generate a new image using the same pose as the reference image provided and a prompt.

{% code title="Controlnet with open pose" lineNumbers="true" fullWidth="false" %}

```python
from openai import OpenAI

# Load environment variables 
be_api_key= "BE_API_KEY"
base_url='https://api.blockentropy.ai/v1'
model="be-stable-diffusion-xl-base-1.0"

client = OpenAI(
    base_url=base_url,
    api_key=be_api_key
)

# We repurpose "n" as the seed for SDXL
response = client.images.edit(
  model=model,
  prompt="Darth vader dancing in the street",
  size="512x512",
  image=Path("person.png"),
  n=1,
  response_format="url", # This field is optional, the default value is url
  user="cn" # This parameter is required to be set to "cn" to use controlnet
)

image_url = response.data[0].url_image
pose_url = response.data[0].url_pose
```

{% endcode %}

| IMAGE                                                                                                                                                                                                                                                     | OUTPUT                                                                                                                                                                                                                                                    | POSE IMAGE                                                                                                                                                                                                                                                |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <img src="https://2308244557-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FM1RdX95Bq0gWD2lplhSA%2Fuploads%2FycsxD4cJORXoalijLPBD%2Fimage.png?alt=media&amp;token=9cbfba1c-d9d4-4fe6-9240-f467587b5e06" alt="" data-size="original"> | <img src="https://2308244557-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FM1RdX95Bq0gWD2lplhSA%2Fuploads%2FEV1aQoESoaoz8IaR2X1v%2Fimage.png?alt=media&amp;token=6cd12951-3db6-417e-afa4-b09cea590eb6" alt="" data-size="original"> | <img src="https://2308244557-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FM1RdX95Bq0gWD2lplhSA%2Fuploads%2FF3lXa3038ykd91fOMQ16%2Fimage.png?alt=media&amp;token=a35a5b96-d692-476c-a326-9d59177b7f84" alt="" data-size="original"> |

Prompt: "A ballerina standing in the street, high quality and photorealistic"
