生成图片
curl --request POST \
--url https://api.mountsea.ai/xai/images \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "a cute cat sitting on a windowsill",
"model": "grok-imagine-image",
"n": 1,
"images": [
"<string>"
]
}
'import requests
url = "https://api.mountsea.ai/xai/images"
payload = {
"prompt": "a cute cat sitting on a windowsill",
"model": "grok-imagine-image",
"n": 1,
"images": ["<string>"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'a cute cat sitting on a windowsill',
model: 'grok-imagine-image',
n: 1,
images: ['<string>']
})
};
fetch('https://api.mountsea.ai/xai/images', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.mountsea.ai/xai/images",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'a cute cat sitting on a windowsill',
'model' => 'grok-imagine-image',
'n' => 1,
'images' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.mountsea.ai/xai/images"
payload := strings.NewReader("{\n \"prompt\": \"a cute cat sitting on a windowsill\",\n \"model\": \"grok-imagine-image\",\n \"n\": 1,\n \"images\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.mountsea.ai/xai/images")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"a cute cat sitting on a windowsill\",\n \"model\": \"grok-imagine-image\",\n \"n\": 1,\n \"images\": [\n \"<string>\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mountsea.ai/xai/images")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"a cute cat sitting on a windowsill\",\n \"model\": \"grok-imagine-image\",\n \"n\": 1,\n \"images\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"taskId": "<string>"
}XAI (Grok)
Generate Image
Text-to-image or image-to-image with Grok Imagine
POST
/
xai
/
images
生成图片
curl --request POST \
--url https://api.mountsea.ai/xai/images \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "a cute cat sitting on a windowsill",
"model": "grok-imagine-image",
"n": 1,
"images": [
"<string>"
]
}
'import requests
url = "https://api.mountsea.ai/xai/images"
payload = {
"prompt": "a cute cat sitting on a windowsill",
"model": "grok-imagine-image",
"n": 1,
"images": ["<string>"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'a cute cat sitting on a windowsill',
model: 'grok-imagine-image',
n: 1,
images: ['<string>']
})
};
fetch('https://api.mountsea.ai/xai/images', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.mountsea.ai/xai/images",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'a cute cat sitting on a windowsill',
'model' => 'grok-imagine-image',
'n' => 1,
'images' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.mountsea.ai/xai/images"
payload := strings.NewReader("{\n \"prompt\": \"a cute cat sitting on a windowsill\",\n \"model\": \"grok-imagine-image\",\n \"n\": 1,\n \"images\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.mountsea.ai/xai/images")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"a cute cat sitting on a windowsill\",\n \"model\": \"grok-imagine-image\",\n \"n\": 1,\n \"images\": [\n \"<string>\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.mountsea.ai/xai/images")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"a cute cat sitting on a windowsill\",\n \"model\": \"grok-imagine-image\",\n \"n\": 1,\n \"images\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"taskId": "<string>"
}Create an image task. Returns
Image-to-image (size follows the first reference if
{ "taskId": "..." }. Poll Get Task Result until status is completed.
quality is only sent upstream when model is grok-imagine-image-2.0. Other models ignore it.Models
| Model | Notes |
|---|---|
grok-imagine-image | Standard |
grok-imagine-image-quality | Higher quality |
grok-imagine-image-2.0 | Supports quality and 1k / 2k |
Request
| Field | Type | Required | Description |
|---|---|---|---|
prompt | string | Yes | Description, max 5000 characters |
model | string | Yes | See models above |
n | number | No | Count 1–10, default 1 |
aspectRatio | string | No | See ratios below. Omit for official auto |
resolution | string | No | 1k / 2k. Omit for official default 1k |
quality | string | No | low / medium / auto — 2.0 only |
images | string[] | No | Reference URLs, max 5. Without aspectRatio, output follows the first image |
Aspect ratios
2:3 3:2 1:1 9:16 16:9 4:3 3:4 2:1 1:2 19.5:9 9:19.5 20:9 9:20 21:9 5:2 auto
Examples
curl -X POST "https://api.mountsea.ai/xai/images" \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"prompt": "a cute cat sitting on a windowsill",
"model": "grok-imagine-image-2.0",
"n": 2,
"aspectRatio": "16:9",
"resolution": "2k",
"quality": "medium"
}'
aspectRatio is omitted):
curl -X POST "https://api.mountsea.ai/xai/images" \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"prompt": "same cat, snowy window, cinematic lighting",
"model": "grok-imagine-image",
"images": ["https://cdn.example.com/ref.jpg"]
}'
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
图片描述提示词(最大 5000 字符)
Maximum string length:
5000Example:
"a cute cat sitting on a windowsill"
图片模型
Available options:
grok-imagine-image, grok-imagine-image-quality, grok-imagine-image-2.0 Example:
"grok-imagine-image"
生成张数,1–10。不传则生成 1 张(与现网一致)
Required range:
1 <= x <= 10图片宽高比。不传则由模型自行决定(官方 auto)
Available options:
2:3, 3:2, 1:1, 9:16, 16:9, 4:3, 3:4, 2:1, 1:2, 19.5:9, 9:19.5, 20:9, 9:20, 21:9, 5:2, auto 图片分辨率,1k / 2k。不传则走官方默认 1k
Available options:
1k, 2k 生成质量,仅 grok-imagine-image-2.0 支持。不传则不向官方传该字段
Available options:
low, medium, auto 参考图片 URL(图生图 / 编辑图片,最多 5 张)。不传 aspectRatio 时输出尺寸跟随第一张参考图;传入则覆盖
Maximum array length:
5Response
200 - application/json
任务 ID,用于后续查询结果