Skip to content

Creates an image given a prompt

client.Images.Generate(ctx, body) (*ImageGenerateResponse, error)
post/images/generations

Creates a high-quality image from a text prompt using GPT-IMAGE-1, the latest image generation model with automatic prompt optimization and enhanced visual capabilities.

ParametersExpand Collapse
body ImageGenerateParams
Prompt param.Field[string]

A text description of the desired image(s). GPT-IMAGE-1 supports up to 32,000 characters and provides automatic prompt optimization for best results.

minLength1
Background param.Field[string]optional

The background setting for the image generation. GPT-IMAGE-1 supports: transparent, opaque, auto.

Model param.Field[string]optional

The model to use for image generation. GPT-IMAGE-1 is the latest model offering the best quality with automatic optimization and enhanced capabilities.

Moderation param.Field[string]optional

The moderation setting for the image generation. GPT-IMAGE-1 supports: low, auto.

N param.Field[int64]optional

The number of images to generate. GPT-IMAGE-1 only supports n=1.

minimum1
OutputCompression param.Field[int64]optional

The output compression for the image generation. GPT-IMAGE-1 supports: 0-100.

minimum0
OutputFormat param.Field[string]optional

The output format for the image generation. GPT-IMAGE-1 supports: png, webp, jpeg.

PartialImages param.Field[int64]optional

The number of partial image chunks to return during streaming generation. This parameter is optional with a default of 0. When stream=true, this must be greater than 0 to receive progressive updates of the image as it's being generated. Higher values provide more frequent updates but may increase response overhead.

minimum0
Quality param.Field[string]optional

The quality of the image that will be generated. GPT-IMAGE-1 supports: auto (automatically select best quality), high, medium, low.

Size param.Field[string]optional

The size of the generated images. GPT-IMAGE-1 supports: auto (automatically select best size), 1536x1024 (landscape), 1024x1536 (portrait).

User param.Field[string]optional

A unique identifier representing your end-user, which can help DigitalOcean to monitor and detect abuse.

maxLength256
ReturnsExpand Collapse
type ImageGenerateResponse struct{…}

The response from the image generation endpoint

Created int64

The Unix timestamp (in seconds) of when the images were created

Data []ImageGenerateResponseData

The list of generated images

B64Json string

The base64-encoded JSON of the generated image. GPT-IMAGE-1 returns images in b64_json format only.

RevisedPrompt stringoptional

The optimized prompt that was used to generate the image. GPT-IMAGE-1 automatically optimizes prompts for best results.

Background stringoptional

The background setting used for the image generation

OutputFormat stringoptional

The output format of the generated image

Quality stringoptional

The quality setting used for the image generation

Size stringoptional

The size of the generated image

Usage ImageGenerateResponseUsageoptional

Usage statistics for the image generation request

InputTokens int64

Number of tokens in the input prompt

TotalTokens int64

Total number of tokens used (input + output)

InputTokensDetails ImageGenerateResponseUsageInputTokensDetailsoptional

Detailed breakdown of input tokens

TextTokens int64optional

Number of text tokens in the input

OutputTokens int64optional

Number of tokens in the generated output

Creates an image given a prompt
package main

import (
  "context"
  "fmt"

  "github.com/stainless-sdks/-go"
  "github.com/stainless-sdks/-go/option"
)

func main() {
  client := gradient.NewClient(
    option.WithModelAccessKey("My Model Access Key"),
  )
  response, err := client.Images.Generate(context.TODO(), gradient.ImageGenerateParams{
    Prompt: gradient.F("A cute baby sea otter floating on its back in calm blue water"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", response.Created)
}
{
  "created": 1677649456,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAAA1BMVEX...",
      "revised_prompt": "A cute baby sea otter floating on its back in calm blue water, captured with professional photography lighting and composition"
    }
  ],
  "background": "opaque",
  "output_format": "png",
  "quality": "high",
  "size": "1024x1024",
  "usage": {
    "input_tokens": 12,
    "total_tokens": 4172,
    "input_tokens_details": {
      "text_tokens": 12
    },
    "output_tokens": 4160
  }
}
Returns Examples
{
  "created": 1677649456,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEAAQMAAABmvDolAAAAA1BMVEX...",
      "revised_prompt": "A cute baby sea otter floating on its back in calm blue water, captured with professional photography lighting and composition"
    }
  ],
  "background": "opaque",
  "output_format": "png",
  "quality": "high",
  "size": "1024x1024",
  "usage": {
    "input_tokens": 12,
    "total_tokens": 4172,
    "input_tokens_details": {
      "text_tokens": 12
    },
    "output_tokens": 4160
  }
}