Skip to main content
POST
/
paas
/
v4
/
async
/
images
/
generations
图像生成(异步)
curl --request POST \
  --url https://open.bigmodel.cn/api/paas/v4/async/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "glm-image",
  "prompt": "一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云.",
  "size": "1280x1280"
}
'
import requests

url = "https://open.bigmodel.cn/api/paas/v4/async/images/generations"

payload = {
"model": "glm-image",
"prompt": "一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云.",
"size": "1280x1280"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({model: 'glm-image', prompt: '一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云.', size: '1280x1280'})
};

fetch('https://open.bigmodel.cn/api/paas/v4/async/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
HttpResponse<String> response = Unirest.post("https://open.bigmodel.cn/api/paas/v4/async/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"glm-image\",\n \"prompt\": \"一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云.\",\n \"size\": \"1280x1280\"\n}")
.asString();
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://open.bigmodel.cn/api/paas/v4/async/images/generations"

payload := strings.NewReader("{\n \"model\": \"glm-image\",\n \"prompt\": \"一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云.\",\n \"size\": \"1280x1280\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://open.bigmodel.cn/api/paas/v4/async/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'glm-image',
'prompt' => '一只可爱的小猫咪,坐在阳光明媚的窗台上,背景是蓝天白云.',
'size' => '1280x1280'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
{
  "model": "<string>",
  "id": "<string>",
  "request_id": "<string>",
  "task_status": "<string>"
}
{
"error": {
"code": "<string>",
"message": "<string>"
}
}

Authorizations

Authorization
string
header
required

标准的 HTTP Bearer 认证方式,在 API Keys 页面获取密钥。

Body

application/json
model
enum<string>
required

模型编码

Available options:
glm-image
Example:

"glm-image"

prompt
string
required

所需图像的文本描述

Example:

"一只可爱的小猫咪"

quality
enum<string>
default:hd

生成图像的质量。hd: 生成更精细、细节更丰富的图像,整体一致性更高,耗时约20秒;

Available options:
hd
size
string
default:1280x1280

图片尺寸,推荐枚举值:1280x1280 (默认), 1568×1056, 1056×1568, 1472×1088, 1088×1472, 1728×960, 960×1728。 自定义参数:长宽推荐设置在1024px-2048px范围内,并保证最大像素数不超过2^22px;长宽均需为32的整数倍。

Example:

"1280x1280"

watermark_enabled
boolean

控制AI生成图片时是否添加水印。

  • true: 默认启用AI生成的显式水印及隐式数字水印,符合政策要求。
  • false: 关闭所有水印,仅允许已签署免责声明的客户使用,签署路径:个人中心-安全管理-去水印管理
Example:

true

user_id
string

终端用户的唯一ID,协助平台对终端用户的违规行为、生成违法及不良信息或其他滥用行为进行干预。ID长度要求:最少6个字符,最多128个字符。

Required string length: 6 - 128

Response

业务处理成功

model
string

此次调用使用的名称。

id
string

生成的任务ID,调用请求结果接口时使用此ID

request_id
string

用户在客户端请求期间提交的任务编号或平台生成的任务编号。

task_status
string

处理状态,PROCESSING (处理中)SUCCESS (成功)FAIL (失败)。结果需要通过查询获取。