Console

Image Generation

Generate images from text descriptions, with support for long text and text rendering, for poster design, illustration, and visual content creation.

Endpoint
POST/v1/images/generations
Model name
moss-image-sft-1.0
  1. Create 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'
  2. 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.

    FieldTypeRequirementDescription
    model: stringRequired

    Model ID. Use the stable model ID for regular calls, or a snapshot model ID when you need to reproduce results from a fixed version.

    prompt: stringRequired

    The text description of the image to generate; a non-empty string of at most 4,000 characters.

    size: stringOptional

    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.

    n: integerOptional

    Number of images to generate; only 1 is supported.

    response_format: stringOptional

    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"
    }
  3. 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.

  4. Get the image result

    On success, read the image address from data[0].url in the response; you can open or download the PNG directly. usage.generated_images, usage.output_width, and usage.output_height report 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.png
  5. Verify success

    Success means you receive the result image URL and can view or download the generated PNG image.

Next steps