# 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="/files/RTJQUmJPkXgrxDm8H4f6" 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="/files/1jfbSf2Jwvf4KC7iNVgn" alt="" data-size="original"> | <img src="/files/H2r4BGEHwP0ESXVdYfIc" alt="" data-size="original"> | <img src="/files/JPpB5a5FEiAieiTja3kq" alt="" data-size="original"> |

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


---

# Agent Instructions: 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.blockentropy.ai/generation/image-generation/usage.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.
