Deploy New API Locally, Connect Upstream LLMs, and Fix v1.0 Model Routing Bugs
Deploy New API with a production Docker Compose stack (PostgreSQL 15 and Redis), connect upstream LLM channels, and fix v1.0 RC Passkey lockouts, Qwen3.8 routing 400s.
Summary
- Run New API in production with PostgreSQL 15 and Redis via Docker Compose instead of default SQLite.
- Configure upstream channels for OpenAI, Anthropic Claude, Google Gemini, DeepSeek, and Qwen with multi-key polling, priority tiers, and protocol translation.
- Fix three common v1.0 RC failures: admin Passkey login lockouts.
Running New API (QuantumNous/new-api) with a single docker run command works for a five-minute local test, but it defaults to an embedded SQLite database (one-api.db) and in-memory rate limiting. As soon as you point coding agents like Codex or Claude Code at a SQLite-backed instance, concurrent streaming requests and token quota deductions lock the database file and stall responses. A production deployment requires a three-container Docker Compose stack: the new-api gateway, PostgreSQL 15 for transactional storage, and Redis for two-tier quota and channel health caching.
Before pulling the image, pay attention to the version tag. The official documentation examples use calciumion/new-api:latest, which currently tracks the v1.0.0-rc release line (v1.0.0-rc.36 through v1.0.0-rc.51). In New API, v1.0 is an active breaking-change branch where each release candidate introduces new architecture—such as the experimental plugin system added in rc.27 that wiped existing video model pricing—while 0.x remains the conservative stable branch. Never run :latest with automatic container updates in production. Pin a verified release candidate tag or stay on a fixed 0.x release until you have tested the upgrade path.
On this page
Production Docker Compose Configuration (PostgreSQL 15 + Redis)
Create a dedicated directory for the gateway and write a docker-compose.yml file that pairs New API with PostgreSQL 15 and Redis. The configuration below includes batch database updates and extended streaming timeouts that prevent premature disconnects on long-horizon reasoning models.
version: '3.4'
services:
new-api:
image: calciumion/new-api:v1.0.0-rc.36
container_name: new-api
restart: always
command: --log-dir /app/logs
ports:
- "3000:3000"
volumes:
- ./data:/data
- ./logs:/app/logs
environment:
- SQL_DSN=postgresql://root:ChangeThisStrongPassword123@postgres:5432/new-api
- REDIS_CONN_STRING=redis://redis:6379
- TZ=Asia/Shanghai
- ERROR_LOG_ENABLED=true
- BATCH_UPDATE_ENABLED=true
- BATCH_UPDATE_INTERVAL=5
- STREAMING_TIMEOUT=300
- SESSION_SECRET=c8f2a1b9e4d74a22b9319e7f8d6c35a1
- SYNC_FREQUENCY=60
depends_on:
- redis
- postgres
healthcheck:
test:
[
"CMD-SHELL",
"wget -q -O - http://localhost:3000/api/status | grep -o '\"success\":\\s*true' || exit 1"
]
interval: 30s
timeout: 10s
retries: 3
redis:
image: redis:latest
container_name: redis
restart: always
command: redis-server --appendonly yes
volumes:
- redis_data:/data
postgres:
image: postgres:15
container_name: postgres
restart: always
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: ChangeThisStrongPassword123
POSTGRES_DB: new-api
volumes:
- pg_data:/var/lib/postgresql/data
volumes:
pg_data:
redis_data:
If your infrastructure standardizes on MySQL instead of PostgreSQL, replace the postgres service block with mysql:8.2, mount mysql_data:/var/lib/mysql, and change SQL_DSN to root:ChangeThisStrongPassword123@tcp(mysql:3306)/new-api.
Several environment variables in this file directly affect gateway stability:
SESSION_SECRET signs session tokens and acts as the default HMAC key (CRYPTO_SECRET) for Redis cache entries. Do not copy the placeholder value random_string from older template comments; New API explicitly checks for random_string on startup and refuses to boot if it sees it. If you run multiple New API nodes behind a load balancer, every node must share the exact same SESSION_SECRET and SQL_DSN.
REDIS_CONN_STRING activates New API's local memory cache alongside Redis to cut down database reads on every API call. Note that New API only parses a single Redis endpoint in REDIS_CONN_STRING and does not natively handle Redis Cluster or Sentinel node lists. If you use a clustered Redis setup, point REDIS_CONN_STRING at a single proxy or managed endpoint.
BATCH_UPDATE_ENABLED=true and BATCH_UPDATE_INTERVAL=5 tell the gateway to aggregate token quota deductions in memory and flush them to PostgreSQL every 5 seconds instead of running an UPDATE query after every single completion. Under heavy parallel traffic, this setting prevents row-level lock contention on user and token records.
Start the stack in the background and verify that all three containers pass their health checks:
mkdir -p new-api && cd new-api
# Save the YAML above as docker-compose.yml
docker compose up -d
docker compose ps
docker compose logs --tail=100 -f new-api
Once new-api reports that it is listening on port 3000, open http://<your-server-ip>:3000 in your browser. Older builds initialized with a hardcoded root / 123456 account, but current versions redirect first-time visitors to an initialization wizard where you create the administrator username and password directly.
Connecting Upstream LLM Channels and Multi-Key Polling
After signing in to the console, go to Channel Management (/console/channel) and click Add Channel. New API normalizes different provider protocols so your local clients can send standard OpenAI-format requests (or Anthropic Messages requests) to any upstream model.
| Upstream Provider | Channel Type in New API | Default Base URL | Recommended Models | Protocol & Routing Notes |
|---|---|---|---|---|
| OpenAI | OpenAI (Type 1) |
https://api.openai.com |
gpt-4o, gpt-4o-mini, o1, o1-mini |
Native tool calling and streaming. Automatically converts system role prompts to developer for o1 reasoning models. |
| Anthropic Claude | Anthropic Claude (Type 14) |
https://api.anthropic.com |
claude-3-5-sonnet-20241022, claude-3-5-haiku-20241022 |
Performs bidirectional translation between OpenAI Chat Completions and Anthropic /v1/messages. |
| Google Gemini | Google Gemini (Type 24) |
https://generativelanguage.googleapis.com |
gemini-1.5-pro-latest, gemini-1.5-flash-latest, gemini-2.0-flash-exp |
Paste the AIza... key from Google AI Studio. |
| DeepSeek | OpenAI (Type 1 Compatible) |
https://api.deepseek.com |
deepseek-chat, deepseek-reasoner |
Fully OpenAI-compatible. Preserves reasoning_content chunks during deepseek-reasoner streams. |
| Alibaba Cloud Qwen (DashScope) | OpenAI (Type 1 Compatible) |
https://dashscope.aliyuncs.com/compatible-mode/v1 |
qwen-max, qwen-plus, qwen-turbo, qwen3.8-27b |
Use the /compatible-mode/v1 base URL rather than the native DashScope endpoint. |
When you configure multiple channels serving the same model name, New API routes traffic using two numbers in the channel settings: Priority and Weight. Priority is a strict tier integer (default 0). New API always sends requests to channels in the highest priority tier first and only falls back to lower-priority channels when every high-priority channel fails or gets disabled. Weight controls the load-balancing ratio among channels that share the exact same priority integer.
If you have several API keys from the same provider, you do not need to create a separate channel for each key. Open the channel editor, switch to Multi-Key Management, and paste one API key per line. You can set the internal key rotation policy to Round Robin or Weighted Random. When a specific key returns HTTP 429 (rate limit) or HTTP 401 (exhausted quota), New API temporarily shelves that key and routes subsequent calls to the remaining active keys in the pool. If your clients still surface 429 errors during traffic spikes, see our guide on tuning pool cooldowns and concurrency to fix "exceeded retry limit, last status: 429 Too Many Requests" in New API.
Fixing v1.0 RC Routing, Login, and Streaming Bugs
Upgrading through the v1.0.0-rc.36 to v1.0.0-rc.51 series exposes three recurring failure modes that are not covered in the standard installation docs.
1. Admin Login Fails with "This Verification Method Is Currently Unavailable" (此验证方式当前不可用)
On v1.0.0-rc.37 and later, administrators sometimes get locked out of the web console with the red error banner 此验证方式当前不可用 ("This verification method is currently unavailable"). Running the CLI password reset script updates the password hash in the database, but the login page still rejects the account with the exact same message.
This deadlock happens when an administrator previously bound a WebAuthn Passkey in their personal security settings, and Passkey authentication was later turned off globally in the system configuration (or the admin moved to a browser or non-HTTPS origin where WebAuthn cannot initialize). When New API sees a Passkey record attached to the user row, it forces the login request down the Passkey verification branch and blocks password authentication, even though the global Passkey service is disabled.
To break the deadlock without wiping the database, either re-enable Passkey support in your configuration and sign in with your hardware key, or connect directly to your PostgreSQL (or MySQL) container and clear the Passkey binding on the admin account:
docker exec -it postgres psql -U root -d new-api
-- Clear the Passkey binding on the root/admin account to restore password login
UPDATE users SET passkey = NULL WHERE username = 'root';
If your schema revision uses a separate webauthn_credentials table, delete the rows matching your admin user's id in that table as well, then restart new-api to flush the cached user object.
2. Intermittent HTTP 400 The model 'qwen3.8-27b' does not exist After Removing Model Mapping
A common routing bug in v1.0.0-rc.45 and nearby builds appears after you use Model Mapping (model redirection) to temporarily reroute traffic. Suppose Channel 1 serves qwen3.8-27b natively. You disable qwen3.8-27b on Channel 1 and set a Model Mapping rule on Channel 2 to rewrite {"qwen3.8-27b": "mimo-v2.6-flash"}. Later, you turn off that Model Mapping rule on Channel 2 and re-enable qwen3.8-27b on Channel 1. Instead of cleanly routing back to Channel 1, client requests begin failing intermittently with:
status_code=400, The model 'qwen3.8-27b' does not exist.
Two mechanisms inside New API combine to cause this error:
First, deleting or clearing the JSON in Model Mapping does not automatically remove qwen3.8-27b from Channel 2's Models tag list. New API's router selects candidate channels by checking the Models list first. Because qwen3.8-27b is still listed as an available model on Channel 2, the scheduler continues assigning ~50% of requests to Channel 2. With the mapping gone, Channel 2 forwards the literal string "qwen3.8-27b" to an upstream provider that only knows mimo-v2.6-flash, triggering the upstream 400 error.
Second, New API uses channel stickiness (session affinity) when handling multi-turn coding agents. Once an agent session is pinned to Channel 2 in Redis, New API keeps routing subsequent turns from that client to Channel 2 until the affinity TTL expires.
To fix this completely:
- Open Channel 2 in
/console/channel, look at the Models selection box, and manually deleteqwen3.8-27bwhenever you remove its mapping rule. - If requests still hit the wrong channel due to session stickiness, delete Channel 2 and recreate it (or flush Redis) so the cached routing table and sticky session bindings are purged immediately.
3. Mid-Stream unexpected EOF Disconnects That Still Deduct Quota
When running long reasoning prompts or large file edits in v1.0.0-rc.45 through rc.51, streams can drop mid-generation with unexpected EOF or stream disconnected before completion, while New API still writes a completion log entry and deducts the consumed tokens from the user's quota.
This happens at three different points in the network path:
First, if you left STREAMING_TIMEOUT at its 120-second default, New API closes the upstream connection internally whenever a reasoning model pauses longer than two minutes between chunks or takes too long to finish a massive response. Setting STREAMING_TIMEOUT=300 (or 600) in docker-compose.yml stops the container from killing slow streams prematurely.
Second, if you put Nginx in front of port 3000 for HTTPS termination, Nginx's default proxy_buffering on and 60-second proxy_read_timeout buffer Server-Sent Events (SSE) in memory and sever idle connections before New API finishes streaming. Update your Nginx location / block to disable buffering and keep HTTP/1.1 chunked connections open:
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Required for SSE streaming without premature EOF
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding on;
}
For deeper proxy-level debugging when coding agents drop mid-reply, see our guides on fixing stream closed before response.completed by disabling proxy buffering and resolving stream disconnected before completion: Upstream request failed.
Third, if the upstream provider itself is overloaded and drops the TCP connection mid-stream (or injects an overload error payload), New API receives an EOF from the upstream socket and bills the tokens generated up to the failure point. Enable automatic channel retries in System Settings and configure a secondary fallback channel at a lower priority tier so failed requests fail over cleanly.
Connecting Coding Clients and Testing Your Gateway
Once your channels are active, open Token Management (/console/token) to generate a gateway API key (sk-...). Your unified OpenAI-compatible Base URL is http://<your-server-ip>:3000/v1 (or https://api.yourdomain.com/v1 behind Nginx). If you are connecting Claude Code v2.1.319 or newer to your New API instance, make sure you also check our Claude Code v2.1.319 CLAUDE_CODE_AUTO_MODE_SERVER=0 gateway fix so Auto Mode prompts do not fail behind a custom Base URL.
Instead of editing JSON and TOML config files by hand for every client, you can use our free, open-source LLM API Config GUI (available for Windows and macOS) to plug your self-hosted New API Base URL, API key, and model IDs directly into Codex, Claude Code, and CC Switch, and run a one-click connection test to diagnose 401, 403, 404, 429, or timeout issues before starting a coding session.


