> ## Documentation Index
> Fetch the complete documentation index at: https://jigsaw-13.mintlify.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Image Generation

> Generate an image based on the given text by employing AI models like Flux, Stable Diffusion, and other top models.

<Warning>
  <p>
    The image generation API is depracated and no longer being maintained.
  </p>
</Warning>

## Request Parameters

### Body

<ParamField body="prompt" type="string" required>
  The text prompt to generate the image from. Must be between 1-5000 characters.
</ParamField>

<ParamField body="aspect_ratio" type="string" default="1:1">
  The aspect ratio of the generated image.

  <ul>
    <li>`1:1`</li>
    <li>`16:9`</li>
    <li>`21:9`</li>
    <li>`3:2`</li>
    <li>`2:3`</li>
    <li>`4:5`</li>
    <li>`5:4`</li>
    <li>`3:4`</li>
    <li>`4:3`</li>
    <li>`9:16`</li>
    <li>`9:21`</li>
  </ul>
</ParamField>

<ParamField body="width" type="number">
  The width of the image. Must be between 256-1920 pixels.
</ParamField>

<ParamField body="height" type="number">
  The height of the image. Must be between 256-1920 pixels.
</ParamField>

<ParamField body="steps" type="number" default="4">
  The number of denoising steps. Must be between 1-90. Higher values produce better quality images but take more time to generate.
</ParamField>

<ParamField body="output_format" type="string" default="png">
  The output format of the generated image. Must be one of the following values:

  * `png`
  * `svg`
</ParamField>

<ParamField body="url" type="string">
  The image url.
</ParamField>

<ParamField body="file_store_key" type="string">
  The key used to store the image on Jigsawstack file. Learn more about how to handle files in Jigsawstack's [Handling Files](/docs/api-reference/handling-files) section.
</ParamField>

<Info>Passing in files is used for image edits</Info>

<ParamField body="advance_config" type="object">
  <Expandable title="advance_config" defaultOpen="false">
    <ParamField body="negative_prompt" type="string">
      Text describing what you don't want in the image.
    </ParamField>

    <ParamField body="guidance" type="number">
      Higher guidance forces the model to better follow the prompt, but may result in lower quality output. Must be between 1-28.
    </ParamField>

    <ParamField body="seed" type="number">
      Makes generation deterministic. Using the same seed and set of parameters will produce identical image each time.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="return_type" type="string">
  The specified return type for the response

  <ul>
    <li>`url`</li>
    <li>`base64`</li>
    <li>`binary`</li>
  </ul>
</ParamField>

<Snippet file="header.mdx" />

## Response

The API returns the generated image directly in the response body as binary data.

<RequestExample>
  ```javascript Javascript theme={null}
  import { JigsawStack } from "jigsawstack";

  const jigsaw = JigsawStack({ apiKey: "your-api-key" });

  const response = await jigsaw.image_generation({
    "prompt": "A beautiful sunset over a calm ocean",
    "return_type": "url"
  })
  ```

  ```python Python theme={null}
  from jigsawstack import JigsawStack

  jigsaw = JigsawStack(api_key="your-api-key")

  response = jigsaw.image_generation({
    "prompt": "A beautiful sunset over a calm ocean",
    "return_type": "url"
  })
  ```

  ```bash Curl theme={null}
  curl https://api.jigsawstack.com/v1/ai/image_generation \
  -X POST \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: your-api-key' \
  -d '{"prompt":"A beautiful sunset over a calm ocean","return_type":"url"}'
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'https://api.jigsawstack.com/v1/ai/image_generation');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
  'Content-Type: application/json',
  'x-api-key: your-api-key',
  ]);
  curl_setopt($ch, CURLOPT_POSTFIELDS, '{"prompt":"A beautiful sunset over a calm ocean","return_type":"url"}');

  $response = curl_exec($ch);

  curl_close($ch);

  ```

  ```ruby Ruby theme={null}
  require 'net/http'
  require 'json'

  uri = URI('https://api.jigsawstack.com/v1/ai/image_generation')
  req = Net::HTTP::Post.new(uri)
  req.content_type = 'application/json'
  req['x-api-key'] = 'your-api-key'

  req.body = {
  'prompt' => 'A beautiful sunset over a calm ocean',
  'return_type' => 'url'
  }.to_json

  req_options = {
  use_ssl: uri.scheme == 'https'
  }
  res = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
  http.request(req)
  end

  ```

  ```go Go theme={null}
  package main

  import (
  "fmt"
  "io"
  "log"
  "net/http"
  "strings"
  )

  func main() {
  client := &http.Client{}
  var data = strings.NewReader(`{"prompt":"A beautiful sunset over a calm ocean","return_type":"url"}`)
  req, err := http.NewRequest("POST", "https://api.jigsawstack.com/v1/ai/image_generation", data)
  if err != nil {
  	log.Fatal(err)
  }
  req.Header.Set("Content-Type", "application/json")
  req.Header.Set("x-api-key", "your-api-key")
  resp, err := client.Do(req)
  if err != nil {
  	log.Fatal(err)
  }
  defer resp.Body.Close()
  bodyText, err := io.ReadAll(resp.Body)
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Printf("%s\n", bodyText)
  }

  ```

  ```java Java theme={null}
  import java.io.IOException;
  import java.net.URI;
  import java.net.http.HttpClient;
  import java.net.http.HttpRequest;
  import java.net.http.HttpRequest.BodyPublishers;
  import java.net.http.HttpResponse;

  HttpClient client = HttpClient.newHttpClient();

  HttpRequest request = HttpRequest.newBuilder()
  .uri(URI.create("https://api.jigsawstack.com/v1/ai/image_generation"))
  .POST(BodyPublishers.ofString("{\"prompt\":\"A beautiful sunset over a calm ocean\",\"return_type\":\"url\"}"))
  .setHeader("Content-Type", "application/json")
  .setHeader("x-api-key", "your-api-key")
  .build();

  HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

  ```

  ```swift Swift theme={null}
  import Foundation

  let jsonData = [
  "prompt": "A beautiful sunset over a calm ocean",
  "return_type": "url"
  ] as [String : Any]
  let data = try! JSONSerialization.data(withJSONObject: jsonData, options: [])

  let url = URL(string: "https://api.jigsawstack.com/v1/ai/image_generation")!
  let headers = [
  "Content-Type": "application/json",
  "x-api-key": "your-api-key"
  ]

  var request = URLRequest(url: url)
  request.httpMethod = "POST"
  request.allHTTPHeaderFields = headers
  request.httpBody = data as Data

  let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
  if let error = error {
      print(error)
  } else if let data = data {
      let str = String(data: data, encoding: .utf8)
      print(str ?? "")
  }
  }

  task.resume()

  ```

  ```dart Dart theme={null}
  import 'package:http/http.dart' as http;

  void main() async {
  final headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'your-api-key',
  };

  final data = '{"prompt":"A beautiful sunset over a calm ocean","return_type":"url"}';

  final url = Uri.parse('https://api.jigsawstack.com/v1/ai/image_generation');

  final res = await http.post(url, headers: headers, body: data);
  final status = res.statusCode;
  if (status != 200) throw Exception('http.post error: statusCode= $status');

  print(res.body);
  }

  ```

  ```kotlin Kotlin theme={null}
  import java.io.IOException
  import okhttp3.MediaType.Companion.toMediaType
  import okhttp3.OkHttpClient
  import okhttp3.Request
  import okhttp3.RequestBody.Companion.toRequestBody

  val client = OkHttpClient()

  val MEDIA_TYPE = "application/json".toMediaType()

  val requestBody = "{\"prompt\":\"A beautiful sunset over a calm ocean\",\"return_type\":\"url\"}"

  val request = Request.Builder()
  .url("https://api.jigsawstack.com/v1/ai/image_generation")
  .post(requestBody.toRequestBody(MEDIA_TYPE))
  .header("Content-Type", "application/json")
  .header("x-api-key", "your-api-key")
  .build()

  client.newCall(request).execute().use { response ->
  if (!response.isSuccessful) throw IOException("Unexpected code $response")
  response.body!!.string()
  }

  ```

  ```csharp C# theme={null}
  using System.Net.Http.Headers;
  using System.Net.Http.Json;

  HttpClient client = new HttpClient();

  HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://api.jigsawstack.com/v1/ai/image_generation");
  request.Headers.Add("x-api-key", "your-api-key");
  request.Content = JsonContent.Create(new
  {
  prompt = "A beautiful sunset over a calm ocean",
  return_type = "url"
  });
  request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

  HttpResponseMessage response = await client.SendAsync(request);
  response.EnsureSuccessStatusCode();
  string responseBody = await response.Content.ReadAsStringAsync();

  Console.WriteLine(responseBody);
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "success": true,
    "url": "https://jigsawstack-temp.b1e91a466694ad4af04df5d05ca12d93.r2.cloudflarestorage.com/temp/f78349bc-0d35-4461-9a71-496527fcd49f.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=7b9a19349842b7b1a9e4c2e19f05b232%2F20250916%2Fauto%2Fs3%2Faws4_request&X-Amz-Date=20250916T185133Z&X-Amz-Expires=604800&X-Amz-Signature=c995f70db449843f4042bdac278acbbd349a64635e777afb78d7b41a01f7c5f0&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject",
    "_usage": {
          "input_tokens": 18,
          "output_tokens": 77,
          "inference_time_tokens": 2030,
          "total_tokens": 2125
    }
  }
  ```
</ResponseExample>
