在 Hermes Agent 中使用 Qwen 2 Image。
Qwen 2 Image 是 Alibaba 的圖像生成和編輯模型。Hermes Agent 透過 RunAPI 自訂 provider 端點呼叫它——發送 prompt,取回圖像 URL。支援透過三個模型版本進行文字轉圖片、圖像編輯和圖像混合。
Use RunAPI to generate an image with Qwen 2 Image.
Requirements:
- Call the RunAPI text_to_image endpoint at https://runapi.ai/api/v1/task/text_to_image.
- Set the model to "qwen-2-text-to-image".
- Read the API key from the RUNAPI_API_KEY environment variable.
- Use the custom:runapi provider configured in Hermes Agent.
- The response returns a task_id. Poll the task status endpoint until the task completes, then retrieve the image URL from the output.
- For image editing, use model "qwen-2-edit-image" and include an image_url field.
- For remixing, use model "qwen-2-remix-image" and include an image_url field.
curl -X POST https://runapi.ai/api/v1/task/text_to_image \
-H "Authorization: Bearer $RUNAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-2-text-to-image",
"prompt": "A traditional Chinese ink painting of misty mountains at dawn, elegant brushwork"
}'
{
"task_id": "tsk_abc123",
"status": "pending",
"model": "qwen-2-text-to-image"
}
三步驟在 Hermes Agent 中使用 Qwen 2 Image
設定 RunAPI
將 RunAPI API key 設定為環境變數。如果你尚未將 RunAPI 新增為 Hermes Agent 自訂 provider,請先參照 Hermes Agent 設定指南,以 base_url https://runapi.ai/v1 新增 custom:runapi。
export RUNAPI_API_KEY=runapi_xxx
呼叫 Qwen 2 Image
將 prompt 貼入 Hermes Agent 或直接呼叫 text_to_image 端點。將 model 欄位設為 qwen-2-text-to-image(生成)、qwen-2-edit-image(編輯)或 qwen-2-remix-image(混合)。
text_to_image
取得結果
端點返回 task ID。輪詢 task status 端點直到狀態變為 completed,然後從輸出中讀取圖像 URL。RunAPI SDK 會自動處理輪詢。
task_id: tsk_abc123
Qwen 2 Image API 參數
| 參數 | 類型 | 說明 |
|---|---|---|
model |
string |
必填。qwen-2-text-to-image、qwen-2-edit-image 或 qwen-2-remix-image。 |
prompt |
string |
文字描述或編輯指令。 |
image_url |
string |
編輯或混合模式的來源圖像。 |
size |
string |
可選。輸出尺寸。 |
Hermes Agent 上的 Qwen 2 Image 是什麼?
Qwen 2 Image 是阿里巴巴的圖像模型,通過單一 API 提供生成、編輯和混合創作三種模式。它能處理複雜的多對象場景,並原生理解中文、英文和混合語言提示詞,特別適合多語言內容工作流程。
Qwen 2 Image 使用場景
agent 工作流中的迭代圖像編輯
在單次 Hermes Agent 運行中串聯多個 Qwen 2 編輯步驟——先生成初始圖像,再依次應用文字引導的修改,如替換背景、調整顏色或添加元素。
初創公司的低成本圖像生成
將 Qwen 2 Image 作為高批量圖像生成任務(產品效果圖、社交媒體內容或開發階段佔位圖)的經濟實惠選擇。
雙語內容製作
無需翻譯即可根據中英文提示詞生成圖像,在單一工作流中為雙語營銷活動或本地化產品頁面產出視覺內容。
Qwen 2 Image + Hermes Agent 常見問題
可以。Hermes Agent 支援自訂 OpenAI 相容 provider。將 RunAPI 新增為 custom:runapi,base_url 設為 https://runapi.ai/v1,key_env 設為 RUNAPI_API_KEY,api_mode 設為 chat_completions。然後以 model 設為 qwen-2-text-to-image 呼叫 text_to_image 端點。
不需要。用於聊天模型的同一個 RUNAPI_API_KEY 亦可呼叫 Qwen 2 Image 及 RunAPI 目錄中的所有其他模型。一個 key,一個餘額,一個控制台。
非同步。端點立即返回 task ID。輪詢 task status 端點或使用 webhook callback 以知悉圖像何時就緒。RunAPI SDK 和 CLI 會自動處理輪詢。
Qwen 2 Image 按任務計費。請查看 RunAPI 收費頁面了解最新價格。無月費訂閱或最低消費——只為完成的生成付費。