| title | description |
|---|---|
Quickstart |
Get started with ModelsLab API in under 5 minutes. Generate your first AI image with a simple API call using cURL, Python, or JavaScript. |
This guide will help you make your first API call to ModelsLab and generate an AI image. By the end, you'll have a working integration.
**Time to complete**: 5 minutesWhat you'll need:
- A ModelsLab account (sign up free)
- An API key (get one here)
Choose your preferred language and run the code:
import requests
response = requests.post(
"https://modelslab.com/api/v6/images/text2img",
json={
"key": "YOUR_API_KEY",
"prompt": "A majestic lion in a savanna at sunset, photorealistic, 8k",
"model_id": "flux",
"width": 512,
"height": 512,
"samples": 1,
"num_inference_steps": 30,
"guidance_scale": 7.5
}
)
data = response.json()
print(data)
# If successful, the image URL will be in data["output"]
if data.get("status") == "success":
print(f"Image URL: {data['output'][0]}")const response = await fetch("https://modelslab.com/api/v6/images/text2img", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
key: "YOUR_API_KEY",
prompt: "A majestic lion in a savanna at sunset, photorealistic, 8k",
model_id: "flux",
width: 512,
height: 512,
samples: 1,
num_inference_steps: 30,
guidance_scale: 7.5
})
});
const data = await response.json();
console.log(data);
// If successful, the image URL will be in data.output
if (data.status === "success") {
console.log(`Image URL: ${data.output[0]}`);
}curl -X POST "https://modelslab.com/api/v6/images/text2img" \
-H "Content-Type: application/json" \
-d '{
"key": "YOUR_API_KEY",
"prompt": "A majestic lion in a savanna at sunset, photorealistic, 8k",
"model_id": "flux",
"width": 512,
"height": 512,
"samples": 1,
"num_inference_steps": 30,
"guidance_scale": 7.5
}'When your image is generated successfully:
{
"status": "success",
"generationTime": 2.45,
"id": "abc123-def456",
"output": [
"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/abc123.png"
],
"meta": {
"prompt": "A majestic lion in a savanna at sunset, photorealistic, 8k",
"model_id": "flux",
"width": 512,
"height": 512,
"seed": 12345
}
}Open the URL in output to see your generated image!
For complex generations, you may receive a processing status:
{
"status": "processing",
"id": "abc123-def456",
"eta": 15,
"message": "Your request is being processed"
}If this happens, use the fetch endpoint to check the status:
# Poll for results
fetch_response = requests.post(
f"https://modelslab.com/api/v6/images/fetch/{data['id']}",
json={"key": "YOUR_API_KEY"}
)
print(fetch_response.json())| Parameter | Description | Default |
|---|---|---|
key |
Your API key (required) | - |
prompt |
Text description of the image (required) | - |
model_id |
AI model to use (e.g., "flux", "sdxl") | "flux" |
width |
Image width in pixels (256-1024) | 512 |
height |
Image height in pixels (256-1024) | 512 |
samples |
Number of images to generate (1-4) | 1 |
num_inference_steps |
Quality/detail level (20-50) | 30 |
guidance_scale |
How closely to follow prompt (1-20) | 7.5 |
Now that you've made your first API call, explore more:
Explore all image generation options Create AI-generated videos Generate speech and clone voices Edit and enhance images with AI - Double-check your API key is copied correctly - Ensure you're including it in the `key` field of the request body - Verify your key hasn't been revoked in the dashboard You've hit your queue limit. Wait for current requests to complete or upgrade your plan. See [Rate Limits](/rate-limits) for details. Some generations take longer. Use the async pattern with the fetch endpoint to handle long-running requests. Need help? Join our [Discord community](https://discord.com/invite/modelslab-1033301189254729748) or contact [support@modelslab.com](mailto:support@modelslab.com).