MixtrainDocs

Models in Mixtrain can be your own code or external models from providers (OpenAI, Anthropic, Fal, Google, Runway, etc.). Use them for image generation, video generation, and other AI tasks.

Quick Start

from mixtrain import Model

model = Model("hunyuan-video")
result = model.run({"prompt": "A cat playing piano"})
print(result.video.url)

Key Concepts

Model Types

  • Your models: Your own code deployed using MixModel
  • External models: Models from OpenAI, Anthropic, Fal, Google, Runway, etc.

Running Models

model = Model("flux-pro")

# Synchronous - blocks until complete
result = model.run({"prompt": "A sunset over mountains"})
print(result.image.url)

# Asynchronous - returns immediately
run_info = model.submit({"prompt": "A dog running"})
print(f"Started run #{run_info['run_number']}")

Batch Processing

Run models on multiple inputs with Model.batch():

from mixtrain import Model

# Single model batch
results = Model.batch(
    models=["flux-pro"],
    inputs_list=[{"prompt": "A sunset"}, {"prompt": "A mountain"}]
)

for r in results.to_dict()["flux-pro"]:
    print(r.image.url)

# Multiple models on same inputs
results = Model.batch(
    models=["flux-pro", "stable-diffusion-xl"],
    inputs_list=[{"prompt": "a cat"}, {"prompt": "a dog"}],
    max_in_flight=50
)

# Access as dict
for model_name, model_results in results.to_dict().items():
    print(f"{model_name}:")
    for r in model_results:
        print(f"  {r.image.url}")

# Or convert to DataFrame
df = results.to_pandas()

Result Types

Model outputs use Mixtrain Types for rich UI rendering:

result = model.run({"prompt": "Generate something"})

result.video   # Video output - .url, .width, .height, .duration_seconds
result.image   # Image output - .url, .width, .height
result.audio   # Audio output - .url, .duration_seconds
result.text    # Text output
result.status  # "completed", "failed", etc.

See Types for all available types.

Building Models

Create your own models with MixModel. Define inputs in the run() method signature:

from mixtrain import MixModel

class ImageClassifier(MixModel):
    def setup(self):
        self.model = self._load_model()

    def run(self, image_url: str, threshold: float = 0.5):
        """Classify an image.

        Args:
            image_url: Image to classify
            threshold: Confidence threshold
        """
        result = self.model.classify(image_url)
        return {"label": result, "confidence": 0.95}

Both calling styles work:

model = ImageClassifier()

# Keyword arguments
result = model.run(image_url="http://...", threshold=0.7)

# Dict input
result = model.run({"image_url": "http://...", "threshold": 0.7})

Next Steps

On this page