Documentation Index
Fetch the complete documentation index at: https://platform.minimaxi.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
根据文本生成图片
根据详尽的文本描述(prompt),直接生成与之匹配的图片。
import base64
import requests
import os
url = "https://api.minimaxi.com/v1/image_generation"
api_key = os.environ.get("MINIMAX_API_KEY")
headers = {"Authorization": f"Bearer {api_key}"}
payload = {
"model": "image-01",
"prompt": "men Dressing in white t shirt, full-body stand front view image :25, outdoor, Venice beach sign, full-body image, Los Angeles, Fashion photography of 90s, documentary, Film grain, photorealistic",
"aspect_ratio": "16:9",
"response_format": "base64",
}
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
images = response.json()["data"]["image_base64"]
for i in range(len(images)):
with open(f"output-{i}.jpeg", "wb") as f:
f.write(base64.b64decode(images[i]))
生成结果:
结合参考图生成图片
此功能允许提供一张或多张包含清晰主体的参考图(支持网络图片链接),并结合 prompt 描述,生成一张保留了主体特征的新图片。该功能尤其适用于需要保持人物形象一致性的场景,例如为同一个虚拟角色生成不同情境下的图片。
import base64
import requests
import os
url = "https://api.minimaxi.com/v1/image_generation"
api_key = os.environ.get("MINIMAX_API_KEY")
headers = {"Authorization": f"Bearer {api_key}"}
payload = {
"model": "image-01",
"prompt": "女孩在图书馆的窗户前,看向远方",
"aspect_ratio": "16:9",
"subject_reference": [
{
"type": "character",
"image_file": "https://cdn.hailuoai.com/prod/2025-08-12-17/video_cover/1754990600020238321-411603868533342214-cover.jpg",
}
],
"response_format": "base64",
}
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
images = response.json()["data"]["image_base64"]
for i in range(len(images)):
with open(f"output-{i}.jpeg", "wb") as f:
f.write(base64.b64decode(images[i]))
生成结果:
推荐阅读
文生图接口
使用 API 接口,输入文本描述,进行图片生成。
图生图接口
使用 API 接口,输入图片内容,进行图片生成。
速率限制
为保证资源的高效使用,引入速率限制,以确保服务的可用性、稳定性。