Generate an image
Generate one or more images from a text prompt.
POST /images/generations
Generate one or more images from a text prompt.
Request body
Content Type: application/json
Response
HTTP 200 — OK
Content Type: application/json
Content Type: text/event-stream
pythonimport osfrom openai import OpenAIclient = OpenAI(base_url="https://api.meta.ai/v1",api_key=os.environ["MODEL_API_KEY"],)response = 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,)print(response.model_dump_json(indent=2))
pythonimport jsonimport osimport requestsresponse = requests.post("https://api.meta.ai/v1/images/generations",headers={"Authorization": f"Bearer {os.environ['MODEL_API_KEY']}","Content-Type": "application/json",},json={"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,},)response.raise_for_status()print(json.dumps(response.json(), indent=2))
shellcurl -X POST "https://api.meta.ai/v1/images/generations" \-H "Authorization: Bearer $MODEL_API_KEY" \-H "Content-Type: application/json" \-d '{"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}'
For prompts, sizing, and worked examples, see the Image generation feature page.