Skip to main content

Generating an image

To query an image model, use the .images method and specify the image model you want to use.
client = Together()

# Generate an image from a text prompt
response = client.images.generate(
    prompt="A serene mountain landscape at sunset with a lake reflection",
    model="black-forest-labs/FLUX.1-schnell",
    steps=4,
)

print(f"Image URL: {response.data[0].url}")
Example response structure and output:
{
  "id": "oFuwv7Y-2kFHot-99170ebf9e84e0ce-SJC",
  "model": "black-forest-labs/FLUX.1-schnell",
  "data": [
    {
      "index": 0,
      "url": "https://api.together.ai/v1/images/...",
      "b64_json": null
    }
  ]
}
Reference image: image-overview1.png

Provide reference image

Use a reference image to guide the generation:
from together import Together

client = Together()

response = client.images.generate(
    model="black-forest-labs/FLUX.1-kontext-pro",
    width=1024,
    height=768,
    prompt="Transform this into a watercolor painting",
    image_url="https://cdn.pixabay.com/photo/2020/05/20/08/27/cat-5195431_1280.jpg",
)
Example output: Reference image: reference_image.png

Supported Models

See our models page for supported image models.

Parameters

ParameterTypeDescriptionDefault
promptstringText description of the image to generateRequired
modelstringModel identifierRequired
widthintegerImage width in pixels1024
heightintegerImage height in pixels1024
nintegerNumber of images to generate (1-4)1
stepsintegerDiffusion steps (higher = better quality, slower)1-50
seedintegerRandom seed for reproducibilityany
negative_promptstringWhat to avoid in generation-
frame_imagesarrayRequired for Kling model. Array of images to guide video generation, like keyframes.-
  • prompt is required for all models except Kling
  • width and height will rely on defaults unless otherwise specified - options for dimensions differ by model
  • Flux Schnell and Kontext [Pro/Max/Dev] models use the aspect_ratio parameter to set the output image size whereas Flux.1 Pro, Flux 1.1 Pro, and Flux.1 Dev use width and height parameters.

Generating Multiple Variations

Generate multiple variations of the same prompt to choose from:
response = client.images.generate(
    prompt="A cute robot assistant helping in a modern office",
    model="black-forest-labs/FLUX.1-schnell",
    n=4,
    steps=4,
)

print(f"Generated {len(response.data)} variations")
for i, image in enumerate(response.data):
    print(f"Variation {i+1}: {image.url}")
Example output: Multiple generated image variations

Custom Dimensions & Aspect Ratios

Different aspect ratios for different use cases:
# Square - Social media posts, profile pictures
response_square = client.images.generate(
    prompt="A peaceful zen garden with a stone path",
    model="black-forest-labs/FLUX.1-schnell",
    width=1024,
    height=1024,
    steps=4,
)

# Landscape - Banners, desktop wallpapers
response_landscape = client.images.generate(
    prompt="A peaceful zen garden with a stone path",
    model="black-forest-labs/FLUX.1-schnell",
    width=1344,
    height=768,
    steps=4,
)

# Portrait - Mobile wallpapers, posters
response_portrait = client.images.generate(
    prompt="A peaceful zen garden with a stone path",
    model="black-forest-labs/FLUX.1-schnell",
    width=768,
    height=1344,
    steps=4,
)
Reference image: dims.png

Quality Control with Steps

Compare different step counts for quality vs. speed:
import time

prompt = "A majestic mountain landscape"
step_counts = [1, 6, 12]

for steps in step_counts:
    start = time.time()
    response = client.images.generate(
        prompt=prompt,
        model="black-forest-labs/FLUX.1-schnell",
        steps=steps,
        seed=42,  # Same seed for fair comparison
    )
    elapsed = time.time() - start
    print(f"Steps: {steps} - Generated in {elapsed:.2f}s")
Reference image: steps.png

Safety Checker

We have a built in safety checker that detects NSFW words but you can disable it by passing in disable_safety_checker=True. This works for every model except Flux Schnell Free and Flux Pro. If the safety checker is triggered and not disabled, it will return a 422 Unprocessable Entity.
from together import Together

client = Together()

response = client.images.generate(
    prompt="a flying cat",
    model="black-forest-labs/FLUX.1-schnell",
    steps=4,
    disable_safety_checker=True,
)

print(response.data[0].url)

Troubleshooting

Image doesn’t match prompt well
  • Make prompt more descriptive and specific
  • Add style references (e.g., “National Geographic style”)
  • Use negative prompts to exclude unwanted elements
  • Try increasing steps to 30-40
Poor image quality
  • Increase steps to 30-40 for production
  • Add quality modifiers: “highly detailed”, “8k”, “professional”
  • Use negative prompt: “blurry, low quality, distorted, pixelated”
  • Try a higher-tier model
Inconsistent results
  • Use seed parameter for reproducibility
  • Keep the same seed when testing variations
  • Generate multiple variations with n parameter
Wrong dimensions or aspect ratio
  • Specify width and height explicitly
  • Common ratios:
    • Square: 1024x1024
    • Landscape: 1344x768
    • Portrait: 768x1344
  • Ensure dimensions are multiples of 8
I