Skip to main content
POST
このルートを使用して、Grok画像モデルでテキストから画像を作成します。リクエスト本文ではapplication/jsonを使用します。 model promptとともに必須です。

モデルを選択

Grok画像モデルIDを モデルページから選択します。API例ではgrok-imagine-image-2.0を使用します。 qualitygrok-imagine-image-2.0でのみ利用でき、lowまたはmediumを受け入れます。アプリケーションが特定の品質レベルに依存する場合は、明示的に設定してください。Image 2.0でresolutionを省略すると、CometAPIは1kを使用します。

出力を設定

  • aspect_ratioを使用して出力形状を選択するか、autoを使用してモデルに形状を選択させます。
  • resolutionを使用して、1kまたは2kの出力をリクエストします。
  • nを使用して、1〜10枚の画像をリクエストします。デフォルトは1です。
  • response_formatを使用して、一時URLまたはBase64エンコードされた画像データを返します。
モデル固有の動作については、 xAI画像生成ガイドをご覧ください。.
リクエストの完了後、URL結果を速やかにダウンロードしてください。生成された画像URLは一時的なものです。アプリケーションでAPIレスポンス内の画像バイトが必要な場合は、b64_jsonを使用してください。

承認

Authorization
string
header
必須

Use your CometAPI API key as the bearer value.

ボディ

application/json
model
enum<string>
必須

The Grok image model ID. See the Models page for available model IDs.

利用可能なオプション:
grok-imagine-image,
grok-imagine-image-quality,
grok-imagine-image-2.0
:

"grok-imagine-image-2.0"

prompt
string
必須

A text description of the image to generate.

Minimum string length: 1
:

"A glass observatory above a quiet alpine lake at sunrise"

n
integer
デフォルト:1

The number of images to generate. Use an integer from 1 through 10.

必須範囲: 1 <= x <= 10
aspect_ratio
enum<string>

The output shape. Use auto to let the model select the aspect ratio.

利用可能なオプション:
1:1,
3:4,
4:3,
9:16,
16:9,
2:3,
3:2,
9:19.5,
19.5:9,
9:20,
20:9,
1:2,
2:1,
auto
:

"16:9"

resolution
enum<string>
デフォルト:1k

The requested output resolution. Image 2.0 uses 1k when this field is omitted.

利用可能なオプション:
1k,
2k
:

"1k"

quality
enum<string>

Image quality for grok-imagine-image-2.0. This field is not available for the older Grok image model IDs.

利用可能なオプション:
low,
medium
:

"low"

response_format
enum<string>
デフォルト:url

The image representation in each response item. Use url for a temporary download URL or b64_json for Base64-encoded image bytes.

利用可能なオプション:
url,
b64_json

レスポンス

200 - application/json

The generated image results.

data
object[]
必須

The generated images.

Minimum array length: 1
usage
object

Additional usage metadata returned for the request. Its contents can vary by model.

最終更新日 2026年8月21日