| title | description |
|---|---|
Authentication |
Learn how to authenticate your ModelsLab API requests. Get your API key, configure headers, and securely integrate ModelsLab AI APIs into your application. |
Include your API key in every request using the key parameter in the request body:
{
"key": "your_api_key_here",
"prompt": "A beautiful sunset over mountains",
...
}import requests
API_KEY = "your_api_key_here" # Use environment variables in production
response = requests.post(
"https://modelslab.com/api/v6/images/text2img",
json={
"key": API_KEY,
"prompt": "A beautiful sunset over mountains",
"model_id": "flux",
"width": 512,
"height": 512
}
)
data = response.json()
print(data)const API_KEY = "your_api_key_here"; // Use environment variables in production
const response = await fetch("https://modelslab.com/api/v6/images/text2img", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
key: API_KEY,
prompt: "A beautiful sunset over mountains",
model_id: "flux",
width: 512,
height: 512
})
});
const data = await response.json();
console.log(data);curl -X POST "https://modelslab.com/api/v6/images/text2img" \
-H "Content-Type: application/json" \
-d '{
"key": "your_api_key_here",
"prompt": "A beautiful sunset over mountains",
"model_id": "flux",
"width": 512,
"height": 512
}'<?php
$apiKey = "your_api_key_here";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://modelslab.com/api/v6/images/text2img");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"key" => $apiKey,
"prompt" => "A beautiful sunset over mountains",
"model_id" => "flux",
"width" => 512,
"height" => 512
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
print_r($data);
?>package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
apiKey := "your_api_key_here"
payload := map[string]interface{}{
"key": apiKey,
"prompt": "A beautiful sunset over mountains",
"model_id": "flux",
"width": 512,
"height": 512,
}
jsonData, _ := json.Marshal(payload)
resp, err := http.Post(
"https://modelslab.com/api/v6/images/text2img",
"application/json",
bytes.NewBuffer(jsonData),
)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result)
}import os
API_KEY = os.environ.get("MODELSLAB_API_KEY")const API_KEY = process.env.MODELSLAB_API_KEY;export MODELSLAB_API_KEY="your_api_key_here"| Status Code | Error Message | Solution |
|---|---|---|
| 401 | Invalid API key | Verify your API key is correct and hasn't been revoked |
| 401 | API key required | Include the key parameter in your request body |
| 402 | Insufficient credits | Add credits to your account or upgrade your plan |
| 403 | Feature not available | This feature requires a higher subscription tier |
You can manage your API keys from the dashboard:
- Create new keys for different applications
- Revoke compromised or unused keys
- View usage statistics per key
- Set rate limits (Enterprise plans)