Guide

AI Agents as NFT Creators: Generate, Mint, and Trade NFTs Autonomously

Purple Flea Research ยท March 6, 2026 ยท 7 min read

Agents as Autonomous Creators

The combination of AI-generated art and autonomous on-chain execution creates a genuinely new business model: the agent-as-creator. An AI agent can generate a unique piece of digital art using Stable Diffusion, pin it permanently to IPFS, mint it as an ERC-721 NFT on Base for under $0.10 in gas fees, list it on OpenSea, and collect royalties from secondary sales โ€” entirely without human intervention.

This is not theoretical. The infrastructure to do all of this exists today and is accessible via API. An agent running on Purple Flea's infrastructure can execute this full pipeline in under 60 seconds per NFT. At scale, an agent minting 100 NFTs per day with a 10% sell-through rate and 5% royalty on secondary sales becomes a meaningful income stream.

The NFT Agent Stack

A full autonomous NFT operation has five layers:

Step 1 โ€” Generate Unique Art

Each NFT in a collection needs to be distinct but cohesive. The standard approach is to define a set of traits (background, foreground element, style, color palette) and sample from them to generate combinations. Rarity is built in: some trait combinations are more common, others rare.

An agent can use the Stable Diffusion API or Replicate to generate the artwork. The generation prompt should encode the selected traits:

import replicate
import random

TRAITS = {
    "background": ["cosmic purple", "deep ocean", "neon city", "forest dusk"],
    "subject": ["geometric flea", "abstract agent", "digital butterfly", "data crystal"],
    "style": ["oil painting", "vaporwave", "minimalist", "watercolor"],
    "palette": ["purple and gold", "cyan and black", "emerald and white"]
}

def generate_nft_metadata() -> dict:
    """Sample traits and generate metadata for one NFT."""
    selected = {trait: random.choice(options) for trait, options in TRAITS.items()}

    prompt = (f"{selected['subject']}, {selected['style']} style, "
              f"{selected['background']} background, "
              f"{selected['palette']} color palette, "
              f"high quality digital art, 4k, detailed")

    output = replicate.run(
        "stability-ai/sdxl:latest",
        input={"prompt": prompt, "width": 1024, "height": 1024, "num_outputs": 1}
    )

    image_url = output[0]
    return {"traits": selected, "prompt": prompt, "image_url": image_url}

Step 2 โ€” Upload to IPFS and Prepare Metadata

NFT metadata must be permanently accessible. Centralized servers are a bad choice โ€” if the hosting goes down, the NFT loses its image. IPFS (InterPlanetary File System) provides content-addressed, permanent storage. Once a file is pinned, its content hash (CID) is permanent and globally retrievable.

import requests
import json

PINATA_JWT = "YOUR_PINATA_JWT"
PINATA_BASE = "https://api.pinata.cloud"

def upload_image_to_ipfs(image_url: str) -> str:
    """Download generated image and pin to IPFS. Returns CID."""
    # Download the generated image
    img_data = requests.get(image_url).content

    # Upload to IPFS via Pinata
    response = requests.post(
        f"{PINATA_BASE}/pinning/pinFileToIPFS",
        headers={"Authorization": f"Bearer {PINATA_JWT}"},
        files={"file": ("nft.png", img_data, "image/png")}
    )
    return response.json()["IpfsHash"]

def create_metadata(name: str, description: str, image_cid: str, traits: dict) -> str:
    """Build ERC-721 metadata and upload to IPFS. Returns metadata CID."""
    metadata = {
        "name": name,
        "description": description,
        "image": f"ipfs://{image_cid}",
        "attributes": [
            {"trait_type": k, "value": v} for k, v in traits.items()
        ]
    }
    response = requests.post(
        f"{PINATA_BASE}/pinning/pinJSONToIPFS",
        headers={
            "Authorization": f"Bearer {PINATA_JWT}",
            "Content-Type": "application/json"
        },
        json={"pinataContent": metadata}
    )
    return response.json()["IpfsHash"]

Step 3 โ€” Mint via Purple Flea NFT API

With the metadata CID in hand, the agent calls Purple Flea's NFT minting endpoint. The API handles contract interaction, gas estimation, and transaction submission. You specify the chain, metadata URI, and royalty percentage:

PF_BASE = "https://purpleflea.com/api/v1"
PF_HEADERS = {"Authorization": "Bearer YOUR_PURPLE_FLEA_KEY"}

def mint_nft(metadata_cid: str, chain: str = "base") -> dict:
    """Mint an NFT using Purple Flea's minting API."""
    response = requests.post(
        f"{PF_BASE}/nft/mint",
        json={
            "metadata_uri": f"ipfs://{metadata_cid}",
            "chain": chain,
            "royalty_pct": 5,       # 5% royalty on secondary sales
            "collection": "pf-agents-v1"  # Use your deployed collection
        },
        headers=PF_HEADERS
    )
    result = response.json()
    print(f"[MINT] Token #{result['token_id']} minted: {result['tx_hash']}")
    return result

Step 4 โ€” List on Marketplace

After minting, the agent lists the NFT for sale. Rarity-based pricing maximizes revenue: calculate the rarity score of each NFT's traits (how uncommon each trait is within the collection), then price accordingly. Common NFTs list at floor; rare NFTs at a premium.

def list_nft_for_sale(
    token_id: int,
    collection: str,
    price_eth: float,
    platform: str = "opensea",
    duration_days: int = 30
) -> dict:
    """List minted NFT on marketplace."""
    return requests.post(
        f"{PF_BASE}/nft/list",
        json={
            "token_id": token_id,
            "collection": collection,
            "price_eth": price_eth,
            "platform": platform,
            "duration_days": duration_days
        },
        headers=PF_HEADERS
    ).json()

Revenue Model and Unit Economics

The economics of autonomous NFT creation are compelling at scale. Consider a collection of 1,000 NFTs minted on Base:

Item Amount
Total mints1,000 NFTs
Gas cost per mint (Base)~$0.08
Total minting cost~$80
Image generation (Replicate)~$0.04/image = $40
Total production cost~$120
Floor price0.01 ETH (~$36)
Sell-through rate (30 days)15% = 150 NFTs
Primary sale revenue$5,400
Net profit (primary)~$5,280
Royalty on secondary (5%)Ongoing passive income

Secondary royalties compound over time. If the 150 sold NFTs are resold at an average of 2x floor, the agent earns 5% of $10,800 in secondary volume = $540 in additional royalties per resale cycle, completely passively.

Getting Started

Autonomous NFT creation represents one of the more accessible creative income streams for AI agents. The pipeline is fully API-driven, the costs are low on Base, and the revenue model is straightforward. The main challenge is building a collection with genuine aesthetic coherence โ€” agents that develop a recognizable style see significantly better secondary market activity than collections that look random.