Image Generation
Generate images from text descriptions, with support for long text and text rendering, for poster design, illustration, and visual content creation.
/v1/images/generationsmoss-image-sft-1.0Create an API Key
Open the API Key Management Platform, create an API Key, and save it as an environment variable. Do not write the API Key into client-side code or commit it to a repository.
Environment variable export MOSS_API_KEY='YOUR_API_KEY'Prepare the request input
Provide the text description, the image size, and the model ID. Currently only one image is generated per request, and streaming output is not supported.
FieldTypeRequirementDescriptionModel ID. Use the stable model ID for regular calls, or a snapshot model ID when you need to reproduce results from a fixed version.
The text description of the image to generate; a non-empty string of at most 4,000 characters.
Image size in the format widthxheight. Each side must be 256–2048 and a multiple of 16; the total pixel count must not exceed 2097152.
Number of images to generate; only 1 is supported.
Only url is supported; b64_json is not supported.
Request body { "model": "moss-image-sft-1.0", "prompt": "An orange cat sitting by the window, a garden after the rain outside, soft natural light, warm and delicate photographic style.", "negative_prompt": "nsfw, worst quality, bad anatomy, watermark, jpeg artifact", "size": "1024x1024", "n": 1, "response_format": "url" }Send the image generation request
Send the request to
/v1/images/generations. When generation completes, the endpoint returns JSON.请求示例 curl --max-time 900 -X POST "https://api.mosi.cn/v1/images/generations" \ -H "Authorization: Bearer $MOSS_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "moss-image-sft-1.0", "prompt": "An orange cat sitting by the window, a garden after the rain outside, soft natural light, warm and delicate photographic style.", "negative_prompt": "nsfw, worst quality, bad anatomy, watermark, jpeg artifact", "size": "1024x1024", "n": 1, "response_format": "url" }'The example timeout is 900 seconds; it does not represent a fixed server-side timeout.
Get the image result
On success, read the image address from
data[0].urlin the response; you can open or download the PNG directly.usage.generated_images,usage.output_width, andusage.output_heightreport the number of images actually generated, the image width, and the image height.请求示例 # Replace the example URL with data[0].url curl --fail --location "https://example.com/generated-image.png" \ --output image.pngVerify success
Success means you receive the result image URL and can view or download the generated PNG image.