Authentication
To use the FlyMyAI API, you need to authenticate your requests using your API key. You can find your API key in your profile settings.
Python SDK​
The Python SDK handles authentication automatically when you initialize the client with your API key:
from flymyai import client
# Initialize the client with your API key
fma_client = client(apikey="fly-***")
# Now you can make authenticated requests
response = fma_client.predict(
model="flymyai/flux-dev",
payload={
"prompt": "A beautiful sunset over mountains",
"height": 1024,
"width": 1024
}
)
cURL​
When making direct API calls using cURL, you need to include your API key in the request headers:
curl -X POST https://api.flymy.ai/api/v1/flymyai/flux-schnell/predict \
-H "x-api-key: fly-***" \
-F "prompt=Funny cat with stupid dog" \
-F "height=1024" \
-F "width=1024" \
-F "num_inference_steps=4" \
-F "guidance_scale=0" \
-F "seed=1654"
API Key Security​
- Keep your API key secure and never share it publicly
- Don't commit your API key to version control
- Use environment variables or secure secret management systems to store your API key
- Rotate your API key if you suspect it has been compromised
Rate Limits​
API requests are subject to rate limits based on your subscription plan. You can check your current usage and limits in your profile settings.
Error Handling​
If authentication fails, you'll receive a 401 Unauthorized response. Here's how to handle authentication errors:
from flymyai import client, FlyMyAIPredictException
try:
fma_client = client(apikey="invalid-key")
response = fma_client.predict(...)
except FlyMyAIPredictException as e:
if e.status_code == 401:
print("Authentication failed. Please check your API key.")
else:
print(f"An error occurred: {e}")
# Example of an authentication error response
{
"error": {
"code": "unauthorized",
"message": "Invalid API key"
}
}