Quickstart
Python​
Installing Python SDK​
pip install flymyai-client
Getting an API Key​
Example: Fastest Image Generation in the World​
# Install the FlyMyAI package
# pip install flymyai
from flymyai import client, FlyMyAIPredictException
import base64
# Set secret api key. You can find your api key in the profile settings
apikey = "fly-***"
# Set the model name
model = "flymyai/SDXLTurbo"
# Prepare the input data
payload = {
"prompt": "An astronaut riding a rainbow unicorn, cinematic, dramatic, photorealistic",
"negative_prompt": "Dark colors, gloomy atmosphere, horror"
}
# Initialize the client
fma_client = client(apikey=apikey)
try:
response = fma_client.predict(
model=model,
payload=payload
)
# Process the output data
sample_encoded = response.output_data["sample"][0]
sample = base64.b64decode(sample_encoded)
with open(f"sample_output.jpg", "wb") as file:
file.write(sample)
print(f"Saved sample_output.jpg")
except FlyMyAIPredictException as e:
print(e)
raise e
JavaScript​
JavaScript SDK is in development. The following is a placeholder for future usage:
// Example usage (coming soon)
import { flymyai } from 'flymyai-client';
const apikey = 'fly-***';
const model = 'flymyai/SDXLTurbo';
const payload = {
prompt: 'An astronaut riding a rainbow unicorn, cinematic, dramatic, photorealistic',
negative_prompt: 'Dark colors, gloomy atmosphere, horror'
};
const fma_client = flymyai.client(apikey);
try {
const response = await fma_client.predict(model, payload);
const sample_encoded = response.output_data.sample[0];
const sample = atob(sample_encoded);
const blob = new Blob([sample], { type: 'image/jpeg' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'sample_output.jpg';
a.click();
console.log('Saved sample_output.jpg');
} catch (e) {
console.error(e);
throw e;
}