Skip to main content
POST
/
paas
/
v4
/
images
/
generations
图像生成
curl --request POST \
  --url https://open.bigmodel.cn/api/paas/v4/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/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/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/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/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/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;
}
{
  "created": 123,
  "data": [
    {
      "url": "<string>"
    }
  ],
  "content_filter": [
    {
      "level": 1
    }
  ]
}
{
"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,
cogview-4-250304,
cogview-4,
cogview-3-flash
Example:

"glm-image"

prompt
string
required

所需图像的文本描述

Example:

"一只可爱的小猫咪"

quality
enum<string>
default:hd

生成图像的质量,glm-image 默认为 hd, 其它默认为 standardhd: 生成更精细、细节更丰富的图像,整体一致性更高,耗时约20秒;standard: 快速生成图像,适合对生成速度有较高要求的场景,耗时约5-10秒。glm-image 仅支持 hd

Available options:
hd,
standard
size
string
default:1280x1280

图片尺寸,glm-image 推荐枚举值:1280x1280 (默认), 1568×1056, 1056×1568, 1472×1088, 1088×1472, 1728×960, 960×1728。自定义参数:长宽推荐设置在1024px-2048px范围内,并保证最大像素数不超过2^22px;长宽均需为32的整数倍。 其它模型推荐枚举值:1024x1024 (默认), 768x1344, 864x1152, 1344x768, 1152x864, 1440x720, 720x1440。自定义参数:长宽均需满足512px-2048px之间,需被16整除,并保证最大像素数不超过2^21px

Example:

"1280x1280"

watermark_enabled
boolean

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

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

true

user_id
string

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

Required string length: 6 - 128

Response

业务处理成功

created
integer

请求创建时间,是以秒为单位的Unix时间戳

data
object[]

数组,包含生成的图片URL。目前数组中只包含一张图片。

content_filter
object[]

返回内容安全的相关信息