生成圖片
使用支援嘅模型、文字提示同驗證嘅圖像生成選項,通過 ShareAI 圖像 API 創建圖像。
喺呢頁面
POST
https://api.shareai.now/api/v1/images/generations從文字提示生成圖像。
- 基礎 URL
https://api.shareai.now- 認證
- Bearer API 密鑰或者已批准嘅 OAuth 訪問權杖
使用目前喺 ShareAI 啟用並由你嘅憑證允許嘅圖像模型。模型決定佢支援嘅大小、質量級別同輸出選項。
發送請求#
cURL
curl --fail-with-body --request POST \
"https://api.shareai.now/api/v1/images/generations" \
-H "Authorization: Bearer $SHAREAI_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "YOUR_IMAGE_MODEL",
"prompt": "A quiet forest painted in watercolor.",
"n": 1,
"size": "1024x1024"
}'
Python
import json
import os
import urllib.request
headers = {"Authorization": "Bearer " + os.environ["SHAREAI_API_KEY"]}
headers["Content-Type"] = "application/json"
payload = {'model': 'YOUR_IMAGE_MODEL', 'prompt': 'A quiet forest painted in watercolor.', 'n': 1, 'size': '1024x1024'}
data = json.dumps(payload).encode()
request = urllib.request.Request('https://api.shareai.now/api/v1/images/generations', data=data, headers=headers, method='POST')
with urllib.request.urlopen(request, timeout=180) as response:
print(json.load(response))
TypeScript
const url = "https://api.shareai.now/api/v1/images/generations";
const headers: Record = {
Authorization: `Bearer ${process.env.SHAREAI_API_KEY}`,
};
headers["Content-Type"] = "application/json";
const payload = {
"model": "YOUR_IMAGE_MODEL",
"prompt": "A quiet forest painted in watercolor.",
"n": 1,
"size": "1024x1024"
};
const response = await fetch(url, { method: "POST", headers, body: JSON.stringify(payload) });
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
console.log(await response.json());
請求字段#
| 字段 | 價值 |
|---|---|
model | 一個啟用嘅圖像生成模型 ID。 |
prompt | 一個唔空嘅文字描述。 |
n | 圖像數量,從 1 到 10,受模型支援限制。 |
size / quality | 可選嘅模型支援大小同質量值。 |
response_format / output_format | 可選嘅模型支援回應同文件格式設置。 |
background | 可選嘅模型支援背景設置。 |
閱讀圖像#
檢查返回嘅 data 條目。根據模型同請求嘅格式,一個條目包含 HTTPS 圖像 URL 或 base64 圖像數據。使用實際返回嘅格式;唔好假設每個提供者都返回 URL。API 唔會幫你下載返回嘅圖像 URL。
大小同時間限制#
請求係同步嘅。合併文字限制係 256 KiB,提供者調用限制係 120 秒,回應限制係 2 MiB。大型 base64 圖像可能會超過呢個回應限制。選擇合適嘅輸出大小或者支援 URL 輸出嘅模型。
小心重試#
生成圖像可能會產生使用費用。喺超時或者模糊嘅網絡故障之後,請檢查活動再重試;重複請求可能會生成並收費另一張圖像。API 喺提交到提供者之後唔會自動重試圖像請求。
支援嘅操作#
呢條路徑係從文字生成圖像。圖像編輯、變化、多部分上傳同串流圖像生成唔支援。目前嘅計費需要兼容嘅模型/提供者令牌使用合同;僅按圖像計費嘅提供者可能唔可用。
使用客戶授權#
對於獲批嘅 OAuth 流程,將訪問令牌作為 Bearer 發送。賬戶資助嘅圖像生成需要 surcharge 同接受嘅使用計劃。所有模型、提供者同賬戶限制仍然有效。
最後更新日期:2026年9月15日