Skip to Content
模型用法MAI Image

MAI Image 系列

透過 OpenAI 相容介面呼叫微軟 MAI Image 系列。文生圖使用 /v1/images/generations,改圖使用 /v1/images/edits。

模型選擇

模型 ID(呼叫時原樣複製)
MAI Image 2.6microsoft/mai-image-2.6
MAI Image 2.6 Flashmicrosoft/mai-image-2.6-flash
MAI Image 2.5 Promicrosoft/mai-image-2.5-pro複雜構圖、人物與物體一致性
MAI Image 2.5microsoft/mai-image-2.5精確的局部修改
MAI Image 2.5 Flashmicrosoft/mai-image-2.5-flash低延遲、批次生成

即時價格:MAI Image 2.6 , MAI Image 2.6 Flash , MAI Image 2.5 。

文生圖

mai_image.py
import base64 from openai import OpenAI client = OpenAI(api_key="YOUR_OFOX_API_KEY", base_url="https://api.ofox.ai/v1", timeout=600) resp = client.images.generate( model="microsoft/mai-image-2.6-flash", prompt="白色桌面上的一顆紅蘋果", size="1024x1024", n=1, ) with open("output.png", "wb") as f: f.write(base64.b64decode(resp.data[0].b64_json))
白色桌面上的一顆紅蘋果
MAI Image 2.6 Flash 實測生成的 1024×1024 PNG。

以下為回應節錄,已省略圖片的 Base64 資料。

{ "data": [ { "b64_json": "BASE64_PNG_OMITTED" } ] }

尺寸(size)

MAI Image 2.5

重點size 僅決定比例,輸出約為 100 萬像素,傳入更大的尺寸不會提高解析度。
請求的 size實際輸出
不傳1024×1024
1024x1024、2048x2048、4096x40961024×1024
1536x10241248×832
1024x1536832×1248
100x100768×768
  • 輸出保留所請求的比例,總像素調整至約 100 萬;傳入過小的尺寸時輸出 768×768。

MAI Image 2.6 / 2.6 Flash

上方範例要求 size="1024x1024",MAI Image 2.6 Flash 在 OfoxAI 實測回傳 1024×1024 PNG。Microsoft Foundry 公布的 2.6 與 2.6 Flash 上限為 2,359,296 像素(相當於 1536×1536)。 Microsoft Foundry 

改圖

Terminal
curl https://api.ofox.ai/v1/images/edits \ --max-time 600 \ -H "Authorization: Bearer $OFOX_API_KEY" \ -F model=microsoft/mai-image-2.5 \ -F prompt="把蘋果改成紫色,其他保持不變" \ -F image=@apple.jpg \ | jq -r '.data[0].b64_json' | base64 --decode > apple_purple.png

在 MAI Image 2.5 範例中,參考圖計入輸入 token,見回應中的 usage.input_tokens_details.image_tokens。實測一張 768×768 的參考圖計 576 個 token。

OfoxAI 目錄列出 MAI Image 2.6 與 2.6 Flash 皆支援 /v1/images/edits。Microsoft Foundry 文件指出這兩款單次編輯最多可傳 5 張 JPEG 或 PNG 參考圖。 Microsoft Foundry 

常見錯誤

錯誤原因處理方式
請求逾時用戶端逾時設定過短將逾時設定為 300 秒以上
404 model_not_found模型 ID 拼寫錯誤從本頁複製模型 ID

需要多張圖片時,請並行發出多次請求,每次生成一張。

常見問題

MAI Image 會輸出多大的圖片?

2.5 在 OfoxAI 的實測尺寸見上表。上方的 2.6 Flash 範例回傳 1024×1024。Microsoft Foundry 為 2.6 系列公布了更高的像素上限。

MAI Image 如何改圖?

使用 /v1/images/edits,以 multipart 表單上傳 image 檔案,寫法與 GPT Image 相同。

最後更新於