Skip to main content

Getting Your API Key

1

Create an Account

Sign up at modelslab.com if you haven’t already.
2

Access Dashboard

Navigate to your API Keys Dashboard.
3

Generate Key

Click Create New Key and copy your API key immediately.
4

Store Securely

Save your key in a secure location. You won’t be able to see it again.
Never share your API key publicly or commit it to version control. Treat it like a password.

Using Your API Key

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",
  ...
}

Code Examples

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)

Environment Variables

Always use environment variables to store your API key in production applications.
import os

API_KEY = os.environ.get("MODELSLAB_API_KEY")

Security Best Practices

Use Environment Variables

Never hardcode API keys in your source code. Use environment variables or secret management tools.

Separate Keys

Create different API keys for development, staging, and production environments.

Rotate Regularly

Periodically rotate your API keys, especially if you suspect they may have been compromised.

Monitor Usage

Regularly check your dashboard for unusual API activity.

Authentication Errors

Status CodeError MessageSolution
401Invalid API keyVerify your API key is correct and hasn’t been revoked
401API key requiredInclude the key parameter in your request body
402Insufficient creditsAdd credits to your account or upgrade your plan
403Feature not availableThis feature requires a higher subscription tier
For detailed error handling, see our Error Codes documentation.

API Key Management

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)

Next Steps