图像生成
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": [
{
"role": "assistant",
"level": 1
}
]
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}图像与视频生成
图像生成
使用 GLM-Image 等系列模型从文本提示生成高质量图像。通过对用户文字描述快速、精准的理解,让 AI 的图像表达更加精确和个性化。点击 Try it 按钮可快速试用。
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": [
{
"role": "assistant",
"level": 1
}
]
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}Body
application/json
模型编码
Available options:
glm-image, cogview-4-250304, cogview-4, cogview-3-flash Example:
"glm-image"
所需图像的文本描述
Example:
"一只可爱的小猫咪"
生成图像的质量,glm-image 默认为 hd, 其它默认为 standard。hd: 生成更精细、细节更丰富的图像,整体一致性更高,耗时约20秒;standard: 快速生成图像,适合对生成速度有较高要求的场景,耗时约5-10秒。glm-image 仅支持 hd。
Available options:
hd, standard 图片尺寸,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"
控制AI生成图片时是否添加水印。
true: 默认启用AI生成的显式水印及隐式数字水印,符合政策要求。false: 关闭所有水印,仅允许已签署免责声明的客户使用,签署路径:个人中心-安全管理-去水印管理
Example:
true
终端用户的唯一ID,协助平台对终端用户的违规行为、生成违法及不良信息或其他滥用行为进行干预。ID长度要求:最少6个字符,最多128个字符。
Required string length:
6 - 128Was this page helpful?