接口描述
- | 描述 |
|---|---|
接口名稱 | 文本生圖 |
請求路徑 | //wishub-x6.daliqc.cn/v1/images/generations |
功能描述 | 基于提示創建圖像 |
請求參數
請求頭參數
參數 | 示例值 | 描述 |
|---|---|---|
Authorization | Bearer AppKey | 鑒權信息填入AppKey。 |
Content-Type | application/json |
|
請求參數
備注:此參數為全平臺模型通用,每個模型支持的參數、參數范圍可能因模型不同而有所差異,詳細可見模型廣場內每個模型的API文檔。
參數名稱 | 參數類型 | 必選 | 描述 |
|---|---|---|---|
model | string | 是 | 模型ID。 |
prompt | string | 是 | 所需圖像的文本描述,最大長度1000。 |
negative_prompt | string | 否 | 避免生成負面圖像的提示,最大長度1000。 |
n | int | 否 | 要生成的圖像數。 一般取值為1,具體取值范圍、默認值需見對應模型。 |
num_inference_steps | int | 否 | 去噪步驟的數量。去噪步驟越多,通常可以得到更高質量的圖像,但推理速度會變慢。 一般取值范圍 [1, 50],具體取值范圍、默認值需見對應模型。 |
quality | int | 否 | 生成圖像質量。openai參數,一站式智算服務平臺未啟用。 |
size | string | 否 | 輸出的圖像尺寸(高x寬)。 一般取值范圍360x640,480x640,512x512,640x360,640x480,720x1280, 1024x1024,1280x720, 默認值為512x512,具體取值范圍、默認值需見對應模型。 |
response_format | string | 否 | 返回圖像的格式。 一般取值范圍url, b64_json,默認值為b64_json,具體取值范圍、默認值需見對應模型。 |
style | string | 否 | 生成圖像風格。 一般取值范圍standard,portrait,landscape,cartoon,technology,photography,concept, 默認值為standard,具體取值范圍、默認值需見對應模型。 |
user | string | 否 | 用戶唯一身份ID。 |
請求參數示例
{
"model": "bfetrcdggsdfsdf",
"prompt": "A cute baby sea otter",
"n": 1,
"size": "512x512"
}
請求返回
請求正常返回
字段名稱 | 二級字段 | 字段類型 | 描述 |
|---|---|---|---|
created |
| string | Unix時間戳(以秒為單位) |
data |
| array | 圖像列表 |
- | b64_json | string | b64_json 格式圖片 |
- | url | string | url 格式圖片 |
- | revised_prompt | string | 實際使用的修改后的prompt |
返回結果示例
{
"id": "1714459832",
"data": [{
"b64_json": "xxxxxxxxxxxxxxxxxxx"
}]
}
異常返回
異常返回時:
http code 返回非200。
http body 中返回 error 結構,error結構中包含code、type、message、param等信息,具體可見錯誤處理章節內容。
錯誤結果示例
{
"error" : {
"code" : "500001",
"type" : "INVOKE_MODEL_ERROR",
"message" : "服務接口異常,請聯系管理員"
}
}
請求示例代碼
假設一站式智算服務平臺用戶組AppKey=884c8fc4054548a7b1ca1123592f5b7,模型ID=96dcaaaaaaaaaaaa5ff55ea377831a,以此為例進行說明。curl方式請求
curl --request POST \
--url //wishub-x6.daliqc.cn/v1/images/generations \
--header 'Accept: */*' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Authorization: Bearer 884c8fc4054548a7b1ca1123592f5b7' \
--header 'Content-Type: application/json' \
--data '{
"model": "96dcaaaaaaaaaaaa5ff55ea377831a",
"prompt" : "A cute baby sea otter",
"n" : 1,
"size" : "512x512"
}'python方式請求
import json
import requests
URL = "//wishub-x6.daliqc.cn/v1/images/generations"
headers = {
"Authorization": "Bearer 884c8fc4054548a7b1ca1123592f5b7",
"Content-Type": "application/json"
}
data = {
"model": "96dcaaaaaaaaaaaa5ff55ea377831a",
"prompt" : "A cute baby sea otter",
"n" : 1,
"size" : "512x512"
}
try:
response = requests.post(URL, headers=headers, json=data)
if response.status_code != 200:
print(response.json())
else:
b64_file_json = response.json()["data"][0]["b64_json"]
except Exception as e:
print(f"Exception: {e}")openai 客戶端示例代碼
import openai
from openai import OpenAI
client = OpenAI(base_url="//wishub-x6.daliqc.cn/v1", api_key="884c8fc4054548a7b1ca1123592f5b7")
try:
response = client.images.generate(
model="96dcaaaaaaaaaaaa5ff55ea377831a",
prompt="A cute baby sea otter",
)
print(f"{response.data[0].b64_json}")
except openai.APIStatusError as e:
print(f"APIStatusError: {e.status_code}, {e.message}, {e.body}")
except openai.APIError as e:
print(f"APIError: {e.body}")
except Exception as e:
print(f"Exception: {e}")