# Image Genaration

### Generation

To generate images using the API you can use following code:

{% tabs %}
{% tab title="Python" %}

```python
import requests

base_url = "http://ai.is-a.dev/v1/images/generate"

payload = {
    "model": "dall-e-3",
    "prompt": "a white siamese cat",
    "response_format": "url", # Can also be 'b64_json'
    "size": "1024x1024",
    "n": 1,
}

response = requests.post(base_url, json=payload)

if response.status_code == 200:
    resp = response.json()
    print("Response:", resp)
else:
    print("Error:", response.status_code, response.text)

```

{% endtab %}

{% tab title="JavaScript" %}
Install OpenAI package:

```
npm install --save openai
# or
yarn add openai
```

Example code:

```javascript
import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: 'https://katz.is-a.dev/v1'
});

const response = await openai.images.generate({
  model: "dall-e-3",
  prompt: "a white siamese cat",
  n: 1,
  size: "1024x1024",
});

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

{% endtab %}

{% tab title="Curl" %}

<pre><code><strong>curl https://katz.is-a.dev/v1/images/generations \
</strong>  -H "Content-Type: application/json" \
  -d '{
    "model": "dall-e-3",
    "prompt": "a white siamese cat",
    "n": 1,
    "size": "1024x1024"
  }'
</code></pre>

{% endtab %}
{% endtabs %}

### Response Structure

The response from the API will be a JSON object containing information about the generated image(s). The key elements in the response include:

* `data`: An array of generated images.
  * `url`: The URL of the generated image.
  * `revised_prompt`:  The revised prompt if `enhance` is set to `true`  &#x20;
  * `b64_json`:  The genarated image in base64
* `created`: The timestamp indicating when the image was generated.

Here's an example of what the response might look like:

```json
{
  "data": [
    {"revised_prompt": "Enhanced Prompt", "url": "https://ai.is-a.dev/cdn/example.png", "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."}
    {"revised_prompt": "Enhanced Prompt2", "url": "https://ai.is-a.dev/cdn/example2.png", "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."}
  ],

  "created": "1696464000"
}
```
