NovelAI SDKNovelAI SDKunofficial

Authentication

Configure your NovelAI API key safely.

You need to authenticate to use the NovelAI API. novelai-sdk supports the standard authentication methods.

It is strongly recommended to use environment variables instead of hardcoding API keys.

Set NOVELAI_API_KEY in your environment:

export NOVELAI_API_KEY="pst-..."

Then in Python:

from novelai import NovelAI

client = NovelAI()  # Automatically reads the env var

.env File

Using .env files with python-dotenv is also common.

.env
NOVELAI_API_KEY=pst-your-api-key-here
from dotenv import load_dotenv
from novelai import NovelAI

load_dotenv()
client = NovelAI()

Direct Initialization

For scripts or testing:

from novelai import NovelAI

client = NovelAI(api_key="pst-your-api-key-here")

On this page