Skip to content
Try chatGet API key

Images

POST /images/generations generates an image from a prompt. model and prompt are required.

Copies this page's setup instructions, to paste into your coding agent.
Show the prompt
Help me set this up to use Bayle AI, an OpenAI-compatible API. Full guide: https://docs.bayle.ai/guides/images/

Goal: generate an image through Bayle from this project and save it to a file.

1. Find or create the OpenAI client for this project (Python or Node, whichever it already uses) and point it at Bayle:
   Python: OpenAI(api_key=os.environ["BAYLE_API_KEY"], base_url="https://api.bayle.ai")
   Node: new OpenAI({ apiKey: process.env.BAYLE_API_KEY, baseURL: 'https://api.bayle.ai' })
2. Pick an image model: curl -s "https://api.bayle.ai/models?type=image" | jq -r '.data[].id'
   Show me the list and let me choose IMAGE_MODEL_ID.
3. Generate with client.images.generate(model=IMAGE_MODEL_ID, prompt="A lighthouse in heavy fog, painted in oils.", response_format="b64_json") and write base64-decoded result.data[0].b64_json to lighthouse.png.
4. Three behaviours differ from OpenAI's image API, so write the code accordingly:
   - A request makes at most one image. `n` above 1 is rejected, so for several images send several requests (they can run concurrently).
   - Always pass `response_format` explicitly. Omitting it returns `b64_json`, not `url`, and there is no `url` key at all, so `data[0].url` is absent.
   - `response_format: "url"` returns a base64 `data:` URI in `url`, not a downloadable link. Do not fetch it over HTTP; decode it, or just ask for `b64_json`.
5. `size`, `quality` and `style` are passed to the model as sent; what they accept depends on the model.
6. Test: run the script, then confirm lighthouse.png exists and is a valid image (for example with `file lighthouse.png`). Show me the result.

Rules:
1. The base URL is https://api.bayle.ai exactly as written. Append no path to it.
2. Read the key from the BAYLE_API_KEY environment variable. Never write the key itself into a file you create, a command, a commit or the chat. Where the tool keeps the key in its own settings screen, tell me where to paste it. If BAYLE_API_KEY is not set, stop and ask me to create a key at https://chat.bayle.ai/developers and export it.
3. Take model ids only from GET https://api.bayle.ai/models (no key needed). Never guess one.
4. Finish with one real test request, show me the result and list the files you changed.

The safe pattern: ask for b64_json explicitly and decode it.

import base64, pathlib
result = client.images.generate(
model="IMAGE_MODEL_ID",
prompt="A lighthouse in heavy fog, painted in oils.",
response_format="b64_json",
)
pathlib.Path("lighthouse.png").write_bytes(base64.b64decode(result.data[0].b64_json))

A request generates at most one image. Asking for more through n is rejected rather than silently truncated, so you find out immediately instead of wondering where the other images went.

To generate several, send several requests. They are independent, so run them concurrently.

Section titled “response_format: "url" returns inline data, not a link”

Asking for url gives you a url field, but it holds a base64 data: URI rather than a fetchable link:

{
"data": [
{ "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..." }
]
}

Passing that to an HTTP client expecting to download something will not work. Decode it instead, or better, ask for b64_json and skip the data: prefix entirely.

Omitting response_format does not default to url

Section titled “Omitting response_format does not default to url”

This is the one that costs people the most time. OpenAI’s API defaults response_format to url, so this works there:

# Works against OpenAI. Finds nothing here.
result = client.images.generate(model="...", prompt="...")
print(result.data[0].url)

Against Bayle, omitting response_format returns b64_json, with no url key present at all, so data[0].url is absent rather than empty.

What you send What comes back
response_format: "b64_json" b64_json, bare base64 bytes
response_format: "url" url, holding a base64 data: URI
nothing b64_json. Not url.

Be explicit and the ambiguity disappears.

size, quality, and style are passed to the model as sent, and what they accept depends on the model. So is any field not listed here, so a parameter your model supports that these docs haven’t caught up with still reaches it.

An image large enough to exceed Bayle’s response size limit is refused before any status is committed, so it arrives as a normal error response rather than a truncated body.