This document provides all environment variables supported by cnAPI and their configuration instructions. You can customize system behavior by setting these environment variables.
[!TIP] Tip
cnAPI supports reading environment variables from the .env file. Please refer to the .env.example file and rename it to .env for use.
Environment Variable Description Default Value Example PORTService listening port 3000PORT=8080TZTime zone setting - TZ=America/New_YorkVERSIONOverride running version number - VERSION=1.2.3
Environment Variable Description Default Value Example SQL_DSNDatabase connection string SQLite (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 pool 100SQL_MAX_IDLE_CONNS=50SQL_MAX_OPEN_CONNSMaximum number of open connections in the connection pool 1000SQL_MAX_OPEN_CONNS=500SQL_MAX_LIFETIMEMaximum connection lifetime (minutes) 60SQL_MAX_LIFETIME=120LOG_SQL_DSNSeparate database connection string for log tables - LOG_SQL_DSN=root:123456@tcp(localhost:3306)/oneapi_logsSQLITE_PATHSQLite database path /path/to/sqlite.dbSQLITE_PATH=/var/lib/new-api/new-api.db
Environment Variable Description Default Value Example REDIS_CONN_STRINGRedis connection string - REDIS_CONN_STRING=redis://default:redispw@localhost:6379REDIS_POOL_SIZERedis connection pool size 10REDIS_POOL_SIZE=20MEMORY_CACHE_ENABLEDWhether to enable memory cache falseMEMORY_CACHE_ENABLED=trueBATCH_UPDATE_ENABLEDEnable database batch update aggregation falseBATCH_UPDATE_ENABLED=trueBATCH_UPDATE_INTERVALBatch update aggregation interval (seconds) 5BATCH_UPDATE_INTERVAL=10
Environment Variable Description Default Value Example SESSION_SECRETSession secret (required for multi-machine deployment) - SESSION_SECRET=random_stringCRYPTO_SECRETEncryption secret (for encrypting database content) - CRYPTO_SECRET=your_crypto_secretFRONTEND_BASE_URLFrontend base URL - FRONTEND_BASE_URL=https://your-domain.comSYNC_FREQUENCYCache and database synchronization frequency (seconds) 60SYNC_FREQUENCY=60NODE_TYPENode type masterNODE_TYPE=slave
[!INFO] Cluster Deployment
For instructions on how to use these environment variables to build a complete cluster deployment, please refer to the Cluster Deployment Guide .
Environment Variable Description Default Value Example GENERATE_DEFAULT_TOKENGenerate initial Token for new registered users falseGENERATE_DEFAULT_TOKEN=trueNOTIFICATION_LIMIT_DURATION_MINUTENotification limit duration (minutes) 10NOTIFICATION_LIMIT_DURATION_MINUTE=15NOTIFY_LIMIT_COUNTMaximum number of notifications within the specified duration 2NOTIFY_LIMIT_COUNT=3
Environment Variable Description Default Value Example GLOBAL_API_RATE_LIMITGlobal API rate limit (per IP, three minutes) 180GLOBAL_API_RATE_LIMIT=100GLOBAL_WEB_RATE_LIMITGlobal Web rate limit (per IP, three minutes) 60GLOBAL_WEB_RATE_LIMIT=30RELAY_TIMEOUTRelay request timeout (seconds) 0RELAY_TIMEOUT=60STREAMING_TIMEOUTStreaming single response timeout (seconds) 300STREAMING_TIMEOUT=120MAX_FILE_DOWNLOAD_MBMaximum file download size (MB) 20MAX_FILE_DOWNLOAD_MB=50GLOBAL_API_RATE_LIMIT_ENABLEGlobal API rate limit switch trueGLOBAL_API_RATE_LIMIT_ENABLE=falseGLOBAL_API_RATE_LIMIT_DURATIONGlobal API rate limit window (seconds) 180GLOBAL_API_RATE_LIMIT_DURATION=120GLOBAL_WEB_RATE_LIMIT_ENABLEGlobal Web rate limit switch trueGLOBAL_WEB_RATE_LIMIT_ENABLE=falseGLOBAL_WEB_RATE_LIMIT_DURATIONGlobal Web rate limit window (seconds) 180GLOBAL_WEB_RATE_LIMIT_DURATION=120CRITICAL_RATE_LIMIT_ENABLECritical operation rate limit switch trueCRITICAL_RATE_LIMIT_ENABLE=falseCRITICAL_RATE_LIMITCritical operation rate limit count 20CRITICAL_RATE_LIMIT=10CRITICAL_RATE_LIMIT_DURATIONCritical operation rate limit window (seconds) 1200CRITICAL_RATE_LIMIT_DURATION=600
[!WARNING] RELAY_TIMEOUT Setting Warning
Exercise caution when setting the RELAY_TIMEOUT environment variable. Setting it too short may lead to the following issues:
The upstream API completes the request and charges, but the local system fails to complete billing due to timeout.
Causes billing desynchronization, potentially leading to system losses.
It is recommended not to set it unless you know what you are doing.
Environment Variable Description Default Value Example CHANNEL_UPDATE_FREQUENCYPeriodically update Channel balance (minutes) - CHANNEL_UPDATE_FREQUENCY=1440CHANNEL_TEST_FREQUENCYPeriodically check Channels (minutes) - CHANNEL_TEST_FREQUENCY=1440POLLING_INTERVALRequest interval when batch updating Channels (seconds) 0POLLING_INTERVAL=5
Environment Variable Description Default Value Example FORCE_STREAM_OPTIONOverride client stream_options parameter trueFORCE_STREAM_OPTION=falseGET_MEDIA_TOKENWhether to count image tokens trueGET_MEDIA_TOKEN=falseGET_MEDIA_TOKEN_NOT_STREAMWhether to count image tokens in non-streaming mode falseGET_MEDIA_TOKEN_NOT_STREAM=falseUPDATE_TASKWhether to update asynchronous tasks (MJ, Suno) trueUPDATE_TASK=falseCountTokenWhether to count text tokens trueCountToken=falseTASK_PRICE_PATCHTask price patch (comma separated) ""TASK_PRICE_PATCH=suno=0.8,mj=1.2
Environment Variable Description Default Value Example AZURE_DEFAULT_API_VERSIONAzure Channel default API version 2025-04-01-previewAZURE_DEFAULT_API_VERSION=2023-05-15COHERE_SAFETY_SETTINGCohere model safety setting NONECOHERE_SAFETY_SETTING=CONTEXTUALGEMINI_VISION_MAX_IMAGE_NUMGemini model maximum image count 16GEMINI_VISION_MAX_IMAGE_NUM=8DIFY_DEBUGDify Channel output workflow and node information trueDIFY_DEBUG=false
Environment Variable Description Default Value Example ERROR_LOG_ENABLEDWhether to record and display error logs on the frontend false ERROR_LOG_ENABLED=true
Environment Variable Description Default Value Example UMAMI_WEBSITE_IDUmami Website ID - UMAMI_WEBSITE_ID=xxxx-xxxxUMAMI_SCRIPT_URLUmami Script URL https://analytics.umami.is/script.jsUMAMI_SCRIPT_URL=https://umami.example.com/script.jsGOOGLE_ANALYTICS_IDGoogle Analytics Site ID - GOOGLE_ANALYTICS_ID=G-XXXXXXX
Environment Variable Description Default Value Example SYNC_UPSTREAM_BASEModel/Vendor metadata upstream address https://basellm.github.io/llm-metadataSYNC_UPSTREAM_BASE=https://mirror.example.com/llm-metadataSYNC_HTTP_TIMEOUT_SECONDSSync HTTP timeout (seconds) 10SYNC_HTTP_TIMEOUT_SECONDS=15SYNC_HTTP_RETRYSync retry count 3SYNC_HTTP_RETRY=5SYNC_HTTP_MAX_MBMaximum response body size (MB) 10SYNC_HTTP_MAX_MB=20
Environment Variable Description Default Value Example VITE_REACT_APP_SERVER_URLFrontend base address for backend requests - VITE_REACT_APP_SERVER_URL=https://api.example.com
The following environment variables have been deprecated. Please use the corresponding options in the System Settings interface:
Environment Variable Alternative Method GEMINI_MODEL_MAPPlease set in System Settings - Model Related Settings GEMINI_SAFETY_SETTINGPlease set in System Settings - Model Related Settings
In multi-machine deployment scenarios, the following environment variables must be set:
# 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
# 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: Sync Frequency
SYNC_FREQUENCY = 60
[!TIP] Complete Cluster Configuration
This is just a basic multi-node configuration example. For complete cluster deployment configuration, architectural description, and best practices, please refer to the Cluster Deployment Guide .
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.
No modification is required under normal circumstances
Environment Variable Description Default Value Example LINUX_DO_TOKEN_ENDPOINTLinuxDo Token Endpoint https://connect.linux.do/oauth2/tokenLINUX_DO_TOKEN_ENDPOINT=https://connect.linux.do/oauth2/tokenLINUX_DO_USER_ENDPOINTLinuxDo User Endpoint https://connect.linux.do/api/userLINUX_DO_USER_ENDPOINT=https://connect.linux.do/api/user
Environment Variable Description Default Value Example ENABLE_PPROFEnable pprof performance analysis falseENABLE_PPROF=trueDEBUGEnable debug mode falseDEBUG=trueGIN_MODEGin running mode - GIN_MODE=release