# Text to Image

## How to Generate Images using the Infron AI API <a href="#how-to-generate-images-using-the-fal-api" id="how-to-generate-images-using-the-fal-api"></a>

To generate images using the Infron AI API, you need to send a request to the appropriate endpoint with the desired input parameters. The API uses pre-trained models to generate images based on the provided text prompt. This allows you to create images by simply describing what you want in natural language.

Here’s an example of how to generate an image using the Infron AI API from text:

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

<pre class="language-sh"><code class="lang-sh">curl https://image.onerouter.pro/v1/images/generations \
<strong>    -H "Content-Type: application/json" \
</strong>    -H "Authorization: &#x3C;API_KEY>" \
    -d '{
    "model": "gpt-image-1",
    "prompt": "A cute baby sea otter",
    "n": 1,
    "output_format": "url"
  }'
</code></pre>

{% endtab %}

{% tab title="Python" %}

```python
from openai import OpenAI
import base64
import os

client = OpenAI(
    api_key="<API_KEY>", # Replace with your Key "sk-***"
    base_url="https://image.onerouter.pro/v1"
)

prompt = """A cute baby sea otter."""

result = client.images.generate(
    model="gpt-image-1",
    prompt=prompt,
    n=1,
    output_format: "url"
)

print(result)
```

{% endtab %}
{% endtabs %}

* `https://image.onerouter.pro/v1/images/generations` is the base URL
* `<API_KEY>` is your API Key generated in [API page](https://app.onerouter.pro/apiKeys).
* `model` is the model name, such as `gpt-image-1`, available model list can be access in [Model page](https://app.onerouter.pro/models).
* `prompt`  is the prompt.
* `n`  is the number of images to generate, default value is `1`.
* `output_format` indicate the output format, default value is `url`.
  * `b64_json`
  * `url`

You can find more models and their descriptions in the [Model page](https://app.onerouter.pro/models).

***

## **Example response**

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

```json
{
    "data": [
        {
            "url": "https://resource.trustai.sg/image/generated%2Fonerouter_a146ee8a-1fe2-43ce-803a-fb1e7f3f6949.png",
            "b64_json": "",
            "revised_prompt": ""
        }
    ],
    "created": 1760177063
}
```

{% endtab %}

{% tab title="Error" %}

```json
{
    "error": {
        "message": "error msg.",
        "type": "error type (such as content_policy_violation)",
        "param": "",
        "code": 422
    }
}
```

{% endtab %}
{% endtabs %}
