Ship a Full-Stack App with One Prompt

Copy this prompt into your AI coding agent, or open it in one below.

Give this to your AI Create a to-do list app using Puter.js
Tutorials

How to Get a Leonardo.Ai API Key: A Step-by-Step Guide

On this page

This guide shows you how to get a Leonardo.Ai API key. You'll create a Leonardo.Ai account, generate your key, and make your first API call, plus a free alternative for adding Leonardo.Ai models to your web app.

Prerequisites

  • A Google, Canva, or email account, Leonardo.Ai supports multiple sign-in methods
  • A valid payment method for verification (you'll receive $5 in free API credits)
  • Basic familiarity with code (we'll show simple examples)

Step 1: Create Your Leonardo.Ai Account

Go to app.leonardo.ai/api-access. You'll see the sign-up/login page.

Leonardo.Ai sign-up page

You can sign up using various methods including Canva, Google, or email. Once you've completed the setup and signed in, you'll land on the dashboard.

Leonardo.Ai dashboard

Note that Leonardo.Ai requires you to provide a valid payment method as verification. Once verified, you'll receive $5 in free API credits to get started.

Step 2: Open the API Keys Page

From the dashboard, open the API Keys page from the sidebar.

Leonardo.Ai API Keys page

Step 3: Generate Your API Key

Inside the API Keys page, click the + Create New Key button.

Provide a name for your API key and an optional webhook URL.

Leonardo.Ai create new API key dialog Leonardo.Ai API key revealed with copy button

Important: Copy the key immediately. Leonardo.Ai only shows it once. If you lose it, you'll need to generate a new one.

Store it somewhere safe, like a password manager, an .env file, or your platform's secrets manager. Never commit API keys to a public repository.

Step 4: Make Your First API Call

Leonardo.Ai uses a direct REST API for image generation. Here's a quick example using curl to generate an image:

curl --request POST \
     --url https://cloud.leonardo.ai/api/rest/v1/generations \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <YOUR_API_KEY>' \
     --header 'content-type: application/json' \
     --data '
{
  "alchemy": false,
  "height": 1080,
  "modelId": "7b592283-e8a7-4c5a-9ba6-d18c31f258b9",
  "contrast": 3.5,
  "num_images": 4,
  "styleUUID": "111dc692-d470-4eec-b791-3475abac4c46",
  "prompt": "A serene watercolor painting of a mountain lake at sunrise",
  "width": 1920,
  "ultra": false
}
'

The response contains a generationId that you can use to fetch the generated images. For the full set of endpoints and parameters, see Leonardo.Ai's official API docs.

Can You Use the Leonardo.Ai API for Free?

Creating an API key is free, but generating images costs credits. Leonardo.Ai's API runs on a credit system, so each generation draws down a balance you pay for. After you add a payment method for verification, new accounts get free credits to start with. For current rates and credit packages, see Leonardo.Ai's pricing page.

Puter.js offers a different model. With its User-Pays model, you can add Leonardo.Ai models to your app for free: each user covers their own AI usage through their own Puter account, so your cost stays at $0 regardless of how many users you have, with no API key and no backend.

Add Leonardo.Ai models with the browser script tag:

<script src="https://js.puter.com/v2/"></script>
<script>
  puter.ai.txt2img("A serene watercolor painting of a mountain lake at sunrise", {
    model: "leonardoai/lucid-origin"
  }).then(imageElement => {
    document.body.appendChild(imageElement);
  });
</script>

or the npm package:

import { puter } from '@heyputer/puter.js';

const imageElement = await puter.ai.txt2img("A serene watercolor painting of a mountain lake at sunrise", {
  model: "leonardoai/lucid-origin"
});
document.body.appendChild(imageElement);

This fits front-end apps where your users sign into Puter: usage is tied to their accounts, and Puter.js runs in the browser, so it does not replace a server-side key for a backend you control.

Conclusion

To get a Leonardo.Ai API key: sign up at app.leonardo.ai/api-access, add a payment method for verification, then open the API Keys page and click + Create New Key. From there you can make your first image generation API call, or skip the key entirely and add Leonardo.Ai models to a web app for free with Puter.js.

Ship a Full-Stack App with One Prompt

Give this to your AI Build an AI chat app using Puter.js