繁中
登入帳號 取得 Pro每月 $15 起$15/月
取得 Pro每月 $15 起$15/月

使用說明 / API 與代理工具

供代理使用的圖片排版 API

請使用原創或風格化角色,或在取得書面同意後使用您本人的形象。任何可識別他人的描繪皆須取得對方書面同意。所有參考圖片、訓練資料、音訊與作品皆須遵守可接受使用政策。

這是一組簡潔的 JSON 介面,讓 LLM 代理(Claude、Codex 或任何支援 HTTP 的工具)完整編排 Ideogram 4 圖片(包含場景、畫面文字、物件區域、字體風格與色彩),完全不需要直接處理模型繁瑣的內部描述詞結構。

您只需以自然語言描述畫面:一個整體場景,加上一組依畫面比例定位的方框。Phosphene 會為您將這些內容轉換為嚴謹的 Ideogram 4 描述結構、進行渲染,並回傳圖片路徑。

本介面與通用的 docs/API.md 相輔相成,兩者皆由同一個面板程序提供服務。

伺服器

  • 基礎網址: http://127.0.0.1:8199
  • 程序: mlx_ltx_panel.py(位於儲存庫根目錄)。描述詞組裝邏輯:ideogram_caption.py。
  • 驗證: 無,僅限本機迴圈存取。
  • 兩個端點: GET /image/agent/schema(規格契約)與 POST /image/agent(驗證/渲染)。

代理程式請先讀取規格契約。 GET /image/agent/schema 會回傳完整的逐欄位規格、描述詞組裝規則以及兩個完整範例。代理程式只需讀取該回應,即可組合出正確的請求。以下摘要主要供人類開發者參考。


方框模型

座標採用相對於畫面尺寸的比例,並以左上角為原點。此設計與長寬比無關,因此不論輸出何種畫面比例,同一個方框都會落在相同的相對位置。

  • x、y:方框的左上角座標(0 = 最左/最上,1 = 最右/最下)。
  • w、h:方框的寬度與高度(佔整體畫面的比例)。
  • (0,0) 為圖片左上角;(1,1) 為右下角。
  • 請保持 x + w ≤ 1 且 y + h ≤ 1;超出邊界的方框會被自動裁切至邊界內(系統會回傳警告,而非錯誤)。

在內部處理時,每個方框都會轉換為 [y_min, x_min, y_max, x_max] 的邊界框,數值為列優先(row-first)的 0..1000 整數。您不需要手動撰寫這種格式,伺服器會自動完成轉換。

請求欄位(POST /image/agent)

欄位型別預設值說明
scenestring無(必填)整體背景、場景與氛圍。請描述畫面世界本身,不要在此寫入要印出的文字。
boxesarray無(必填)已放置的元素清單。純場景渲染可傳入 []。
renderdesign | photodesigndesign = 平面設計/海報/向量風格;photo = 攝影寫實風格。
aspect16:9 | 1:1 | 9:16 | 4:3 | 3:4 | 21:916:916:9=1280×720、1:1=1024×1024、9:16=720×1280、4:3=1024×768、3:4=768×1024、21:9=1280×544。
qualityturbo | default | qualityturbo取樣器品質設定,對應 V4_TURBO_12 / V4_DEFAULT_20 / V4_QUALITY_48。
nint 1 至 41要渲染的候選圖片數量。
seedint-1固定種子碼以利重現結果;-1 = 隨機。當 n>1 時依序為 seed、seed+1……
validate_onlyboolfalse若為 true:不執行渲染,僅回傳組裝好的描述詞與警告。
waitbooltrue若為 true:阻塞等待渲染完成並回傳圖片路徑。若為 false:加入佇列並立即回傳。

方框欄位

欄位型別適用對象說明
typetext | object兩者皆適用text 渲染指定文字;object 渲染所描述的物件。
x、y、w、hnumber 0 至 1兩者皆適用以左上角為原點,依畫面比例計算(見上方說明)。
textstringtext(必填)要實際渲染出來的文字內容。空白的文字方框會被略過。
descstringobject(必填)、text(選填)要渲染的內容描述。用於 text 方框時,會覆蓋自動產生的字體風格/對齊/顏色描述。
styleheadline | subhead | body | caps | script | seriftext排版字體風格。預設為 headline。
alignleft | center | righttext預設為 center。
color#RRGGBBtext不分大小寫,會自動正規化為大寫。無效格式會退回 #FFFFFF。

回應格式

  • validate_only:true → 200 { "ok": true, "caption": {…}, "issues": [warnings]}。
  • wait:true(預設)→ 200 { "ok": true, "caption": {…}, "images": [{"path","url"}], "seconds": N, "job_id": "…"}。在同一主機上開啟每個 url 即可檢視 PNG 圖片。
  • wait:false → 202 { "ok": true, "queued": true, "job_id": "…", "caption": {…}, "where_results_land": "…"}。
  • 錯誤請求 → 400 {"ok": false, "issues": […]}(缺少 scene、object 缺少 desc、n 超出範圍、未知的列舉值、無法渲染任何內容的方框等)。
  • GPU 忙碌/已有渲染作業進行中 → 503(暫時性狀態,請在釋出後重試)。若是 wait:true 的請求,則會直接在佇列中排隊等待。
  • 逾時 → 超過 25 分鐘回傳 504(該作業在佇列中仍可能繼續完成)。

issues 欄位皆為人類可讀的訊息。警告(Warnings)(例如超出畫面邊界裁切、嚴重重疊、無效色彩退回預設值、略過空白文字方框)仍會繼續渲染;**嚴重錯誤(fatal)**子集則會回傳 400。


Curl 範例

1. 驗證版面配置而不渲染(免費且即時)

curl -s http://127.0.0.1:8199/image/agent \
  -H 'Content-Type: application/json' \
  -d '{
    "validate_only": true,
    "scene": "A moody vintage travel poster of a mountain lake at golden hour, warm muted palette",
    "render": "design",
    "aspect": "16:9",
    "boxes": [
      {"type":"text","x":0.08,"y":0.08,"w":0.84,"h":0.18,"text":"LAKE DISTRICT","style":"headline","align":"center","color":"#F5C518"},
      {"type":"text","x":0.30,"y":0.80,"w":0.40,"h":0.10,"text":"Est. 1951","style":"serif","align":"center","color":"#FFFFFF"},
      {"type":"object","x":0.55,"y":0.32,"w":0.35,"h":0.42,"desc":"A small wooden canoe drifting on the still lake"}
    ]
  }'

2. 渲染完整 16:9 海報並等待圖片完成

curl -s http://127.0.0.1:8199/image/agent \
  -H 'Content-Type: application/json' \
  -d '{
    "scene": "A moody vintage travel poster of a mountain lake at golden hour, warm muted palette",
    "render": "design",
    "aspect": "16:9",
    "quality": "turbo",
    "n": 1,
    "wait": true,
    "boxes": [
      {"type":"text","x":0.08,"y":0.08,"w":0.84,"h":0.18,"text":"LAKE DISTRICT","style":"headline","align":"center","color":"#F5C518"},
      {"type":"text","x":0.30,"y":0.80,"w":0.40,"h":0.10,"text":"Est. 1951","style":"serif","align":"center","color":"#FFFFFF"},
      {"type":"object","x":0.55,"y":0.32,"w":0.35,"h":0.42,"desc":"A small wooden canoe drifting on the still lake"}
    ]
  }'
# -> {"ok":true,"job_id":"...","caption":{...},"images":[{"path":".../cand_..._mflux.png","url":"/file?path=..."}],"seconds":...}

3. 提交 9:16 標籤並立即回傳(不阻塞等待)

curl -s http://127.0.0.1:8199/image/agent \
  -H 'Content-Type: application/json' \
  -d '{
    "scene": "A minimalist product label, soft off-white paper texture, centered composition",
    "render": "design",
    "aspect": "9:16",
    "quality": "default",
    "wait": false,
    "boxes": [
      {"type":"text","x":0.10,"y":0.42,"w":0.80,"h":0.16,"text":"COLD BREW","style":"caps","align":"center","color":"#0A0A0A"}
    ]
  }'
# -> 202 {"ok":true,"queued":true,"job_id":"...","caption":{...},"where_results_land":"..."}

讀取規格契約

curl -s http://127.0.0.1:8199/image/agent/schema | python3 -m json.tool

渲染時間預期

實際等待時間約等於一次性模型冷載入時間 + n × 單張圖片取樣時間。面板啟動後的第一張 Ideogram 渲染會較慢,因為系統需要先載入一次模型權重。

quality取樣器速度
turboV4_TURBO_12(約 12 步)最快
defaultV4_DEFAULT_20(約 20 步)適中
qualityV4_QUALITY_48(約 48 步)最慢,細節保真度最高

所有渲染會與面板的其他 GPU 工作(影片、訓練、其他圖片作業)依序排程(serialized)。wait:true 的請求會在進行中的作業後方等待;如果您不想長時間維持連線,請使用 wait:false 並透過 GET /state 輪詢您的 job_id。wait 的逾時上限為 25 分鐘。

注意(Ideogram 權重存取權限): Ideogram 4 在首次使用時會從 Hugging Face 下載受限權重。如果您遇到關於存取被拒的 5xx 錯誤,面板操作員需要在設定中填入 Hugging Face Read 權杖,並且使用同一帳號前往 huggingface.co/ideogram-ai/ideogram-4-fp8 接受授權條款。此設定由操作員在首次使用時進行一次即可。


提供給代理開發者的系統提示詞片段

將以下內容貼入您的代理程式系統提示詞中,即可讓它正確呼叫此端點:

You can generate composed images (posters, labels, text-on-image graphics) with Phosphene's Ideogram 4 agent API at http://127.0.0.1:8199.

ALWAYS start by calling GET /image/agent/schema once — it returns the exact field schema, the rules, and two worked examples. Compose against that.

To make an image, POST JSON to /image/agent with:
  - scene: a plain-language description of the overall background/mood (required).
  - boxes: a list of placed elements (required; [] for a pure-scene image). Each box positions itself by FRACTIONS of the frame with a TOP-LEFT origin: x,y is the top-left corner and w,h the size, each in [0,1]. (0,0)=top-left, (1,1)=bottom-right. Keep x+w<=1 and y+h<=1.
      * text box:   {"type":"text","x","y","w","h","text": "<the literal words>", "style":"headline|subhead|body|caps|script|serif","align":"left|center|right","color":"#RRGGBB"}
      * object box: {"type":"object","x","y","w","h","desc":"<what to render there>"}   (desc is required for objects)
  - render: "design" (graphic/poster) or "photo". aspect: "16:9"|"1:1"|"9:16"|"4:3"|"3:4"|"21:9". quality: "turbo"|"default"|"quality". n: 1-4.

Iterate cheaply with "validate_only": true — it returns the built caption plus warnings without rendering. When the layout looks right, POST again with "wait": true to render and receive image urls. Do NOT hand-write Ideogram's internal caption JSON — the server builds it from your scene+boxes. Max 6 text boxes.
Pro 更快的算圖速度,並搶先體驗新功能。每一份授權都在支持 Phosphene 持續免費。 查看 Pro

來源:公開程式碼庫中的 docs/AGENT_API.md。已於發佈前經本網站審閱。建議修改。