Skip to main content

Quickstart

Python

Installing Python SDK

pip install flymyai

Getting an API Key

  1. Register on FlyMy.AI
  2. Go to your profile and get your key, username, and project_name

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;
}

More