Archive
Image Generation
Generate an image based on the given text by employing AI models like Flux, Stable Diffusion, and other top models.
POST
/
v1
/
ai
/
image_generation
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"
})
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"
})
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
$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);
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
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)
}
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());
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()
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);
}
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()
}
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);
{
"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
}
}
The image generation API is depracated and no longer being maintained.
Request Parameters
Body
string
required
The text prompt to generate the image from. Must be between 1-5000 characters.
string
default:"1:1"
The aspect ratio of the generated image.
1:116:921:93:22:34:55:43:44:39:169:21
number
The width of the image. Must be between 256-1920 pixels.
number
The height of the image. Must be between 256-1920 pixels.
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.
string
default:"png"
The output format of the generated image. Must be one of the following values:
pngsvg
string
The image url.
string
The key used to store the image on Jigsawstack file. Learn more about how to handle files in Jigsawstack’s Handling Files section.
Passing in files is used for image edits
object
Show advance_config
Show advance_config
string
Text describing what you don’t want in the image.
number
Higher guidance forces the model to better follow the prompt, but may result in lower quality output. Must be between 1-28.
number
Makes generation deterministic. Using the same seed and set of parameters will produce identical image each time.
string
The specified return type for the response
urlbase64binary
Header
string
required
Your JigsawStack API key
Response
The API returns the generated image directly in the response body as binary data.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"
})
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"
})
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
$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);
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
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)
}
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());
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()
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);
}
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()
}
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);
{
"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
}
}
Was this page helpful?
⌘I
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"
})
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"
})
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
$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);
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
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)
}
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());
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()
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);
}
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()
}
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);
{
"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
}
}