The Image function of the Together Python Library allows you to easily integrate the Together API's image generation functionality into your applications, allowing you to generate images with a single line of code.

See all commands with:

together image --help

Quickstart

Library

Here's an example code block to get started with the complete library:

import together
import base64

together.api_key = "xxxxx"

# generate image 
response = together.Image.create(prompt="Space robots")

# save the first image
image = response["output"]["choices"][0]
with open("spacerobots.png", "wb") as f:
    f.write(base64.b64decode(image["image_base64"]))

Command-line interface

To generate images, simply run:

together image "Space robots"

By default, complete will query runwayml/stable-diffusion-v1-5. You can pick a different model with --model or -m followed by the model string.

When using the CLI, the images are saved with the pattern image-X.png; the prefix can be changes with --output-prefix or -o followed by a string.

For example, to query stabilityai/stable-diffusion-2-1, generate 4 images, and save them to spacerobots-X.png, run:

$ together image --model stabilityai/stable-diffusion-2-1 "Space robots" -r 4 -o spacerobots
Image saved to spacerobots-0.png
Image saved to spacerobots-1.png
Image saved to spacerobots-2.png
Image saved to spacerobots-3.png

Reference

Library

together.Image.create()

  • prompt (string, required) -- A string providing context for the model to complete
  • model (string, optional) -- Model string to query. Default: runwayml/stable-diffusion-v1-5
  • steps (integer, optional) -- Sampling steps is the number of iterations that the model runs to go from random noise to a recognizable image based on the text. Default: 20
  • seed (integer, optional) -- Random seed used for generation. Default: 42
  • results (integer, optional) -- Number of result images to generate. Default: 1
  • height (integer, optional) -- Height of the image to generate in number of pixels. Default: 256
  • width (integer, optional) -- Width of the image to generate in number of pixels. Default: 256

Command-line interface

together image

  • PROMPT (string, required) -- A string providing context for the model to complete
  • --model,-m (string, optional) -- Model string to query. Default: runwayml/stable-diffusion-v1-5
  • --steps (integer, optional) -- Sampling steps is the number of iterations that the model runs to go from random noise to a recognizable image based on the text. Default: 20
  • --seed (integer, optional) -- Random seed used for generation. Default: 42
  • --results,-r (integer, optional) -- Number of result images to generate. Default: 1
  • --height (integer, optional) -- Height of the image to generate in number of pixels. Default: 256
  • --width (integer, optional) -- Width of the image to generate in number of pixels. Default: 256
  • --output-prefix,-o (string, optional) -- Prefix for the file names the output images will be saved to. An image number will be appended to this name. Default: image
  • --raw (bool, optional) -- Indicates whether to output raw image to CLI. Enabling this option does not save the image to disk. Default: False

FAQ

Why do I see a 429 status code error - "No instance started"?

This error is returned by the server if an Inference VM has not been started for the model being queried. To resolve this error, simply navigate to the Playground and start an instance of a model by hitting the "play" button in the model card.

What models are available to generate images with?

See the Models page for a list of image models that can be used for generating images. You can also see these models by navigating to the Playground.