Learn how to use the FLUX Finetuning API to finetune images and then register the output on Story in TypeScript.
.env
file:.env
file:.env
file:.env
file. You can just use the public default one we provide:images
. In that folder, add a bunch of images that you want your finetune to train on. Supported formats: JPG, JPEG, PNG, and WebP. Also recommended to use more than 5 images.images.zip
/v1/finetune
API route. Create a flux
folder, and inside that folder add a file named requestFinetuning.ts
and add the following code:
/v1/finetune
API docs here.train.ts
and call the requestFinetuning
function we just made:
finetune_id
, and will be used to create images in the following steps.
flux
folder, create a file named finetune-progress.ts
and add the following code:
/v1/get_result
API docs here.finetune-progress.ts
and call the finetuneProgress
function we just made:
finetune_id
), which is trained on our images, to create new images.
There are several different inference endpoints we can use, each with their own pricing (found at the bottom of the page). For this tutorial, I’ll be using the /v1/flux-pro-1.1-ultra-finetuned
endpoint, which is documented here.
In our flux
folder, create a finetuneInference.ts
file and add the following code:
/v1/flux-pro-1.1-ultra-finetuned
API docs here.inference.ts
and call the finetuneInference
function we just made. The first parameter should be the finetune_id
we got from running the script above, and the second parameter is a prompt to generate a new image.
flux
folder, create a file named getInference.ts
and add the following code:
/v1/get_result
API docs here.inference.ts
file, lets add a loop that continuously fetches the inference until it’s ready. When it’s ready, we will view the new image.
sample
into your browser and see the final result! Make sure to save this image as it will disappear eventually.
story
folder and add a utils.ts
file. In there, add the following code to set up your Story Config:
sample
file ourselves on IPFS because the sample is only temporary.
In a new pinata
folder, create a uploadToIpfs.ts
file and create a function to upload our image and get details about it:
story
folder, create a registerIp.ts
file.
View the IPA Metadata Standard and construct the metadata for your IP as shown below:
registerIp.ts
file, configure your NFT Metadata, which follows the OpenSea ERC-721 Standard.
pinata
folder, create a function to upload your IP & NFT Metadata objects to IPFS:
mintAndRegisterIp
function to mint an NFT and register it as an IP Asset in the same transaction.
This function needs an SPG NFT Contract to mint from. For simplicity, you can use a public collection we have created for you on Aeneid testnet: 0xc32A8a0FF3beDDDa58393d022aF433e78739FAbc
.
Creating your own custom ERC-721 collection
nftContract
and tokenId
- instead of using the mintAndRegisterIp
function. See a working code example here. This is helpful if you already have a custom NFT contract that has your own custom logic, or if your IPs themselves are NFTs.
registerIp
function, let’s add it to our inference.ts
file: