novelai_api.low_level

print_with_parameters(args: Dict[str, Any])[source]

Print the provided parameters in a nice way

class LowLevel[source]

Bases: object

Low level API for NovelAI. This class is not meant to be used directly, but rather through NovelAIAPI.low_level.

The most relevant methods are:

__init__(parent: NovelAIAPI)[source]
is_schema_validation_enabled: bool

Enable or disable schema validation for responses. Default is True.

async request(method: str, endpoint: str, data: Dict[str, Any] | str | None = None, custom_base_address: str | None = None)[source]

Send request with support for data streaming

Parameters:
  • method – Method of the request (get, post, delete)

  • endpoint – Endpoint of the request

  • data – Data to pass to the method if needed

  • custom_base_address – Custom address to use for the request

async is_reachable() bool[source]

Check if the NovelAI API is reachable

Returns:

True if reachable, False if not

async register(recapcha: str, access_key: str, email: str | None, giftkey: str | None = None) bool[source]

Register a new account

Parameters:
  • recapcha – Recapcha of the NovelAI website

  • access_key – Access key of the account

  • email – Hashed email (used for recovery)

  • giftkey – Giftkey

Returns:

True if success

async login(access_key: str) Dict[str, str][source]

Log in to the account

Parameters:

access_key – Access key of the account

Returns:

Response of the request

async change_access_key(current_key: str, new_key: str, new_email: str | None = None) Dict[str, str][source]

Change the access key of the given account

Parameters:
  • current_key – Current key of the account

  • new_key – New key of the account

  • new_email – New email, if it changed

async send_email_verification(email: str) bool[source]

Send the email for account verification

Parameters:

email – Address to send the email to

async verify_email(verification_token: str) bool[source]

Check the token sent for email verification

Parameters:

verification_token – Token sent to the email address

async get_information() Dict[str, Any][source]

Get extensive information about the account

async request_account_recovery(email: str) bool[source]

Send a recovery token to the provided email address, if the account has been lost WARNING: the content will not be readable with a different encryption key

Parameters:

email – Address to send the email to

async recover_account(recovery_token: str, new_key: str, delete_content: bool = False) Dict[str, Any][source]

Recover the lost account

Parameters:
  • recovery_token – Token sent to the given email address

  • new_key – New access key for the account

  • delete_content – Delete all content that was on the account

async delete_account() bool[source]

Delete the account

async get_data() Dict[str, Any][source]

Get various data about the account

async get_priority() Dict[str, Any][source]

Get the priority information of the account

The priority system is a legacy system and isn’t really important

class SubscriptionTier[source]

Bases: enum.IntEnum

Index of the subscription tiers

PAPER tier is the free trial

PAPER = 0
TABLET = 1
SCROLL = 2
OPUS = 3
async get_subscription() Dict[str, Any][source]

Get various information about the account’s subscription

async get_keystore() Dict[str, str][source]

Get the keystore

The keystore is the storage for the encryption keys of any content on the account. Losing it is equal to losing all your encrypted content

async set_keystore(keystore: Dict[str, str]) bool[source]

Set the keystore

The keystore is the storage for the encryption keys of any content on the account. Losing it (or overwriting it with wrong data) is equal to losing all your encrypted content

async download_objects(object_type: str) Dict[str, List[Dict[str, str | int]]][source]

Download all the objects of a given type from the account

Parameters:

object_type – Type of the objects to download

async upload_objects(object_type: str, meta: str, data: str) bool[source]

Upload multiple objects of the given type

Parameters:
  • object_type – Type of the objects to upload

  • meta – Meta of the objects to upload (meta links to encryption key in keystore)

  • data – Serialized data of the content to upload

async download_object(object_type: str, object_id: str) Dict[str, str | int][source]

Download the selected object of a given type from the account

Parameters:
  • object_type – Type of the object to download

  • object_id – Id of the selected object

async upload_object(object_type: str, object_id: str, meta: str, data: str) bool[source]

Upload an object of then given type

Parameters:
  • object_type – Type of the object to upload

  • meta – Meta of the object to upload (meta links to encryption key in keystore)

  • data – Serialized data of the content to upload

  • object_id – Id of the selected object

async delete_object(object_type: str, object_id: str) Dict[str, str | int][source]

Download the selected object of a given type from the account

Parameters:
  • object_type – Type of the object to delete

  • object_id – Id of the selected object

async get_settings() str[source]

Get the account settings. The format is arbitrary.

async set_settings(value: str) bool[source]

Set the account settings. The format is arbitrary.

async bind_subscription(payment_processor: str, subscription_id: str) bool[source]

Bind payment information to the account to renew subscription monthly

async change_subscription(new_plan: str) bool[source]

Change the subscription tier. Payment information should still be bound to the account

async generate(prompt: List[int] | str, model: novelai_api.Preset.Model, params: Dict[str, Any], stream: bool = False)[source]

Generate text with streaming support. As the model accepts a complete prompt, the context building must be done before calling this function. Any content going beyond the tokens limit will be truncated, starting from the top.

Parameters:
  • prompt – Input to be sent the AI

  • model – Model of the AI

  • params – Generation parameters

  • stream – Use data streaming for the response

Returns:

Generated output

async generate_image(prompt: str, model: novelai_api.ImagePreset.ImageModel, action: novelai_api.ImagePreset.ImageGenerationType, parameters: Dict[str, Any]) AsyncIterator[Tuple[str, bytes]][source]

Generate one or multiple image(s)

Parameters:
  • prompt – Prompt for the image

  • model – Model to generate the image

  • action – Type of image generation to use

  • parameters – Parameters for the images

Returns:

(name, data) pairs for the raw PNG image(s)

async generate_prompt(model: novelai_api.Preset.Model, prompt: str, temp: float, length: int) Dict[str, Any][source]

Generate a prompt

Parameters:
  • model – Model to use for the prompt

  • prompt – Prompt to base the generation on

  • temp – Temperature for the generation

  • length – Length of the returned prompt

Returns:

Generated prompt

async generate_controlnet_mask(model: novelai_api.ImagePreset.ControlNetModel, image: str) Tuple[str, bytes][source]

Get the ControlNet’s mask for the given image. Used for ImageSampler.controlnet_condition

Parameters:
  • model – ControlNet model to use

  • image – b64 encoded PNG image to get the mask of

Returns:

A pair (name, data) for the raw PNG image

async upscale_image(image: str, width: int, height: int, scale: int) Tuple[str, bytes][source]

Upscale the given image. Afaik, the only allowed values for scale are 2 and 4.

Parameters:
  • image – b64 encoded PNG image to upscale

  • width – Width of the starting image

  • height – Height of the starting image

  • scale – Upscaling factor (final width = starting width * scale, final height = starting height * scale)

Returns:

A pair (name, data) for the raw PNG image

async augment_image(request_type: novelai_api.DirectorToolsPreset.RequestType, preset: novelai_api.DirectorToolsPreset.DirectorToolsPreset) Tuple[str, bytes][source]

Augment the given image with the given preset

Parameters:
  • request_type – Type of request to use

  • preset – Preset to use for the augmentation

Returns:

A pair (name, data) for the raw PNG image

async classify() NoReturn[source]

Not implemented

async suggest_tags(tag: str, model: novelai_api.ImagePreset.ImageModel) Dict[str, Any][source]

Suggest tags with a certain confidence, considering how much the tag is used in the dataset

Parameters:
  • tag – Tag to suggest others of

  • model – Image model to get the tags from

Returns:

List of similar tags with a confidence level

async generate_voice(text: str, seed: str, voice: int, opus: bool, version: str) Dict[str, Any][source]

Generate the Text To Speech of the given text

Parameters:
  • text – Text to synthesize into voice (text will be cut to 1000 characters backend-side)

  • seed – Voice to use (TTS v2 only)

  • voice – Index of the voice to use (TTS v1 only)

  • opus – True for WebM format, False for mp3 format

  • version – Version of the TTS (“v1” or “v2”)

Returns:

TTS audio data of the text

async train_module(data: str, rate: int, steps: int, name: str, desc: str) Dict[str, Any][source]

Train a module for text gen

Parameters:
  • data – Dataset of the module, in one single string

  • rate – Learning rate of the training

  • steps – Number of steps to train the module for

  • name – Name of the module

  • desc – Description of the module

Returns:

Status of the module being trained

async get_trained_modules() List[Dict[str, Any]][source]

Get the modules currently in training or that finished training

async get_trained_module(module_id: str) Dict[str, Any][source]

Get a module currently in training or that finished training

Parameters:

module_id – Id of the selected module

async delete_module(module_id: str) Dict[str, Any][source]

Delete a module currently in training or that finished training

Parameters:

module_id – Id of the selected module

Returns:

Module that got deleted

async buy_steps(amount: int)[source]