Skip to main content
This example demonstrates deploying a text-to-image model using Dedicated Containers. You’ll build a Sprocket worker that generates images from text prompts and deploy it to Together’s managed GPU infrastructure.

What you’ll learn

  • Deploying a custom model with Sprocket and Jig
  • Returning base64-encoded images from your worker
  • Submitting jobs via the Queue API and polling for results
  • Configuring autoscaling for production workloads

Prerequisites

  • Together API key: Get one from together.ai
  • Dedicated Containers access: Contact [email protected] to enable for your organization
  • Docker: For building container images. Install Docker
  • Together CLI: Install with pip install "together[cli]" --upgrade or uv tool install "together[cli]"
Set your API key:
Install Together library:

Overview

This example deploys a Flux2 text-to-image model as a Dedicated Container. The Sprocket worker handles job processing, and Together manages GPU provisioning, autoscaling, and observability. What gets deployed:
  • A Sprocket worker running on an H100 GPU
  • Queue-based job processing for async image generation
  • Automatic scaling based on queue depth

How it works

  1. Build: Jig builds a Docker image from your pyproject.toml configuration
  2. Push: The image is pushed to Together’s private container registry
  3. Deploy: Together provisions an H100 GPU and starts your container
  4. Queue: Jobs are submitted to the managed queue and processed by your Sprocket worker
  5. Scale: The autoscaler adjusts replicas based on queue depth

Project structure

Implementation

Sprocket Worker Code

Configuration

Key Concepts

Base64 Image Encoding

Images are returned as base64-encoded strings for JSON compatibility:
Decoding on the client:

Generation Parameters

Flux2 supports several parameters to control generation:

Deployment

Deploy

Check Deployment Status

Wait until the deployment shows running and replicas are ready before submitting jobs.

Submit Jobs

Jobs are submitted to the managed queue and processed asynchronously. You’ll need to poll for the result.

Input Parameters

Output

  • image: Base64-encoded PNG image data
  • format: Image format (always "png")
  • encoding: Encoding type (always "base64")

Batch Processing and Autoscaling

The configuration above can be updated to include autoscaling by increasing the max_replicas parameter. Then when the queue backlog grows, more replicas are added automatically. When workers are idle, replicas are removed (down to min_replicas). To scale more aggressively for high-throughput workloads:
To scale to zero when idle, specify min_replicas = 0 (saves costs but adds cold start latency):

Cleanup

When you’re done, delete the deployment:

Next Steps