curl --request POST \
--url https://api.apiyi.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "grok-imagine-image",
"prompt": "A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography"
}
'import requests
url = "https://api.apiyi.com/v1/images/generations"
payload = {
"model": "grok-imagine-image",
"prompt": "A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography"
}
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({
model: 'grok-imagine-image',
prompt: 'A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography'
})
};
fetch('https://api.apiyi.com/v1/images/generations', 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.apiyi.com/v1/images/generations",
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([
'model' => 'grok-imagine-image',
'prompt' => 'A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography'
]),
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.apiyi.com/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"grok-imagine-image\",\n \"prompt\": \"A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography\"\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.apiyi.com/v1/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"grok-imagine-image\",\n \"prompt\": \"A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/v1/images/generations")
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 \"model\": \"grok-imagine-image\",\n \"prompt\": \"A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography\"\n}"
response = http.request(request)
puts response.read_body{
"created": 0,
"data": [
{
"url": "<string>",
"b64_json": "<string>"
}
],
"usage": {
"prompt_tokens": 1000,
"total_tokens": 1000
}
}Grok Imagine 공식 텍스트 투 이미지 API 레퍼런스
Grok Imagine 공식 텍스트 투 이미지 API 레퍼런스 및 실시간 테스트 — 3개 모델, 1k / 1.5k / 2k 해상도 등급, 2.0의 low / medium 품질, 등급별 xAI와 동일한 가격 책정
curl --request POST \
--url https://api.apiyi.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "grok-imagine-image",
"prompt": "A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography"
}
'import requests
url = "https://api.apiyi.com/v1/images/generations"
payload = {
"model": "grok-imagine-image",
"prompt": "A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography"
}
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({
model: 'grok-imagine-image',
prompt: 'A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography'
})
};
fetch('https://api.apiyi.com/v1/images/generations', 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.apiyi.com/v1/images/generations",
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([
'model' => 'grok-imagine-image',
'prompt' => 'A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography'
]),
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.apiyi.com/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"grok-imagine-image\",\n \"prompt\": \"A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography\"\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.apiyi.com/v1/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"grok-imagine-image\",\n \"prompt\": \"A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/v1/images/generations")
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 \"model\": \"grok-imagine-image\",\n \"prompt\": \"A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography\"\n}"
response = http.request(request)
puts response.read_body{
"created": 0,
"data": [
{
"url": "<string>",
"b64_json": "<string>"
}
],
"usage": {
"prompt_tokens": 1000,
"total_tokens": 1000
}
}GrokOfficial 그룹 필요: Grok Imagine Official은 Default 그룹에 포함되어 있지 않으므로, 호출하기 전에(이 페이지의 Playground 포함) 접근 권한을 신청해야 합니다. 접근 권한이 없거나 요청당 과금 Token을 사용하는 경우 모든 호출에서 503이 반환됩니다. 자세한 내용은 Grok Imagine Official 개요 - 그룹 설정을 참조하십시오.Bearer sk-xxx), prompt을 입력한 뒤 모델, resolution 및 aspect_ratio(2.0의 경우 quality 추가)을 선택하고 전송하십시오.size가 아닌resolution을 사용하십시오:size은 해상도 티어에 매핑되지 않으므로 이미지는 기본값인1k으로 생성되며 이에 따라 과금됩니다.- 잘못된 입력 시 오류 반환: 범위를 벗어난
resolution/aspect_ratio은 422를 반환하고quality: "high"은 400을 반환합니다. 이는 리버스 채널의 사일런트 폴백(silent fallback) 방식과 정반대입니다. - 항상
n= 1로 전송하십시오: 여러 장의 이미지가 필요한 경우 여러 요청을 동시에 전송하십시오.
medium 및 2K 환경의 grok-imagine-image-2.0은 약 60~80초가 소요되므로 클라이언트 타임아웃을 360초로 설정하십시오. 자세한 내용은 이미지 API 주의 사항 및 모범 사례를 참조하십시오.코드 예제
Python (OpenAI SDK)
from openai import OpenAI
import urllib.request
client = OpenAI(
api_key="sk-your-api-key",
base_url="https://api.apiyi.com/v1",
timeout=360.0 # the image API is synchronous; give it a generous timeout
)
resp = client.images.generate(
model="grok-imagine-image-2.0",
prompt="A photorealistic red wooden boat moored on a glassy alpine lake at dawn, "
"mist over the water, snow-capped peaks behind, cinematic photography",
n=1,
# resolution / aspect_ratio / quality are not standard OpenAI SDK fields; put them in extra_body
extra_body={
"resolution": "1.5k",
"aspect_ratio": "16:9",
"quality": "medium"
}
)
# The default response is an image link; download and store it right away
urllib.request.urlretrieve(resp.data[0].url, "out.png")
Python (requests)
import requests
import base64
API_KEY = "sk-your-api-key"
response = requests.post(
"https://api.apiyi.com/v1/images/generations",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
},
json={
"model": "grok-imagine-image-quality",
"prompt": "Rainy cyberpunk city at night, close-up of neon signs, cinematic lighting",
"n": 1,
"resolution": "2k",
"aspect_ratio": "9:16",
"response_format": "b64_json"
},
timeout=360
).json()
# b64_json is plain base64 (no data: prefix); decode and write it
with open("out.png", "wb") as f:
f.write(base64.b64decode(response["data"][0]["b64_json"]))
cURL
curl -X POST "https://api.apiyi.com/v1/images/generations" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-image",
"prompt": "An orange cat in sunglasses sitting at a beach bar, photorealistic, warm sunset",
"n": 1,
"resolution": "1k",
"aspect_ratio": "3:2"
}'
Node.js (fetch)
import fs from 'node:fs';
// Need 3 images: send 3 requests concurrently, each with n=1
const prompts = Array(3).fill('A serene Japanese garden with cherry blossoms, koi pond, golden hour');
const results = await Promise.all(prompts.map(prompt =>
fetch('https://api.apiyi.com/v1/images/generations', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-your-api-key'
},
body: JSON.stringify({
model: 'grok-imagine-image-2.0',
prompt,
n: 1,
resolution: '1k',
aspect_ratio: '4:3',
quality: 'low'
}),
signal: AbortSignal.timeout(360000)
}).then(r => r.json())
));
for (const [i, data] of results.entries()) {
const img = await fetch(data.data[0].url);
fs.writeFileSync(`out-${i}.img`, Buffer.from(await img.arrayBuffer()));
}
파라미터 빠른 참조
| 파라미터 | 타입 | 필수 여부 | 기본값 | 참고사항 |
|---|---|---|---|---|
model | string | ✅ | — | grok-imagine-image / grok-imagine-image-quality / grok-imagine-image-2.0 |
prompt | string | ✅ | — | 모든 언어의 prompt를 지원합니다. 피사체, 장면, 스타일, 조명을 설명합니다 |
n | integer | ❌ | 1 | 이 채널에서는 항상 1입니다. 추가 생성이 필요한 경우 동시에 호출하십시오 |
resolution | string | ❌ | 1k | 1k / 1.5k / 2k(소문자), 가격 등급을 설정하며 범위를 벗어난 값은 422를 반환합니다 |
aspect_ratio | string | ❌ | 1:1 | 일반적인 값: 1:1 / 16:9 / 9:16 / 4:3 / 3:4 / 3:2 / 2:3, 범위를 벗어난 값은 422를 반환합니다 |
quality | string | ❌ | low | grok-imagine-image-2.0 전용: low 또는 medium, high은 400을 반환합니다 |
response_format | string | ❌ | url | url은 이미지 링크를 반환하고, b64_json는 순수 base64를 반환합니다(data: 접두사 없음) |
| 모델 | 1k | 1.5k | 2k |
|---|---|---|---|
grok-imagine-image | $0.02 | $0.02 | $0.02 |
grok-imagine-image-quality | $0.05 | $0.06 | $0.07 |
grok-imagine-image-2.0 (low) | $0.04 | $0.05 | $0.06 |
grok-imagine-image-2.0 (medium) | $0.06 | $0.07 | $0.08 |
응답 형식
{
"created": 0,
"data": [
{ "url": "https://.../sync_xxxxxxxx_0.png" }
],
"usage": {
"prompt_tokens": 1000,
"total_tokens": 1000
}
}
data[]의 각 항목에는response_format에 따라url또는b64_json중 하나가 포함됩니다.- 반환된 이미지 링크는 즉시 다운로드하십시오. 해당 링크를 계속해서 참조하지 마십시오.
usage은 자리표시자(prompt_tokens은 항상1000 × image count)이며 대조 목적으로 사용할 수 없습니다 — 콘솔 과금 내역이 공식 기준입니다.created은 항상 0이므로 시간 측정용으로 사용하지 마십시오.
관련 문서
- Grok Imagine 공식 개요 - 요금, 그룹 적용, 공식 vs 리버스
- Grok Imagine 동영상 - 동일 그룹, 초당 과금
- Grok Imagine 리버스 - 이미지 편집 및 호출당 다중 이미지 생성
인증
API Key from the APIYI console (Token group must include GrokOfficial)
본문
Model ID:
grok-imagine-image— standard, $0.02 per image at every resolutiongrok-imagine-image-quality— high quality, $0.05 / $0.06 / $0.07 at 1k / 1.5k / 2kgrok-imagine-image-2.0— newer model,low$0.04 / $0.05 / $0.06,medium$0.06 / $0.07 / $0.08
grok-imagine-image, grok-imagine-image-quality, grok-imagine-image-2.0 Prompt in any language. Describe the subject, scene, style, and lighting in detail
"A photorealistic red wooden boat moored on a glassy alpine lake at dawn, mist over the water, snow-capped peaks behind, cinematic photography"
Image count. Fixed at 1 on this channel; call concurrently for more images
1 Resolution tier (lowercase), which also sets the price: 1k (default) / 1.5k / 2k.
Out-of-range values (such as 4k or 1K) return 422. Do not use size instead — it is not mapped to a resolution tier.
1k, 1.5k, 2k Output aspect ratio, default 1:1. Measured examples: grok-imagine-image at 1k + 3:2 outputs 1248×832; -quality at 2k + 9:16 outputs 1584×2816.
Out-of-range values (such as 5:7) return 422.
1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3 Quality tier, only for grok-imagine-image-2.0: low (default) or medium ($0.02 more per image, slower).
high returns 400. The other two models take no quality.
low, medium Response format: url (default; download and store the image right away) or b64_json (plain base64, no data: prefix)
url, b64_json 응답
Image generated successfully
이 페이지가 도움이 되었나요?