Quickstart
Python​
Installing Python SDK​
pip install flymyai
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​
Installing JavaScript SDK​
npm install flymyai-js-client
or
yarn add flymyai-js-client
Example: Fastest Image Generation in the World​
import { FlyMyAI } from "flymyai-js-client";
import base64 from 'base64-js';
// Initialize the client
const client = new FlyMyAI({ apiKey: "fly-***" });
// Set the model name
const model = "flymyai/SDXLTurbo";
// Prepare the input data
const payload = {
prompt: "An astronaut riding a rainbow unicorn, cinematic, dramatic, photorealistic",
negative_prompt: "Dark colors, gloomy atmosphere, horror"
};
try {
const response = await client.predict(payload, model);
// Process the output data
const sample_encoded = response.output_data["sample"][0];
const sample = base64.toByteArray(sample_encoded);
const blob = new Blob([sample], { type: 'image/jpeg' });
const url = URL.createObjectURL(blob);
// Download the image
const a = document.createElement('a');
a.href = url;
a.download = 'sample_output.jpg';
a.click();
console.log('Saved sample_output.jpg');
} catch (error) {
console.error('Error making prediction:', error);
throw error;
}
Streaming Example​
import { FlyMyAI } from "flymyai-js-client";
const client = new FlyMyAI({ apiKey: "fly-***" });
const model = "flymyai/SDTurboFMAAceleratedH100";
const payload = {
i_prompt: "An astronaut riding a rainbow unicorn, cinematic, dramatic, photorealistic",
i_negative_prompt: "Dark colors, gloomy atmosphere, horror"
};
async function streamPredictions() {
try {
for await (const result of client.stream(payload, model)) {
console.log(
"Streaming result:",
(result.output_data?.output || [])[0] || ""
);
}
} catch (error) {
console.error("Error during streaming:", error);
}
}
streamPredictions();