/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
--queueflag. Requests go straight to your container and return synchronously, instead of through the managed queue. predict_path: Pass the OpenAI route tosprocket.run(). In HTTP server mode the raw JSON request body is passed straight topredict(), sopredict()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]" --upgradeoruv 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
predict_pathsets the route: Without it, the worker servesPOST /generate. Setting it to/v1/images/generationsis what lets OpenAI clients call the deployment unmodified. The path can’t collide with the reserved/healthand/metricsroutes.predict()owns the contract: Pydantic rejects bad types, out-of-rangen, or an unsupportedresponse_formatbefore generation runs. The returned dict is sent back as the JSON response body, so it must match the OpenAI response shape exactly.b64_jsononly: Returning base64 keeps the image in the response with no external storage dependency, and it is whatgpt-image-1itself returns. Serving theurlresponse format would require publicly fetchable storage, which this guide doesn’t cover.
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
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
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:
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.