Skip to content

產生與編輯圖片

圖片 API 支援文字生圖與圖片編輯。模型、尺寸、品質和輸入格式會影響價格;編輯請使用 multipart/form-data,純生成使用 JSON。

  • 使用 /v1/images/generations 建立新圖片,使用 /v1/images/edits 修改輸入圖片。
  • 提交前確認模型支援的 size、quality、張數與檔案限制。
  • 實際扣款以完成的結果和回傳用量為準;失敗工作不應按成功結果收費。

完整範例

原始指南中的可執行範例完整保留如下。請只執行適用於您所用工具和作業系統的區塊。

bash
curl https://nordrouter.com/v1/chat/completions \
  -H "Authorization: Bearer sk-nr-YOUR-KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "google/gemini-3.1-flash-image-preview",
    "modalities": ["image", "text"],
    "messages": [{ "role": "user", "content": "A cozy cabin in the woods, watercolor" }]
  }'
python
from openai import OpenAI

client = OpenAI(base_url="https://nordrouter.com/v1", api_key="sk-nr-YOUR-KEY")

resp = client.chat.completions.create(
    model="google/gemini-3.1-flash-image-preview",
    modalities=["image", "text"],
    messages=[{"role": "user", "content": "A cozy cabin in the woods, watercolor"}],
)
img_b64 = resp.choices[0].message.images[0]["image_url"]["url"]  # data:image/png;base64,...
python
resp = client.chat.completions.create(
    model="google/gemini-3.1-flash-image-preview",
    modalities=["image", "text"],
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "Repaint the car blue and remove the background"},
            {"type": "image_url", "image_url": {"url": "data:image/png;base64,<YOUR-PHOTO>"}},
        ],
    }],
)
bash
curl https://nordrouter.com/v1/images/generations \
  -H "Authorization: Bearer sk-nr-YOUR-KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-image-2",
    "prompt": "Coffee shop logo, minimalist, emerald on white",
    "size": "1024x1024",
    "n": 1
  }'
python
resp = client.images.generate(
    model="openai/gpt-image-2",
    prompt="Coffee shop logo, minimalist, emerald on white",
    size="1024x1024",
)
img_b64 = resp.data[0].b64_json

官方資料與相關連結

Model≈ per imageHow to call
google/gemini-3.1-flash-image-preview (Nano Banana)~$0.012chat + modalities
google/gemini-3-pro-image (Nano Banana Pro)~$0.028chat + modalities
openai/gpt-image-2~$0.001–0.10 (varies by size & quality)/v1/images/generations
Size · qualityOutput tokensPrice
1024×1024 · low~200~$0.0014
1024×1024 · high~7,000~$0.05
1536×1024 · high~10,500~$0.076
2048×2048 · high~14,300~$0.10

相關指南

先以最小文字請求驗證連線,再加入串流、工具呼叫、圖片或其他進階功能。請勿把 API 金鑰寫入公開程式碼或瀏覽器前端。

疑難排解