Our infrastructure might seem a bit confusing, but it's actually quite simple. Just the first one really matters for you, if you want to access our AI API. The other ones are just for the team.
### AI API
**Public** (everyone can use it with a valid API key)
Create a `.env` file, make sure not to reveal any of its contents to anyone, and fill in the required values in the format `KEY=VALUE`. Otherwise, the code won't run.
### Database
Set up a MongoDB database and set `MONGO_URI` to the MongoDB database connection URI. Quotation marks are definetly recommended here!
### ~~`ACTUAL_IPS` (optional)~~ (deprecated, might come back in the future)
This is a security measure to make sure a proxy, VPN, Tor or any other IP hiding service is used by the host when accessing "Closed"AI's API.
It is a space separated list of IP addresses that are allowed to access the API.
You can also just add the *beginning* of an API address, like `12.123.` (without an asterisk!) to allow all IPs starting with `12.123.`.
> To disable the warning if you don't have this feature enabled, set `ACTUAL_IPS` to `None`.
### Timeout
`TRANSFER_TIMEOUT` seconds to wait until the program throws an exception for if the request takes too long. We recommend rather long times like `500` for 500 seconds.
### Core Keys
`CORE_API_KEY` specifies the **very secret key** for which need to access the entire user database etc.
`MODERATION_DEBUG_KEY` can be almost any string (avoid spaces or special characters) - users can add `#` + this key to their API key (e.g. `Bearer nv-123#modkey` as the `Authorization` header) to bypass the moderation checks. This is especially useful if the moderation is too sensitive and can be disabled for certain trusted users.
`KEYGEN_INFIX` can be almost any string (avoid spaces or special characters) - this string will be put in the middle of every NovaAI API key which is generated. This is useful for identifying the source of the key using e.g. RegEx.
This is one of the most essential parts of NovaAI. Providers are the APIs used to access the AI models.
The modules are located in `api/providers/` and active providers are specified in `api/providers/__init__.py`.
You shouldn't use `.env` for provider keys. Instead, use the database as it's more flexible and secure. For a detailed explanation, scroll down a bit to the database section.
Always return the `provider_auth` dictionary key if you a API key is required. Example:
```py
...
return {
...
'provider_auth': f'exampleprovider>{key}'
}
...
```
Whereas `exampleprovider` is the provider name used in the database.
### Check providers
List all providers using `python api`. This **won't** start the API server.
Check if a provider is working using `python api <provider>`, e.g. `python api azure`. This **doesn't** require the API to be running.
## Core Database
You need to set up a MongoDB database and set `MONGO_URI` in `.env` to the MongoDB database connection URI. Use quotation marks!
It's also important to set up the database `nova-core`.
The following collections are used in the database and will be created automatically if they don't exist.
### `users`
Generally, the `api_key` should be treated as the primary key. However, the `discord` and `github` keys are also unique and can be used as primary keys.
-`active`: defaults to `true`. May be used in the future so that users can deactivate their accounts.
-`ban_reason`: defaults to `""`. If the user is banned, this will be set to the reason.
-`auth`:
-`discord`: Discord user ID. Use a string, because Discord IDs can be larger than the maximum integer value.
-`github`: GitHub user ID. Not used yet.
-`level`: Discord (Arcane bot) level. [int]
### `providerkeys`
Used in `api/providers/...` to store API keys of the providers.
-`provider`: provider name [str], e.g. `azure``
-`key`: API key [str], e.g. `sk-...`
-`rate_limited_since`: timestamp [int], defaults to `null`. The unix timestamp when the provider was rate limited. If it's `null`, the provider is not rate limited.
-`inactive_reason`: defaults to `null`. If the key is disabled or terminated, this will be set to the reason automatically. You can also set it manually. [str]
-`source`: just to keep track of where the key came from. [str]
### `stats`
Logs general statistics.
Automatically updated by the API server.
More info is yet to be documented.
### `logs`
Every API request is logged here.
Automatically updated by the API server.
More info is yet to be documented.
## Finance Database
The finance database is used to keep track of the finances.
**Important:** *always* use the specified `currency` for the field `amount`.
### `donations`
-`currency`: (crypto) currency [str], e.g. EUR, USD, BTC, USDT-TRX, ...
-`amount`: amount [float].
-`user`: [str], Discord user ID
-`proof`: [str], link to proof (e.g. transaction hash)
-`timestamp`: [int], unix timestamp
### `expenses`
-`currency`: (crypto) currency [str], e.g. EUR, USD, BTC, USDT-ETH, ...
-`amount`: amount [float]. NOT negative!
-`proof`: [str], link to proof (e.g. transaction hash)
-`type`: [str], type of expense, e.g. `wage`, `payment`, `donation`, ...
-`to`: [str], entity the expense was paid to, e.g. `IPRoyal`, `employee/John`