Skip to main content
This guide deploys FLUX.2 behind an OpenAI-compatible /v1/images/generations endpoint using Sprocket and Jig. Clients call it with the OpenAI SDK or plain HTTP, with no Together-specific request or response shapes. Two things make a container OpenAI-compatible:
  • HTTP server mode: Run the worker without the --queue flag. Requests go straight to your container and return synchronously, instead of through the managed queue.
  • predict_path: Pass the OpenAI route to sprocket.run(). In HTTP server mode the raw JSON request body is passed straight to predict(), so predict() owns both parsing the OpenAI request and returning the OpenAI response shape.

Prerequisites

  • Together API key: Get one from together.ai.
  • Dedicated containers access: Contact [email protected] to enable it 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]".
  • Hugging Face token: The FLUX.2 weights are gated. Request access to black-forest-labs/FLUX.2-klein-9B.

HTTP server mode vs queue mode

The image generation example serves the same model family through the managed queue. The difference is entirely in how requests are served:

Write the worker

The worker validates the OpenAI Images request with Pydantic, generates the image(s), and returns the OpenAI response shape. The last line sets the endpoint path:
run.py
Three details to note:
  • predict_path sets the route: Without it, the worker serves POST /generate. Setting it to /v1/images/generations is what lets OpenAI clients call the deployment unmodified. The path can’t collide with the reserved /health and /metrics routes.
  • predict() owns the contract: Pydantic rejects bad types, out-of-range n, or an unsupported response_format before generation runs. The returned dict is sent back as the JSON response body, so it must match the OpenAI response shape exactly.
  • b64_json only: Returning base64 keeps the image in the response with no external storage dependency, and it is what gpt-image-1 itself returns. Serving the url response format would require publicly fetchable storage, which this guide doesn’t cover.
To support more of the OpenAI Images API (quality, output_format, output_compression), add the fields to ImageGenerationRequest and map them to pipeline arguments. Pydantic ignores fields you don’t declare, so clients sending extra OpenAI parameters won’t get errors.

Configure the deployment

pyproject.toml
Unlike the queue examples, cmd has no --queue flag. That single difference switches the worker into HTTP server mode. The example also pins one always-on replica so requests never wait for a cold start.

Set the Hugging Face token

The model weights are gated, so the container needs your Hugging Face token at runtime. Store it as a secret:

Deploy

Then get the endpoint URL:
The URL has the form https://api.together.ai/v1/deployment-request/<DEPLOYMENT_NAME>. Requests to any path under it are forwarded to your container, authenticated with your Together API key. Your worker never handles auth.

Call the endpoint

Point any OpenAI client at the endpoint URL plus /v1, using your Together API key:
The response is the standard OpenAI Images shape:

Supported parameters

Any other OpenAI parameter is accepted and ignored, so standard clients work without modification.

Clean up

Delete the deployment when you’re done:

Next steps

Image generation with queues

Serve the same model through the managed queue for async jobs.

Sprocket overview

Understand queue mode, HTTP server mode, and the worker lifecycle.

Sprocket SDK reference

Full reference for sprocket.run(), including predict_path.

Jig CLI reference

All deploy, secrets, and endpoint commands.