For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DocsAPI ReferenceSDKs
DocsAPI ReferenceSDKs
      • Overview
      • Chat Completions
      • Prompt Templates
      • Files & Batches
      • Embeddings
      • Image Generation
      • Responses (Reasoning)
      • Compare (Multi-model)
      • Models
      • Error Handling
LogoLogo
On this page
  • Image Generation
  • Streaming
  • Parameters
Go SDK

Image Generation

||View as Markdown|
Was this page helpful?
Edit this page
Previous

Embeddings

Next

Responses API (Reasoning)

Built with

Image Generation

1model := "openai/gpt-image-1"
2size := "1024x1024"
3quality := "high"
4outputFormat := "webp"
5n := 1
6
7resp, err := client.Images.Generate(ctx, meshapi.ImageGenerationParams{
8 Model: &model,
9 Prompt: "A watercolor of a fox in a snowy forest",
10 N: &n,
11 Size: &size,
12 Quality: &quality,
13 OutputFormat: &outputFormat,
14})
15if err != nil {
16 log.Fatal(err)
17}
18
19if len(resp.Data) > 0 {
20 fmt.Println(*resp.Data[0].URL)
21}

Streaming

1chunkCh, errCh := client.Images.Stream(ctx, meshapi.ImageGenerationParams{
2 Model: &model,
3 Prompt: "A watercolor of a fox in a snowy forest",
4 N: &n,
5 Size: &size,
6 Quality: &quality,
7 OutputFormat: &outputFormat,
8})
9
10for chunk := range chunkCh {
11 if chunk.Status != nil && *chunk.Status == "processing" {
12 fmt.Println("Generating...")
13 } else if len(chunk.Data) > 0 && chunk.Data[0].URL != nil {
14 fmt.Println("Done:", *chunk.Data[0].URL)
15 }
16}
17if err := <-errCh; err != nil {
18 log.Fatal(err)
19}

Parameters

FieldTypeNotes
PromptstringRequired
Model*stringe.g. "openai/gpt-image-1"
N*intNumber of images (1–10)
Size*string"auto", "1024x1024", "WIDTHxHEIGHT"
Quality*string"auto", "low", "medium", "high", "hd", "standard"
ResponseFormat*string"url" or "b64_json"
OutputFormat*string"png", "jpeg", or "webp". OpenAI only
Stream*boolEnable SSE keep-alive streaming