88API88API
User GuideAPI ReferenceAI ApplicationsHelp & Support

Environment Variable Configuration Guide

This document provides all environment variables supported by 88API and their configuration instructions. You can customize the system's behavior by setting these environment variables.

Tip

88API supports reading environment variables from the .env file. Please refer to the .env.example file and rename it to .env for use.

Basic Configuration

Environment VariableDescriptionDefault ValueExample
PORTService listening port3000PORT=8080
TZTime zone settingAsia/ShanghaiTZ=America/New_York

Database Configuration

Environment VariableDescriptionDefault ValueExample
SQL_DSNDatabase connection stringSQLite (data/one-api.db)MySQL: SQL_DSN=root:123456@tcp(localhost:3306)/new-api | PostgreSQL: SQL_DSN=postgresql://root:123456@postgres:5432/new-api
SQL_MAX_IDLE_CONNSMaximum number of idle connections in the connection pool100SQL_MAX_IDLE_CONNS=50
SQL_MAX_OPEN_CONNSMaximum number of open connections in the connection pool1000SQL_MAX_OPEN_CONNS=500
SQL_CONN_MAX_LIFETIMEMaximum connection lifetime (minutes)60SQL_CONN_MAX_LIFETIME=120
LOG_SQL_DSNSeparate database connection string for the log table-LOG_SQL_DSN=root:123456@tcp(localhost:3306)/oneapi_logs
SQLITE_BUSY_TIMEOUTSQLite lock wait timeout (milliseconds)3000SQLITE_BUSY_TIMEOUT=5000

Cache Configuration

Environment VariableDescriptionDefault ValueExample
REDIS_CONN_STRINGRedis connection string-REDIS_CONN_STRING=redis://default:redispw@localhost:6379
MEMORY_CACHE_ENABLEDWhether to enable memory cachefalseMEMORY_CACHE_ENABLED=true
REDIS_CONN_POOL_SIZERedis connection pool size-REDIS_CONN_POOL_SIZE=10
REDIS_PASSWORDPassword for Redis cluster or sentinel mode-REDIS_PASSWORD=your_password
REDIS_MASTER_NAMERedis sentinel mode master name-REDIS_MASTER_NAME=mymaster
BATCH_UPDATE_ENABLEDEnable database batch update aggregationfalseBATCH_UPDATE_ENABLED=true
BATCH_UPDATE_INTERVALBatch update aggregation interval (seconds)5BATCH_UPDATE_INTERVAL=10

Multi-Node and Security Configuration

Environment VariableDescriptionDefault ValueExample
SESSION_SECRETSession secret (required for multi-machine deployment)-SESSION_SECRET=random_string
CRYPTO_SECRETEncryption key (encrypts database content)-CRYPTO_SECRET=your_crypto_secret
FRONTEND_BASE_URLFrontend base URL-FRONTEND_BASE_URL=https://your-domain.com
SYNC_FREQUENCYCache and database synchronization frequency (seconds)600SYNC_FREQUENCY=60
NODE_TYPENode typemasterNODE_TYPE=slave
INITIAL_ROOT_TOKENRoot user token created on first startup-INITIAL_ROOT_TOKEN=your_token
INITIAL_ROOT_ACCESS_TOKENSystem management token created on first startup-INITIAL_ROOT_ACCESS_TOKEN=your_token

Cluster Deployment

For information on how to use these environment variables to build a complete cluster deployment, please refer to the Cluster Deployment Guide.

User and Token Configuration

Environment VariableDescriptionDefault ValueExample
DEFAULT_QUOTADefault quota for new users0DEFAULT_QUOTA=10
GLOBAL_USER_QUOTAGlobal user quota limit-GLOBAL_USER_QUOTA=100
GENERATE_DEFAULT_TOKENGenerate initial token for new registered usersfalseGENERATE_DEFAULT_TOKEN=true
NOTIFICATION_LIMIT_DURATION_MINUTEDuration of notification limit (minutes)10NOTIFICATION_LIMIT_DURATION_MINUTE=15
NOTIFY_LIMIT_COUNTMaximum number of notifications within the specified duration2NOTIFY_LIMIT_COUNT=3

Request Limit Configuration

Environment VariableDescriptionDefault ValueExample
GLOBAL_API_RATE_LIMITGlobal API rate limit (per IP, three minutes)180GLOBAL_API_RATE_LIMIT=100
GLOBAL_WEB_RATE_LIMITGlobal Web rate limit (per IP, three minutes)60GLOBAL_WEB_RATE_LIMIT=30
RELAY_TIMEOUTRelay request timeout (seconds)-RELAY_TIMEOUT=60
USER_CONTENT_REQUEST_TIMEOUTUser content download timeout (seconds)-USER_CONTENT_REQUEST_TIMEOUT=30
STREAMING_TIMEOUTStreaming single response timeout (seconds)60STREAMING_TIMEOUT=120
MAX_FILE_DOWNLOAD_MBMaximum file download size (MB)20MAX_FILE_DOWNLOAD_MB=50

RELAY_TIMEOUT Setting Warning

Please exercise caution when setting the RELAY_TIMEOUT environment variable. Setting it too short may lead to the following issues:

  • The upstream API has completed the request and charged, but local billing failed due to timeout

  • Causing billing synchronization issues, which may lead to system losses

  • It is recommended not to set this, unless you know what you are doing

Channel Management Configuration

Environment VariableDescriptionDefault ValueExample
CHANNEL_UPDATE_FREQUENCYPeriodically update channel balance (minutes)-CHANNEL_UPDATE_FREQUENCY=1440
CHANNEL_TEST_FREQUENCYPeriodically check channels (minutes)-CHANNEL_TEST_FREQUENCY=1440
POLLING_INTERVALRequest interval during batch channel updates (seconds)0POLLING_INTERVAL=5
ENABLE_METRICWhether to disable channels based on request success ratefalseENABLE_METRIC=true
METRIC_QUEUE_SIZERequest success rate statistics queue size10METRIC_QUEUE_SIZE=20
METRIC_SUCCESS_RATE_THRESHOLDRequest success rate threshold0.8METRIC_SUCCESS_RATE_THRESHOLD=0.7
TEST_PROMPTUser prompt when testing modelsPrint your model name exactly...TEST_PROMPT=Hello

代理配置

环境变量说明默认值示例
RELAY_PROXY中继请求使用的代理-RELAY_PROXY=http://127.0.0.1:7890
USER_CONTENT_REQUEST_PROXY用户内容请求使用的代理-USER_CONTENT_REQUEST_PROXY=http://127.0.0.1:7890

Model and Request Processing Configuration

Environment VariableDescriptionDefault ValueExample
FORCE_STREAM_OPTIONOverride client stream_options parametertrueFORCE_STREAM_OPTION=false
GET_MEDIA_TOKENWhether to count image tokenstrueGET_MEDIA_TOKEN=false
GET_MEDIA_TOKEN_NOT_STREAMWhether to count image tokens in non-streaming modetrueGET_MEDIA_TOKEN_NOT_STREAM=false
UPDATE_TASKWhether to update asynchronous tasks (MJ, Suno)trueUPDATE_TASK=false
ENFORCE_INCLUDE_USAGEForce usage return in stream modefalseENFORCE_INCLUDE_USAGE=true
TIKTOKEN_CACHE_DIRTiktoken encoder cache directory, used to store tokenizer files to avoid network download-TIKTOKEN_CACHE_DIR=/cache/tiktoken
DATA_GYM_CACHE_DIRDataGym cache directory-DATA_GYM_CACHE_DIR=/cache/data_gym

Tiktoken File Configuration

After downloading the tiktoken files, please rename them as follows:

  • cl100k_base.tiktoken renamed to 9b5ad71b2ce5302211f9c61530b329a4922fc6a4
  • o200k_base.tiktoken renamed to fb374d419588a4632f3f557e76b4b70aebbca790

These files should be placed in the directory specified by TIKTOKEN_CACHE_DIR to improve token calculation performance and reduce network dependency.

Tiktoken Configuration Example

# Docker environment example
TIKTOKEN_CACHE_DIR=/app/data/tiktoken

  # Then download and rename the tiktoken files and place them in this directory:

# /app/data/tiktoken/9b5ad71b2ce5302211f9c61530b329a4922fc6a4

# /app/data/tiktoken/fb374d419588a4632f3f557e76b4b70aebbca790

Tiktoken is the tokenizer used by OpenAI to calculate the number of tokens in the text. By caching these files locally, the system can avoid downloading them from the network every time it starts, improving stability and performance, especially in network-restricted environments.

Specific Model Configuration

Environment VariableDescriptionDefault ValueExample
AZURE_DEFAULT_API_VERSIONAzure channel default API version2024-12-01-previewAZURE_DEFAULT_API_VERSION=2023-05-15
COHERE_SAFETY_SETTINGCohere model safety settingNONECOHERE_SAFETY_SETTING=CONTEXTUAL
GEMINI_VISION_MAX_IMAGE_NUMGemini model maximum image count16GEMINI_VISION_MAX_IMAGE_NUM=8
GEMINI_VERSIONGemini versionv1GEMINI_VERSION=v1beta
DIFY_DEBUGDify channel output workflow and node informationtrueDIFY_DEBUG=false

Other Configuration

Environment VariableDescriptionDefault ValueExample
EMAIL_SERVEREmail server configuration-EMAIL_SERVER=smtp.example.com:25
EMAIL_FROMEmail sender address-EMAIL_FROM=noreply@example.com
EMAIL_PASSWORDEmail server password-EMAIL_PASSWORD=yourpassword
ERROR_LOG_ENABLEDWhether to record and display error logs on the frontendfalseERROR_LOG_ENABLED=true

Deprecated Environment Variables

The following environment variables have been deprecated. Please use the corresponding options in the system settings interface:

Environment VariableAlternative Method
GEMINI_MODEL_MAPPlease set in System Settings - Model Related Settings
GEMINI_SAFETY_SETTINGPlease set in System Settings - Model Related Settings

Multi-Machine Deployment Example

In multi-machine deployment scenarios, the following environment variables must be set:

Master Node Configuration

# Database Configuration - Use remote database
SQL_DSN=root:password@tcp(db-server:3306)/oneapi

# Security Configuration
SESSION_SECRET=your_unique_session_secret
CRYPTO_SECRET=your_unique_crypto_secret

# Redis Cache Configuration
REDIS_CONN_STRING=redis://default:password@redis-server:6379

Slave Node Configuration

# Database Configuration - Use the same remote database
SQL_DSN=root:password@tcp(db-server:3306)/oneapi

# Security Configuration - Use the same secrets as the master node
SESSION_SECRET=your_unique_session_secret
CRYPTO_SECRET=your_unique_crypto_secret

# Redis Cache Configuration - Use the same Redis as the master node
REDIS_CONN_STRING=redis://default:password@redis-server:6379

# Node Type Setting
NODE_TYPE=slave

# Optional: Frontend Base URL
FRONTEND_BASE_URL=https://your-domain.com

# Optional: Synchronization Frequency
SYNC_FREQUENCY=60

Complete Cluster Configuration

This is just a basic multi-node configuration example. For complete cluster deployment configuration, architecture description, and best practices, please refer to the Cluster Deployment Guide.

Environment Variable Example in Docker Compose

Below is a brief example of setting environment variables in a Docker Compose configuration file:

services:
  new-api:
    image: calciumion/new-api:latest
    environment:
      - TZ=Asia/Shanghai
      - SQL_DSN=root:123456@tcp(mysql:3306)/oneapi
      - REDIS_CONN_STRING=redis://default:redispw@redis:6379
      - SESSION_SECRET=your_unique_session_secret
      - CRYPTO_SECRET=your_unique_crypto_secret
      - MEMORY_CACHE_ENABLED=true
      - GENERATE_DEFAULT_TOKEN=true
      - STREAMING_TIMEOUT=120
      - CHANNEL_UPDATE_FREQUENCY=1440

For the complete Docker Compose configuration, including more environment variable setting options, please refer to the Docker Compose Configuration Instructions document.