Skip to main content
POST
https://gptproto.com
/
v1
/
images
/
generations
grok-2-image (Text To Image)
curl --request POST \
  --url https://gptproto.com/v1/images/generations

Authentication

  1. Sign up for a GPTProto account at https://gptproto.com
  2. Navigate to the API Keys section in your dashboard
  3. Generate a new API key (sk-xxxxx)
  4. 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
}'

{
    "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

ParameterTypeRequiredDefaultRangeDescription
modelstring✅ Yes--Model to be used.
promptstring✅ Yes--Prompt for image generation.
imagestring or file❌ No--base64-encoded data string of the picture or a public URL.
ninteger❌ No11-10The number of images to generate. Must be between 1 and 10.
aspect_ratiostring❌ No1:11: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
Aspect ratio of the generated image. Only supported by grok-imagine models.
response_formatstring❌ Nourlb64_json
url
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 CodeError NameDescription
401UnauthorizedAPI key is missing or invalid
403ForbiddenYour API key doesn’t have permission to access this resource, or insufficient balance for the requested operation
429Too Many RequestsYou’ve exceeded your rate limit
500Internal server errorAn internal server error occurred
503Content policy violationContent blocked due to safety concerns (actual status code is 400)