Create image
curl --request POST \
--url https://api.together.xyz/v1/images/generations \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "cat floating in space, cinematic",
"model": "stabilityai/stable-diffusion-xl-base-1.0",
"steps": 20,
"seed": 123,
"n": 1,
"height": 1024,
"width": 1024,
"negative_prompt": "<string>"
}
'import requests
url = "https://api.together.xyz/v1/images/generations"
payload = {
"prompt": "cat floating in space, cinematic",
"model": "stabilityai/stable-diffusion-xl-base-1.0",
"steps": 20,
"seed": 123,
"n": 1,
"height": 1024,
"width": 1024,
"negative_prompt": "<string>"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'cat floating in space, cinematic',
model: 'stabilityai/stable-diffusion-xl-base-1.0',
steps: 20,
seed: 123,
n: 1,
height: 1024,
width: 1024,
negative_prompt: '<string>'
})
};
fetch('https://api.together.xyz/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.together.xyz/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'cat floating in space, cinematic',
'model' => 'stabilityai/stable-diffusion-xl-base-1.0',
'steps' => 20,
'seed' => 123,
'n' => 1,
'height' => 1024,
'width' => 1024,
'negative_prompt' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.together.xyz/v1/images/generations"
payload := strings.NewReader("{\n \"prompt\": \"cat floating in space, cinematic\",\n \"model\": \"stabilityai/stable-diffusion-xl-base-1.0\",\n \"steps\": 20,\n \"seed\": 123,\n \"n\": 1,\n \"height\": 1024,\n \"width\": 1024,\n \"negative_prompt\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.together.xyz/v1/images/generations")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"cat floating in space, cinematic\",\n \"model\": \"stabilityai/stable-diffusion-xl-base-1.0\",\n \"steps\": 20,\n \"seed\": 123,\n \"n\": 1,\n \"height\": 1024,\n \"width\": 1024,\n \"negative_prompt\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.together.xyz/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"cat floating in space, cinematic\",\n \"model\": \"stabilityai/stable-diffusion-xl-base-1.0\",\n \"steps\": 20,\n \"seed\": 123,\n \"n\": 1,\n \"height\": 1024,\n \"width\": 1024,\n \"negative_prompt\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"model": "<string>",
"object": "list",
"data": [
{
"index": 123,
"b64_json": "<string>"
}
]
}Images
Create image
Use an image model to generate an image for a given prompt.
POST
/
images
/
generations
Create image
curl --request POST \
--url https://api.together.xyz/v1/images/generations \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "cat floating in space, cinematic",
"model": "stabilityai/stable-diffusion-xl-base-1.0",
"steps": 20,
"seed": 123,
"n": 1,
"height": 1024,
"width": 1024,
"negative_prompt": "<string>"
}
'import requests
url = "https://api.together.xyz/v1/images/generations"
payload = {
"prompt": "cat floating in space, cinematic",
"model": "stabilityai/stable-diffusion-xl-base-1.0",
"steps": 20,
"seed": 123,
"n": 1,
"height": 1024,
"width": 1024,
"negative_prompt": "<string>"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'cat floating in space, cinematic',
model: 'stabilityai/stable-diffusion-xl-base-1.0',
steps: 20,
seed: 123,
n: 1,
height: 1024,
width: 1024,
negative_prompt: '<string>'
})
};
fetch('https://api.together.xyz/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.together.xyz/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'cat floating in space, cinematic',
'model' => 'stabilityai/stable-diffusion-xl-base-1.0',
'steps' => 20,
'seed' => 123,
'n' => 1,
'height' => 1024,
'width' => 1024,
'negative_prompt' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.together.xyz/v1/images/generations"
payload := strings.NewReader("{\n \"prompt\": \"cat floating in space, cinematic\",\n \"model\": \"stabilityai/stable-diffusion-xl-base-1.0\",\n \"steps\": 20,\n \"seed\": 123,\n \"n\": 1,\n \"height\": 1024,\n \"width\": 1024,\n \"negative_prompt\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.together.xyz/v1/images/generations")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"cat floating in space, cinematic\",\n \"model\": \"stabilityai/stable-diffusion-xl-base-1.0\",\n \"steps\": 20,\n \"seed\": 123,\n \"n\": 1,\n \"height\": 1024,\n \"width\": 1024,\n \"negative_prompt\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.together.xyz/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"cat floating in space, cinematic\",\n \"model\": \"stabilityai/stable-diffusion-xl-base-1.0\",\n \"steps\": 20,\n \"seed\": 123,\n \"n\": 1,\n \"height\": 1024,\n \"width\": 1024,\n \"negative_prompt\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"model": "<string>",
"object": "list",
"data": [
{
"index": 123,
"b64_json": "<string>"
}
]
}Authorizations
Body
application/json
A description of the desired images. Maximum length varies by model.
Example:
"cat floating in space, cinematic"
The model to use for image generation.
Example:
"stabilityai/stable-diffusion-xl-base-1.0"
Number of generation steps.
Seed used for generation. Can be used to reproduce image generations.
Number of image results to generate.
Height of the image to generate in number of pixels.
Width of the image to generate in number of pixels.
The prompt or prompts not to guide the image generation.