> ## Documentation Index
> Fetch the complete documentation index at: https://docs.story.foundation/llms.txt
> Use this file to discover all available pages before exploring further.

# Protect DALL·E AI-Generated Images

> Learn how to license and protect DALL·E AI-Generated images on Story.

In this tutorial, you will learn how to license and protect DALL·E 2 AI-Generated images by registering it on Story.

## The Explanation

Let's say you generate an image using AI. Without adding a proper license to your image, others could use it freely. In this tutorial, you will learn how to add a license to your DALL·E 2 AI-Generated image so that if others want to use it, they must properly license it from you.

In order to register that IP on Story, you first need to mint an NFT to represent that IP, and then register that NFT on Story, turning it into an [IP Asset](/concepts/ip-asset).

## 0. Before you Start

There are a few steps you have to complete before you can start the tutorial.

1. You will need to install [Node.js](https://nodejs.org/en/download) and [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm). If you've coded before, you likely have these.
2. Add your Story Network Testnet wallet's private key to `.env` file:

```yaml .env theme={null}
WALLET_PRIVATE_KEY=
```

3. Go to [Pinata](https://pinata.cloud/) and create a new API key. Add the JWT to your `.env` file:

```yaml .env theme={null}
PINATA_JWT=
```

4. Go to [OpenAI](https://platform.openai.com/settings/organization/api-keys) and create a new API key. Add the new key to your `.env` file:

<Warning>
  **OpenAI Credits**

  In order to generate an image, you'll need OpenAI credits. If you just created an account, you will probably have a free trial that will give you a few credits to start with.
</Warning>

```yaml .env theme={null}
OPENAI_API_KEY=
```

5. Add your preferred RPC URL to your `.env` file. You can just use the public default one we provide:

```yaml .env theme={null}
RPC_PROVIDER_URL=https://aeneid.storyrpc.io
```

6. Install the dependencies:

```bash Terminal theme={null}
npm install @story-protocol/core-sdk pinata-web3 viem openai
```

## 1. Generate an Image

In a `main.ts` file, add the following code to generate an image:

```typescript main.ts theme={null}
import OpenAI from "openai";

async function main() {
  const openai = new OpenAI({
    apiKey: process.env.OPENAI_API_KEY,
  });

  const image = await openai.images.generate({
    model: "dall-e-2",
    prompt: "A cute baby sea otter",
  });

  console.log(image.data[0].url); // the url to the newly created image
}

main();
```

## 2. Set up your Story Config

In a `utils.ts` file, add the following code to set up your Story Config:

<Info>
  Associated docs: [TypeScript SDK Setup](/developers/typescript-sdk/setup)
</Info>

```typescript utils.ts theme={null}
import { StoryClient, StoryConfig } from "@story-protocol/core-sdk";
import { http } from "viem";
import { privateKeyToAccount, Address, Account } from "viem/accounts";

const privateKey: Address = `0x${process.env.WALLET_PRIVATE_KEY}`;
export const account: Account = privateKeyToAccount(privateKey);

const config: StoryConfig = {
  account: account,
  transport: http(process.env.RPC_PROVIDER_URL),
  chainId: "aeneid",
};
export const client = StoryClient.newClient(config);
```

## 3. Set up your IP Metadata

View the [IPA Metadata Standard](/concepts/ip-asset/ipa-metadata-standard) and construct your metadata for your IP. Back in the `main.ts` file, properly format your metadata as shown below:

```typescript main.ts theme={null}
import OpenAI from "openai";
import { client, account } from "./utils";

async function main() {
  // previous code here ...

  const ipMetadata = {
    title: "Baby Sea Otter",
    description: "A baby sea otter generated with DALL·E.",
    createdAt: "1728401700",
    image: image.data[0].url,
    imageHash: "0x...", // a hash of the image
    mediaUrl: image.data[0].url,
    mediaHash: "0x...", // a hash of the image
    mediaType: "image/png",
    creators: [
      {
        name: "Jacob Tucker",
        address: "0x67ee74EE04A0E6d14Ca6C27428B27F3EFd5CD084",
        description: "A cool dev rel person.",
        contributionPercent: 100,
        socialMedia: [
          {
            platform: "Twitter",
            url: "https://x.com/jacobmtucker",
          },
        ],
      },
    ],
  };
}

main();
```

## 4. Set up your NFT Metadata

The NFT Metadata follows the [ERC-721 Metadata Standard](https://eips.ethereum.org/EIPS/eip-721).

```typescript main.ts theme={null}
import OpenAI from "openai";
import { client, account } from "./utils";

async function main() {
  // previous code here ...

  const nftMetadata = {
    name: "Image Ownership NFT",
    description:
      "This NFT represents ownership of the image generated by Dall-E 2",
    image: image.data[0].url,
    attributes: [
      {
        key: "Model",
        value: "dall-e-2",
      },
      {
        key: "Prompt",
        value: "A cute baby sea otter",
      },
    ],
  };
}

main();
```

## 5. Upload & Register IP

Now that we have all of our metadata set up, you can easily complete this tutorial by going to [Register an IP Asset](/developers/typescript-sdk/register-ip-asset#3-%5Boptional%5D-upload-your-ip-and-nft-metadata-to-ipfs) and **completing steps 3 (Upload your IP and NFT Metadata to IPFS) & 4 (Register an NFT as an IP Asset)**.

Once you have done that, you should see a console log with a link to our IP-explorer that shows your registered AI generated image.

## 6. Done!

<CardGroup cols={1}>
  <Card title="Learn More" href="/developers/tutorials" icon="book-open">
    Explore more tutorials in our documentation
  </Card>
</CardGroup>
