Skip to main content

Python SDK 🐍

Installation 📦

pip install flymyai

Quick Start 🚀

from flymyai import client, FlyMyAIPredictException

# Set your API key
apikey = "fly-***"

# Initialize the client
fma_client = client(apikey=apikey)

# Set the model name
model = "flymyai/hidream-i1-dev"

# Prepare the input data
payload = {
"prompt": "A beautiful sunset over mountains, digital art",
"negative_prompt": "blurry, low quality",
"width": 512,
"height": 512,
"num_inference_steps": 30,
"guidance_scale": 7.5,
"seed": 42
}

try:
# Make the prediction
response = fma_client.predict(
model=model,
payload=payload
)

# Process the output data
print(f"Generated image URL: {response.output_data['image_url']}")
except FlyMyAIPredictException as e:
print(f"Error: {e}")

Advanced Examples 🎯

Image Generation with HiDream

from flymyai import client, FlyMyAIPredictException

apikey = "fly-***"
model = "flymyai/hidream-i1-dev"

payload = {
"prompt": "A futuristic cityscape with flying cars, neon lights, cyberpunk style",
"negative_prompt": "blurry, low quality, distorted",
"width": 768,
"height": 512,
"num_inference_steps": 50,
"guidance_scale": 8.5,
"seed": 12345
}

fma_client = client(apikey=apikey)
try:
response = fma_client.predict(model=model, payload=payload)
print(f"Generated image URL: {response.output_data['image_url']}")
except FlyMyAIPredictException as e:
print(f"Error: {e}")

Video Generation with wan2-img-to-video-lora

from flymyai import client, FlyMyAIPredictException

apikey = "fly-***"
model = "flymyai/wan2-img-to-video-lora"

payload = {
"prompt": "A cinematic shot of a spaceship flying through a nebula",
"negative_prompt": "blurry, low quality, distorted",
"width": 512,
"height": 512,
"num_frames": 24,
"num_inference_steps": 50,
"guidance_scale": 7.5,
"input_image": "https://example.com/input.jpg",
"lora_url": "https://example.com/model.safetensors",
"fps": 8,
"acceleration_factor": 1
}

fma_client = client(apikey=apikey)
try:
response = fma_client.predict(model=model, payload=payload)
print(f"Generated video URL: {response.output_data['video_url']}")
except FlyMyAIPredictException as e:
print(f"Error: {e}")

LoRA Training with flux-lora-trainer

from flymyai import client, FlyMyAIPredictException

apikey = "fly-***"
model = "flymyai/flux-lora-trainer"

payload = {
"lora_name": "Hello World",
"trigger_word": "Hello World",
"dataset_url": "https://example.com/dataset.zip",
"training_steps": 1000,
"huggingface_model_name": "black-forest-labs/FLUX.1-dev"
}

fma_client = client(apikey=apikey)
try:
response = fma_client.predict(model=model, payload=payload)
print(f"Trained model: {response.output_data['model']}")
print(f"Config: {response.output_data['config']}")
except FlyMyAIPredictException as e:
print(f"Error: {e}")

Using Flux Models

from flymyai import client, FlyMyAIPredictException

apikey = "fly-***"
model = "flymyai/flux-dev"

payload = {
"prompt": "A magical forest with glowing mushrooms and fairies",
"height": 512,
"width": 512,
"num_inference_steps": 30,
"guidance_scale": 7.5,
"seed": 42
}

fma_client = client(apikey=apikey)
try:
response = fma_client.predict(model=model, payload=payload)
print(f"Generated image URL: {response.output_data['image_url']}")
except FlyMyAIPredictException as e:
print(f"Error: {e}")

Error Handling 🛡️

The SDK provides detailed error handling through the FlyMyAIPredictException class:

try:
response = fma_client.predict(model=model, payload=payload)
except FlyMyAIPredictException as e:
print(f"Error code: {e.code}")
print(f"Error message: {e.message}")
print(f"Error details: {e.details}")

Best Practices 💡

  1. Always use try-except blocks to handle potential errors
  2. Set appropriate timeouts for long-running operations
  3. Validate input parameters before making API calls
  4. Use environment variables for API keys
  5. Implement proper error logging

Additional Resources 📚