Images
You're Claude Code, working in my repository.
Task
Call Meta's images endpoints from my app: POST /v1/images/generations for text to image and POST /v1/images/edits to edit or compose images, decode data[].b64_json into image files, and surface the API's 400 messages.
Read this first
Meta's docs page "Images" as Markdown: https://dev.meta.ai/docs/api-reference/images.md
It's the source of truth for request and response shapes. The same page for people: https://dev.meta.ai/docs/api-reference/images
Setup
- Base URL: https://api.meta.ai/v1
- Auth: send Authorization: Bearer $MODEL_API_KEY, reading MODEL_API_KEY from the environment. Never hard-code, print or commit the key.
- Model: muse-image-1.0
- Python: the OpenAI SDK (pip install openai) with base_url="https://api.meta.ai/v1" and api_key=os.environ["MODEL_API_KEY"] works, or plain requests.
Facts to get right
- Model muse-image-1.0 on both. They're compatible with the OpenAI Images API: client.images.generate and client.images.edit with base_url https://api.meta.ai/v1.
- Both answer an ImagesResponse: {"created", "data": [{"b64_json"} or {"url"}], "output_format", "background": "opaque", "usage"}.
- Edits: the OpenAI SDK sends multipart image parts; over raw HTTP, Meta also takes JSON with images: [{image_url} or {file_id}], 1 to 10 items.
- stream: true answers with server-sent events: image_generation.completed or image_edit.completed, each carrying b64_json.
- $0.01 per image returned, whatever reasoning_strength or tools did.
Starter code (Python)
import base64
import os
from openai import OpenAI
client = OpenAI(base_url="https://api.meta.ai/v1", api_key=os.environ["MODEL_API_KEY"])
generated = client.images.generate(model="muse-image-1.0", prompt="a watercolor painting of a red fox sitting in a snowy pine forest, soft golden morning light", n=1)
with open("fox.webp", "wb") as f:
f.write(base64.b64decode(generated.data[0].b64_json))
with open("fox.webp", "rb") as image:
edited = client.images.edit(
model="muse-image-1.0",
prompt="add a small red wool hat on the fox's head, keep the snowy forest background",
image=image,
n=1,
)
with open("fox-hat.webp", "wb") as f:
f.write(base64.b64decode(edited.data[0].b64_json))
Done when
- A generation saves data[0].b64_json as an image file that opens.
- An edit of that file returns a changed image.
- A bad request (an unknown field such as seed) prints Meta's 400 message.
- The key comes from MODEL_API_KEY and never appears in code, logs or commits.
- API errors (4xx, 429) surface their message instead of failing silently.2,621 characters
The images endpoints generate an image from a text prompt and edit or compose existing images.
For prompts, multi-turn editing, reference images, and worked examples, see the Image generation feature page.
Mirrored from dev.meta.ai/docs/api-reference/images (synced Oct 30, 2026). Text and examples © Meta. Live demos run on Muse Muse's key.