0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Microsoft MAI-Image-2 入門 — Arena.ai 3位のAI画像生成APIをPythonで実装する

0
Last updated at Posted at 2026-04-12

はじめに

2026年4月2日、Microsoftは新しいAI画像生成モデル MAI-Image-2 を発表しました。Microsoft Foundry(旧Azure AI Foundry)を通じてAPIアクセスが可能で、Arena.ai リーダーボードでテキスト→画像モデルの第3位に即座にランクインした注目のモデルです。

この記事では、MAI-Image-2の概要・主要機能・スペックを整理し、Microsoft Foundry APIを使ったPython実装例を解説します。

この記事で学べること

  • MAI-Image-2の特徴・主要機能・スペック
  • Microsoft Foundryへのデプロイ手順
  • Python(APIキー認証 / Entra ID認証)での画像生成実装
  • 料金・レート制限・注意点

前提条件

  • Azure サブスクリプション(有効な支払い方法あり)
  • Microsoft Foundry プロジェクトへのアクセス権
  • Python 3.9+

TL;DR

  • MAI-Image-2は2026年4月2日リリース、Arena.ai 3位の高性能テキスト→画像モデル
  • エンドポイント: https://<resource-name>.services.ai.azure.com/mai/v1/images/generations
  • 最大解像度: 1024×1024(縦横それぞれ最小768px)、PNG出力
  • 料金: 入力 $5/1Mトークン、出力 $33/1Mトークン
  • 既存モデル(MAI-Transcribe-1・MAI-Voice-1)と同じFoundryで統合管理可能

MAI-Image-2とは

MAI-Image-2は、Microsoftが自社開発した**拡散ベース(Diffusion-based)**のテキスト→画像生成モデルです。テキストプロンプトを入力として受け取り、段階的にノイズを除去することで高品質な画像を生成します。

競合モデルとの比較

モデル Arena.ai 順位 提供元 特徴
FLUX1.1 [pro] 1位 Black Forest Labs 最高品質・商用利用
Midjourney V7 2位 Midjourney アーティスティック品質
MAI-Image-2 3位 Microsoft フォトリアル・テキスト生成
Imagen 4 4位〜 Google Google エコシステム統合

MAI-Image-2の特筆すべき点は、インバウンドテキスト生成(画像内テキストの精度)とフォトリアルな人物・風景描写が今世代のモデルで大幅に向上した点です。


主要機能・スペック

3つの強み

1. フォトリアリズム

自然な光・正確なスキントーン・生活感のある背景描写に優れ、製品写真・マーケティングビジュアル・ブランドアセットの生成に適しています。

2. インバウンドテキスト生成

インフォグラフィック・スライド・図解など、画像内に文字を含むコンテンツの生成精度が高く、プロンプトの意図を忠実に再現します。Arena.aiの評価でもText Renderingカテゴリで前世代から大幅な改善が確認されています1

3. 複雑なシーン構成

シュルレアリスム的コンセプト・精緻な構図・シネマティックなビジュアルなど、複雑な指示への対応力が向上しています。

モデルスペック

項目
入力形式 テキスト(最大32,000トークン)
出力形式 PNG画像(1枚)
最小解像度 幅・高さともに768px以上
最大総ピクセル数 1,048,576(1024×1024相当)
生成速度 前世代比 2倍以上高速
デプロイ形式 Global Standard

解像度の制約: width × height ≤ 1,048,576 が条件です。768×1365(総ピクセル約1,048,320)のような縦長・横長画像も生成可能です。


デプロイ手順

1. Azure CLIでのデプロイ

az cognitiveservices account deployment create \
  --name <ACCOUNT_NAME> \
  --resource-group <RESOURCE_GROUP> \
  --deployment-name <DEPLOYMENT_NAME> \
  --model-name mai-image-2 \
  --model-format Microsoft \
  --model-version 2026-02-20 \
  --sku-name GlobalStandard \
  --sku-capacity 1

デプロイ可能なリージョン: West Central US、East US、West US、West Europe、Sweden Central、South India

2. 環境変数の設定

export AZURE_ENDPOINT="https://<resource-name>.services.ai.azure.com"
export AZURE_API_KEY="<your-api-key>"
export DEPLOYMENT_NAME="<your-deployment-name>"

APIキーとエンドポイントは、Azure Portal の 「キーとエンドポイント」 セクション、またはFoundry Portal のデプロイ詳細ページで確認できます。


Pythonでの実装

パターン1: APIキー認証

最もシンプルな実装方法です。

pip install requests
import os
import base64
import requests

endpoint = os.environ["AZURE_ENDPOINT"]
api_key = os.environ["AZURE_API_KEY"]
deployment_name = os.environ["DEPLOYMENT_NAME"]

width = 1024
height = 1024

url = f"{endpoint}/mai/v1/images/generations"

payload = {
    "model": deployment_name,
    "prompt": "A photorealistic image of a mountain lake at sunrise, "
              "with mist rising from the water and golden light filtering "
              "through pine trees",
    "width": width,
    "height": height
}

response = requests.post(
    url,
    headers={
        "Content-Type": "application/json",
        "api-key": api_key,
    },
    json=payload,
)
response.raise_for_status()

result = response.json()

# base64デコードしてPNGとして保存
image_data = [
    output
    for output in result.get("data", [])
    if "b64_json" in output
]

if image_data:
    image_base64 = image_data[0]["b64_json"]
    output_path = "output.png"
    with open(output_path, "wb") as f:
        f.write(base64.b64decode(image_base64))
    print(f"画像を保存しました: {output_path}")
else:
    print("予期しないレスポンス形式:", result)

レスポンス形式(JSON):

{
  "data": [
    {
      "b64_json": "<base64エンコードされたPNGデータ>"
    }
  ]
}

パターン2: Microsoft Entra ID認証(推奨)

本番環境ではAPIキーではなくEntra ID(旧Azure AD)トークンを使用することが推奨されます。

pip install azure-identity
import os
import base64
import requests
from azure.identity import DefaultAzureCredential, get_bearer_token_provider

endpoint = os.environ["AZURE_ENDPOINT"]
deployment_name = os.environ["DEPLOYMENT_NAME"]

# Entra IDトークンの取得
token_provider = get_bearer_token_provider(
    DefaultAzureCredential(),
    "https://cognitiveservices.azure.com/.default"
)
token = token_provider()

url = f"{endpoint}/mai/v1/images/generations"

payload = {
    "model": deployment_name,
    "prompt": "A futuristic city skyline at night with neon lights "
              "reflected in wet streets, cinematic style",
    "width": 1024,
    "height": 768  # 横長フォーマット(1024×768=786,432 ≤ 1,048,576)
}

response = requests.post(
    url,
    headers={
        "Content-Type": "application/json",
        "Authorization": f"Bearer {token}",
    },
    json=payload,
)
response.raise_for_status()

result = response.json()
image_base64 = result["data"][0]["b64_json"]

with open("cityscape.png", "wb") as f:
    f.write(base64.b64decode(image_base64))
print("cityscape.png を保存しました")

パターン3: cURL(REST API)

curl -X POST "https://<resource-name>.services.ai.azure.com/mai/v1/images/generations" \
  -H "Content-Type: application/json" \
  -H "api-key: $AZURE_API_KEY" \
  -d '{
      "model": "'"$DEPLOYMENT_NAME"'",
      "prompt": "An infographic showing AI model comparison table with clean typography",
      "width": 1024,
      "height": 1024
    }' \
  | jq -r '.data[0].b64_json' \
  | base64 --decode > output.png

料金・レート制限

料金体系

課金対象 料金
入力トークン(テキストプロンプト) $5.00 / 1Mトークン
出力トークン(画像生成) $33.00 / 1Mトークン

1024×1024の画像1枚の生成コストは、プロンプト長によりますが一般的に数セント程度です。

レート制限(RPM: Requests Per Minute)

ティア RPM
1 9
2 15
3 30
4 45
5 60
6 90

クォータの増加が必要な場合は、クォータ増加リクエストフォームから申請できます。


エラー対処

エラーコード 原因 対処
401 Unauthorized APIキーが無効またはトークン期限切れ Azure Portalでキーを再生成。Entra ID認証の場合はスコープ https://cognitiveservices.azure.com/.default を確認
404 Not Found デプロイ名またはエンドポイントURLが誤っている Foundry Portalの Deployments でデプロイ名・エンドポイントを確認
400 Bad Request width/height が768未満、または総ピクセル数が1,048,576超 解像度制約を確認。width × height ≤ 1,048,576 かつ両辺 ≥ 768
429 Too Many Requests レート制限超過 リトライまたはクォータ増加申請

利用可能なプラットフォーム

MAI-Image-2は開発者向けAPI以外にも、以下のMicrosoftプロダクトへ順次ロールアウト中です:

  • Microsoft Copilot - チャット内での画像生成
  • Bing Image Creator - Web検索連携の画像生成
  • PowerPoint - スライド用画像の自動生成
  • MAI Playground - 無料プレビュー(試用可能)

まとめ

Microsoft MAI-Image-2のポイントをまとめます。

  • Arena.ai 3位: 世界トップクラスの画像生成品質を持つMicrosoft初の本格的テキスト→画像API
  • インバウンドテキスト生成が強力: 図解・インフォグラフィックに最適
  • 実装が簡潔: requests ライブラリのPOSTリクエスト1本で画像生成が完結
  • Foundryで統合管理: MAI-Transcribe-1(文字起こし)・MAI-Voice-1(音声)と同じFoundryプロジェクトで一元管理可能
  • 本番環境ではEntra ID認証推奨: DefaultAzureCredentialで安全な認証

MAI-Image-2はCopilot・Bing・PowerPointへの組み込みを通じて、Microsoftエコシステム全体での普及が進むと予想されます。開発者はFoundry APIを通じて同等の機能をアプリケーションへ組み込めます。

参考リンク

  1. Microsoft Launches MAI-Image-2 — quasa.io

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?