Skip to content

Make images from a script

Pro

You’ll get: a script that writes an image file from a prompt, on your own Mac, through the same gateway as your other apps. Use it for batches, tests or automations.

You need:

  • A local image model in Image Lab. See Create your first image.
  • A client API key that can use the model. Make one in API keys.
  • For curl: jq and base64. For Python: the openai package (pip install openai).

Open Image Lab → Use in your apps to copy these examples with your address and model already in place.

export NEXUS_API_KEY=msty_nexus_key_here

Put your client API key in place of msty_nexus_key_here.

curl http://127.0.0.1:3939/v1/images/generations \
-H "Authorization: Bearer $NEXUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "images/flux-3-image-klein-q4", "prompt": "A red bicycle against a white wall", "size": "1024x1024"}' \
| jq -r '.data[0].b64_json' | base64 --decode > image.png
import base64, os
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:3939/v1", api_key=os.environ["NEXUS_API_KEY"])
result = client.images.generate(
model="images/flux-3-image-klein-q4",
prompt="A red bicycle against a white wall",
size="1024x1024",
)
with open("image.png", "wb") as file:
file.write(base64.b64decode(result.data[0].b64_json))
print("seed", result.data[0].seed)
result = client.images.edit(
model="images/flux-3-image-klein-q4",
image=open("image.png", "rb"),
prompt="Make the bicycle blue",
)

Images from scripts aren’t saved in the Gallery. To save them, send the header:

result = client.images.generate(
model="images/flux-3-image-klein-q4",
prompt="A red bicycle against a white wall",
extra_headers={"X-Msty-Nexus-Image-Gallery": "save"},
)

With curl, add -H "X-Msty-Nexus-Image-Gallery: save".

image.png opens as a picture. With the save header, it also shows in Gallery.

  • A 1024 × 1024 image takes about 100 seconds on an M3 Max. Use 512x512 while you test. Raise the client’s timeout if it gives up early.
  • Run one request at a time per Mac. A request for a different local model while another image is being made gets a busy error (429) with a Retry-After header. Wait and retry.
  • Use a fixed seed (in extra_body for Python) to get the same image again.

All fields and errors: Use images in your apps.