生成图片
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)
生成图像
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>"
}创建图像任务。返回
图生图(不传
{ "taskId": "..." }。用 获取任务结果 轮询,直到 status 为 completed。
仅当
model 为 grok-imagine-image-2.0 时才会把 quality 传给上游,其他模型忽略该字段。模型
| 模型 | 说明 |
|---|---|
grok-imagine-image | 标准 |
grok-imagine-image-quality | 更高画质 |
grok-imagine-image-2.0 | 支持 quality 与 1k / 2k |
请求
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
prompt | string | 是 | 描述,最多 5000 字符 |
model | string | 是 | 见上方模型 |
n | number | 否 | 张数 1–10,默认 1 |
aspectRatio | string | 否 | 见下方比例。不传则官方 auto |
resolution | string | 否 | 1k / 2k。不传则官方默认 1k |
quality | string | 否 | low / medium / auto — 仅 2.0 |
images | string[] | 否 | 参考图 URL,最多 5 张。不传 aspectRatio 时输出跟随第一张 |
宽高比
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
示例
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 时尺寸跟随第一张参考图):
curl -X POST "https://api.mountsea.ai/xai/images" \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"prompt": "同一只猫,窗外下雪,电影感光影",
"model": "grok-imagine-image",
"images": ["https://cdn.example.com/ref.jpg"]
}'
授权
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
请求体
application/json
图片描述提示词(最大 5000 字符)
Maximum string length:
5000示例:
"a cute cat sitting on a windowsill"
图片模型
可用选项:
grok-imagine-image, grok-imagine-image-quality, grok-imagine-image-2.0 示例:
"grok-imagine-image"
生成张数,1–10。不传则生成 1 张(与现网一致)
必填范围:
1 <= x <= 10图片宽高比。不传则由模型自行决定(官方 auto)
可用选项:
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
可用选项:
1k, 2k 生成质量,仅 grok-imagine-image-2.0 支持。不传则不向官方传该字段
可用选项:
low, medium, auto 参考图片 URL(图生图 / 编辑图片,最多 5 张)。不传 aspectRatio 时输出尺寸跟随第一张参考图;传入则覆盖
Maximum array length:
5响应
200 - application/json
任务 ID,用于后续查询结果