Grok-2-Image - Text To Image - openai
Grok 2 image text to image generation. Create bold, creative, and high-quality AI visuals with a unique edge from your prompts.
POST
/
v1
/
images
/
generations
grok-2-image (Text To Image)
curl --request POST \
--url https://gptproto.com/v1/images/generationsimport requests
url = "https://gptproto.com/v1/images/generations"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://gptproto.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://gptproto.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",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://gptproto.com/v1/images/generations"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://gptproto.com/v1/images/generations")
.asString();require 'uri'
require 'net/http'
url = URI("https://gptproto.com/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyAuthentication
- Sign up for a GPTProto account at https://gptproto.com
- Navigate to the API Keys section in your dashboard
- Generate a new API key (sk-xxxxx)
- Copy and securely store your API key For authentication details, please refer to the Authentication section.
Initiate Request
curl --location 'https://gptproto.com/v1/images/generations' \
--header 'Authorization: GPTPROTO_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"model": "grok-2-image",
"prompt": "a cat.",
"n": 1
}'
const axios = require('axios');
let data = JSON.stringify({
"model": "grok-2-image",
"prompt": "a cat.",
"n": 1
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://gptproto.com/v1/images/generations',
headers: {
'Authorization': 'GPTPROTO_API_KEY',
'Content-Type': 'application/json'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
import requests
import json
url = "https://gptproto.com/v1/images/generations"
payload = json.dumps({
"model": "grok-2-image",
"prompt": "a cat.",
"n": 1
})
headers = {
'Authorization': 'GPTPROTO_API_KEY',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://gptproto.com/v1/images/generations"
method := "POST"
payload := strings.NewReader(`{
"model": "grok-2-image",
"prompt": "a cat.",
"n": 1
}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "GPTPROTO_API_KEY")
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Response Example
Response Example
{
"data": [
{
"url": "https://imgen.x.ai/xai-imgen/xai-tmp-imgen-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.jpeg",
"revised_prompt": "a photograph of a cat wearing a hat, sitting on a wooden surface with a neutral expression. The cat has a mix of gray and white fur, with its front paws resting on the hat, which has a wide brim and a dark color, possibly black or dark gray. The background features a blurred indoor setting with a wooden wall and a hint of a window with natural light filtering through. The lighting is soft and natural, suggesting an indoor environment with ample sunlight. The cat's expression is neutral, with its eyes looking directly at the camera, and its ears are pointed upwards. The hat appears to be made of a soft material, possibly felt, and it covers the top of the cat's head while leaving its face visible. The image has a shallow depth of field, focusing sharply on the cat and the hat while blurring the background. There are no texts visible in the image. The cat's posture is relaxed, with its body slightly turned to the side and its tail not visible in the frame. The overall composition is balanced, with the cat and hat as the central elements, and the background includes a wooden structure that could be part of furniture or a wall."
}
]
}
Parameters
Core Parameters
| Parameter | Type | Required | Default | Range | Description |
|---|---|---|---|---|---|
model | string | ✅ Yes | - | - | Model to be used. |
prompt | string | ✅ Yes | - | - | Prompt for image generation. |
image | string or file | ❌ No | - | - | base64-encoded data string of the picture or a public URL. |
n | integer | ❌ No | 1 | 1-10 | The number of images to generate. Must be between 1 and 10. |
aspect_ratio | string | ❌ No | 1:1 | 1:13:44:39:1616:92:33:29:19.519.5:99:2020:91:22:1auto | Aspect ratio of the generated image. Only supported by grok-imagine models. |
response_format | string | ❌ No | url | b64_jsonurl | Response format to return the image in. Can be url or b64_json. If b64_json is specified, the image will be returned as a base64-encoded string instead of a url to the generated image file. |
Error Codes
Common Error Codes
| Error Code | Error Name | Description |
|---|---|---|
| 401 | Unauthorized | API key is missing or invalid |
| 403 | Forbidden | Your API key doesn’t have permission to access this resource, or insufficient balance for the requested operation |
| 429 | Too Many Requests | You’ve exceeded your rate limit |
| 500 | Internal server error | An internal server error occurred |
| 503 | Content policy violation | Content blocked due to safety concerns (actual status code is 400) |
⌘I

