AI
We will use generative AI in our project to visualize our user's worlds. Whilst AI could also be used for other purposes, e.g. generating text or stories, it isn't perhaps mature enough yet to serve these purposes. At least in my opinion the quality of AI text generation for the purposes of world-building is not yet quite there yet.
For this reason the use of AI on Epic Fantasy Forge is limited to image generation. Whilst there are also sometimes quality issues with AI-generated images, a lot of people (myself included), don't have the necessary time and/or skills to visualize their worlds. In this regard AI can be really helpful.
As AI is not for everyone, it is an optional feature on Epic Fantasy Forge and can be disabled. Users may also upload their own images to Epic Fantasy Forge in lieu of using AI generated images.
AI Provider
The AI provider recommended in this guide is Leonardo.Ai. We will be using the Leonardo.Ai API. Usage of the API is available in several pricing tiers. The pricing tier recommended in this guide is "API Standard" for $49 per month. This pricing tier should be sufficient if there are not too many users.
As Epic Fantasy Forge is a free app, we will need to fairly use the API credits that come with our monthly plan. To ensure a consistent use of credits, regardless of the number of users our app has, we will generate images for user's worlds every night at 00:00 AM. If there are too many users, then they are served on a round-robin basis, i.e. one night the images will be generated for a certain subset of users and another night for another subset of users and so on.
The basis for the image generation will be the texts users write to describe their worlds. As users update their texts, the images may be re-generated over time.
API
To get started with the Leonardo.Ai API, create an account on Leonardo.Ai. Once you have an account, subscribe to the "API Standard" tier.
Once you are subscribed, navigate to your dashboard. Then click on "API Access" on the left sidebar and click on "Create New Key":
First we will create an API key for our test environment. Enter "Test" as your API key name.
For the webhook callback, enter a URL for an API endpoint that will handle callbacks from Leonardo.Ai. This endpoint will be called by Leonardo.Ai when image generation is complete. Setting this endpoint is optional as you can also poll for image completion, however callbacks are a more efficient and cleaner solution compared to polling. In the case of Epic Fantasy Forge, we set the callback URL to "https://api.test.epicfantasyforge.com/leonardo-callback.
Note that the subdomain api.test.epicfantasyforge.com doesn't exist yet. We will create it later. Naturally the endpoint "leonardo-callback" also doesn't exist yet, we will create it in a later section of this guide.
For the webhook callback API key, generate a secret using a trusted tool, for example using your password manager. Then store this secret in a safe location, e.g. your password manager, and copy it into the webhook callback API key field. Leonardo.Ai will include this secret in every callback it makes to your API so you can be sure that Leonardo.Ai is calling your API.
You API key is now generated. Copy it and store it in a safe location, e.g. your password manager.
Now repeat the above process and create another API key for your production environment. This time call the API key "Production" and set the webhook callback URL to point to your production environment, e.g. "https://api.epicfantasyforge.com/leonardo-callback" in the case of Epic Fantasy Forge.
You should now have two API keys for your two environments:
Now save these API keys in your CI as CI variables. Remember to set the "Visibility" to "Masked and hidden" so these secrets are not shown in your CI job logs. For more information how to create CI variables CI Variables section on the Technical Documentation page in this guide.
Finally you should have four additional CI variables, two for the Leonardo API keys and two additional for the webhook callbacks.
We will take these CI variables into use in a later section of this guide.
Image Generation
To find models, prompts and settings that work well with our app, it might be more convenient to first play around with Leonardo.Ai using the regular UI rather than the API. For this purpose the "Apprentice" subscription is recommended for $12 per month. Whilst there is a free plan, it is very limited.
This is what image generation on Leonardo.Ai looks like: