Skip to content

About

Local API proxy for DeepSeek Web Chat with support for OpenAI/Anthropic API, streaming, tool calling, Responses API, and Open WebUI

Resources

Stars

2 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

FreeDeepseekAPI

Local OpenAI-compatible API proxy for DeepSeek Web Chat

License MIT Node.js 18 plus No npm dependencies OpenAI compatible

Quick Start • Features • Examples • Models • Endpoints • Open WebUI

FreeDeepseekAPI launches a local API server for DeepSeek Web Chat (chat.deepseek.com) and allows connecting DeepSeek Web to Open WebUI, LiteLLM, Hermes, Claude Code, OpenAI SDK-style clients, and other OpenAI-compatible tools.

The project works through your regular logged-in DeepSeek account in a separate Chrome profile. The local server accepts API requests and then itself accesses DeepSeek Web through the saved browser session.

⚠️ This is an experimental web-chat proxy. DeepSeek may change the internal Web API without notice. For production cases, the official paid DeepSeek API is more reliable.

ForgetMeAI: https://t.me/forgetmeai


Navigation


✨ What this gives

  • Use DeepSeek Web as a local API endpoint.
  • Connect DeepSeek to Open WebUI and other OpenAI-compatible clients.
  • Receive regular JSON responses or streaming SSE.
  • Use reasoning models with a separate reasoning_content.
  • Work with the Anthropic Messages API shim for Claude Code / Anthropic SDK.
  • Use the OpenAI Responses API shim for new OpenAI/Codex-style clients.
  • Maintain separate web sessions for different agents/users.

🚀 Features

  • OpenAI-compatible API: POST /v1/chat/completions
  • Anthropic-compatible shim: POST /v1/messages
  • OpenAI Responses shim: POST /v1/responses
  • Streaming: SSE chunks and regular non-stream JSON responses
  • Reasoning output: separate reasoning_content for thinking models
  • Tool calling: parsing OpenAI tools, Anthropic tools, and Responses function tools
  • Model capabilities: GET /v1/model-capabilities with alias → real web mode
  • Agent sessions: separate DeepSeek session per user / agent id- Session recovery: auto-reset of outdated chains/sessions
  • Zero dependencies: Node.js 18, without npm dependencies

⚡ Quick Start

git clone https://github.com/ForgetMeAI/FreeDeepseekAPI.git
cd FreeDeepseekAPI
npm run auth
npm start

npm run auth opens the authorization menu:

  1. select item 1;
  2. log into DeepSeek in a separate Chrome profile;
  3. send a short message like ok;
  4. return to the terminal and press Enter.

npm start shows the launch menu:

  • 1 — authorize / update DeepSeek login
  • 2 — show models and statuses
  • 3 — start proxy
  • 4 — exit

For headless/CI launch without a menu:

NON_INTERACTIVE=1 npm start
# or
SKIP_ACCOUNT_MENU=1 npm start

By default, the server listens on:

http://localhost:9655

By default, the proxy is only accessible from this computer. To access from the network explicitly, set the address and a separate proxy key:

HOST=0.0.0.0 PROXY_API_KEY='replace-with-a-long-random-value' npm start

After that, pass the key as Authorization: Bearer <key>. Without a PROXY_API_KEY, non-health endpoints remain unauthorized, so do not publish such an instance to the network.

Browser requests are allowed from loopback origin. If the UI is open at another address, add its exact origin separated by a comma, for example PROXY_CORS_ORIGINS=https://ui.example.com,http://192.168.1.20:3000.


🪟 Windows launch

git clone https://github.com/ForgetMeAI/FreeDeepseekAPI.git
cd FreeDeepseekAPI
npm run auth
npm start

If Chrome is installed in a non-standard location, explicitly specify the path:

$env:CHROME_PATH="C:\Program Files\Google\Chrome\Application\chrome.exe"
npm run auth

If Chrome is not found, npm run auth now prints ready instructions for Windows/macOS/Linux instead of a mysterious stack trace.


🐧 Linux / Chromium launch

git clone https://github.com/ForgetMeAI/FreeDeepseekAPI.git
cd FreeDeepseekAPI
CHROME_PATH=$(which chromium) npm run auth
npm start

Если Chromium называется иначе:

CHROME_PATH=$(which chromium-browser) npm run auth
# или
CHROME_PATH=$(which google-chrome) npm run auth

🖥 VPS / headless запуск

Самый надёжный flow без Chrome на сервере:

  1. На домашнем ПК, где есть GUI/Chrome:
npm run auth
  1. Скопируйте deepseek-auth.json на VPS:
scp deepseek-auth.json user@your-vps:/opt/FreeDeepseekAPI/deepseek-auth.json
  1. На VPS импортируйте/проверьте файл и выставьте безопасные права:
cd /opt/FreeDeepseekAPI
npm run auth:import -- --input ./deepseek-auth.json
npm run doctor -- --offline
  1. Запускайте proxy без интерактивного меню:
NON_INTERACTIVE=1 npm start

Можно импортировать не только готовый deepseek-auth.json, но и browser cookie export:

DEEPSEEK_TOKEN="<token>" npm run auth:import -- --input ./cookies.json

Important: deepseek-auth.json is access to your DeepSeek Web login. Do not commit, do not publish, store with 0600 permissions.


🦭 Rootless Podman

The container is intended only for non-interactive proxy runs. Perform browser authentication on the host with the command npm run auth: auth scripts and deepseek-auth.json are not copied into the image.

Run Podman as a regular user, without sudo.

  1. Build the local image:
podman build --tag localhost/free-deepseek-api:local --file Containerfile .
  1. Pass DeepSeek auth and a separate proxy key via Podman secrets:
podman secret create --replace free-deepseek-auth ./deepseek-auth.json

printf 'Proxy API key: '
IFS= read -r -s PROXY_API_KEY
printf '\n'
printf '%s' "$PROXY_API_KEY" |
  podman secret create --replace free-deepseek-proxy-key -

Use a long random key. The value will remain in the 'PROXY_API_KEY' of the current shell to check the API; it does not fall into the image or Podman command line.

  1. Run a container with least privileges:
podman run --detach \
  --name free-deepseek-api \
  --publish 127.0.0.1:9655:9655 \
  --secret free-deepseek-auth,target=deepseek-auth.json,uid=1000,gid=1000,mode=0400 \
  --secret free-deepseek-proxy-key,target=proxy-api-key,uid=1000,gid=1000,mode=0400 \
  --read-only \
  --cap-drop=ALL \
  --security-opt=no-new-privileges \
  localhost/free-deepseek-api:local

Inside the container, 'NON_INTERACTIVE=1', 'HOST=0.0.0.0' and Paths to both Secrets. 'REQUIRE_PROXY_API_KEY=1' will prevent the container from starting, if the secret with the key is missing or empty. On the host, the port is published only to 127.0.0.1; Do not remove this address without a separate network firewall/access policy.

  1. Check the liveness, readiness of the account, and the secure endpoint:
podman healthcheck run free-deepseek-api
curl --fail http://127.0.0.1:9655/readyz
curl --fail \
  -H "Authorization: Bearer $PROXY_API_KEY" \
  http://127.0.0.1:9655/v1/models

Встроенный healthcheck проверяет локальный /health (жив ли процесс). /readyz дополнительно вернёт 503, если ни один DeepSeek auth-аккаунт сейчас не готов обслуживать запросы. Диагностика контейнера:

podman logs free-deepseek-api
podman inspect --format '{{. State.Health.Status}}' free-deepseek-api

Остановка и удаление контейнера вместе с сохранёнными Podman secrets:

podman stop free-deepseek-api
podman rm free-deepseek-api
podman secret rm free-deepseek-auth free-deepseek-proxy-key
unset PROXY_API_KEY

При ротации auth или proxy key замените соответствующий secret и пересоздайте контейнер, чтобы поведение не зависело от версии Podman.


🩺 Diagnostics / doctor

npm run doctor
# без сетевых запросов к DeepSeek:
npm run doctor -- --offline

doctor checks:

  • whether deepseek-auth.json / DEEPSEEK_AUTH_DIR is found;
  • whether the JSON is valid;
  • whether there is a token, cookie, wasmUrl;
  • whether the file permissions are safe on macOS/Linux (0600);
  • when run normally — whether the DeepSeek PoW endpoint is accessible.

If you see data.biz_data is null, fetch failed, 401/403/429, or Hermes/OpenCode cannot see the models — the first thing to do is run npm run doctor.


♻️ Session reuse and chat reset

FreeDeepseekAPI does not create a new DeepSeek chat for every HTTP request without reason. The logic is as follows:

  • one x-agent-session, session or user → one DeepSeek chat session;
  • if the session ID already exists — the proxy reuses it and continues the chain via parent_message_id;
  • auto-reset occurs on TTL, DeepSeek session error, or if the message chain is too long;
  • local history is saved with a short context so that a new DeepSeek session can continue the conversation.
  • Long Agent requests are limited to 'DEEPSEEK_MAX_PROMPT_CHARS' before sending (80,000 characters by default): the start of the task, fresh Tool Results and Tool Adapter are saved;
  • if the client has already sent multi-turn history, the local recovery-history is not added a second time;
  • An empty response is repeated a maximum of 'DEEPSEEK_MAX_RETRIES' times (default is 2), and on each retry the context is reduced.

Explicitly set agent/session:

curl -X POST http://localhost:9655/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "x-agent-session: my-agent" \
  -d '{"model":"deepseek-chat","messages":[{"role":"user","content":"Hello"}]}'

View active sessions:

curl http://localhost:9655/v1/sessions

Reset one session:

curl -X POST "http://localhost:9655/reset-session?agent=my-agent"

Reset all sessions:

curl -X POST "http://localhost:9655/reset-session?agent=all"

Why chats still appear in DeepSeek Web: the proxy works through the internal Web Chat API, while DeepSeek stores the actual chat sessions itself. This is normal for a web proxy. The task of session reuse is not to create new chats unnecessarily and to reset carefully only when the chain has expired/broken.


👥 Multi-account pool

You can connect several auth files. The correct model: sticky account per agent/session — the proxy does not switch accounts within a live DeepSeek session. If an account receives 401/403/429 and goes into cooldown, the session is safely reset and a new request can go to another available account.

Option 1 — directory with auth files:

mkdir -p accounts
cp deepseek-auth-main.json accounts/main.json
cp deepseek-auth-backup.json accounts/backup.json
chmod 600 accounts/*.json
DEEPSEEK_AUTH_DIR=./accounts NON_INTERACTIVE=1 npm start

Option 2 — list of files:

DEEPSEEK_AUTH_PATH="./accounts/main.json,./accounts/backup".json" NON_INTERACTIVE=1 npm start

How the pool works:

  • a new agent/session gets an available account round-robin;
  • the selected account is bound to the session (sticky);
  • on 401, 403, 429, the account goes into cooldown;
  • if the session's sticky account goes into cooldown, the old DeepSeek session is reset to avoid hammering a rate-limited/expired account;
  • account status is visible at /health without paths to auth files and without file names;
  • auth files must be stored with 0600 permissions.

Set cooldown:

DEEPSEEK_ACCOUNT_COOLDOWN_MS=600000 npm start

🔑 Ideas for console authorization

The password flow from PR #3 can be implemented, but it’s safer not to store the password and not make it default. Proper implementation:

  1. npm run auth:console asks for email/phone and password via hidden prompt.
  2. The password is kept only in process memory, not written to files/logs/history.
  3. The script repeats the Web login flow via fetch/CDP: it receives a captcha/verification challenge, gives the user a link/code, waits for confirmation.
  4. After successful login, only the standard format deepseek-auth.json is saved.
  5. If DeepSeek requests captcha/2FA — the script honestly says “open the link, complete the verification, press Enter,” rather than trying to bypass protection.
  6. For VPS, the auth:console --no-save-password --output deepseek-auth.json mode is better.

Minimum safe MVP: console auth only interactive, without env-password. Allowed automation variant: DEEPSEEK_EMAIL=... npm run auth:console, but the password is still entered via hidden prompt.


✅ Checking operation

curl http://localhost:9655/
curl http://localhost:9655/v1/models
curl http://localhost:9655/v1/model-capabilities

If everything is fine, /health will return the server status, a list of supported aliases, and config_ready: true.


🧪 Example requests

Chat Completions

curl -X POST http://localhost:9655/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-chat",
    "messages": [{"role": "user", "content": "Привет! Ответь одной фразой."}],
    "stream": false
  }'

Reasoning

curl -X POST http://localhost:9655/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-reasoner",
    "messages": [{"role": "user", "content": "Реши коротко: почему небо голубое?"}],
    "stream": false
  }'

Для reasoning-моделей API отдаёт цепочку размышления отдельно от финального ответа:

  • non-stream: choices[0].message.reasoning_content
  • stream: choices[0].delta.reasoning_content
  • usage: usage.completion_tokens_details.reasoning_tokens

reasoning_tokens — приблизительная оценка по извлечённому DeepSeek Web THINK-тексту, потому что web stream не отдаёт официальный token usage по reasoning отдельно.

Web search

curl -X POST http://localhost:9655/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-chat-search",
    "messages": [{"role": "user", "content": "Найди свежий факт про DeepSeek и ответь кратко."}],
    "stream": false
  }'

Streaming

curl -N -X POST http://localhost:9655/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-chat",
    "messages": [{"role": "user", "content": "Напиши короткую шутку."}],
    "stream": true
  }'

Anthropic Messages API

curl -X POST http://localhost:9655/v1/messages \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-chat",
    "max_tokens": 512,
    "messages": [{"role": "user", "content": "Ответь ровно OK"}],
    "stream": false
  }'

Для Claude Code можно указывать backend напрямую:

export ANTHROPIC_BASE_URL="http://127.0.0.1:9655"
export ANTHROPIC_AUTH_TOKEN="dummy-key"
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
claude --model deepseek-chat

OpenAI Responses API

curl -X POST http://localhost:9655/v1/responses \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-chat",
    "input": "Answer exactly OK",
    "stream": false
  }'

Tool calling

FreeDeepseekAPI accepts:

  • OpenAI tools;
  • Anthropic tools;
  • Responses API function tools.

The proxy asks DeepSeek to return strict JSON tool call, but it can also parse fallback formats:

  • TOOL_CALL:
  • fenced JSON with an explicit tool_call, tool_calls, or function_call envelope
  • <tool_call>...</tool_call>
  • DeepSeek DSML (<|DSML|tool_calls>...) and the Web variant with <||DSML|| Tool Calls>

🧠 Models

GET /v1/models returns only aliases that are currently verified and working through this proxy.

Working aliases

Alias Web mode Reasoning Web search Comment
deepseek-chat Fast / default no no basic chat
deepseek-v3 Fast / default no no compatible alias
deepseek-default Fast / default no no compatible alias
deepseek-reasoner Fast / default yes no thinking_enabled=true
deepseek-r1 Fast / default yes no R1-compatible alias
deepseek-chat-search Fast / default no yes web search
deepseek-default-search Fast / default no yes web search alias
deepseek-reasoner-search 'Fast' / 'default' Yes Yes reasoning search
deepseek-r1-search 'Fast' / 'default' Yes Yes R1-compatible search
deepseek-expert 'expert' Yes Yes Expert mode
deepseek-v4-pro 'expert' Yes Yes Expert reasoning

Full mapping:

curl http://localhost:9655/v1/model-capabilities

According to the official DeepSeek V4 Preview page, 'deepseek-chat' and 'deepseek-reasoner' are now routed to 'deepseek-v4-flash' non-thinking/thinking. In the 'chat.deepseek.com' direct stream itself, the exact name of the checkpoint is not given ('model: ""'), so the proxy fixes both the web mode ('default') and the current official routing ('DeepSeek-V4-Flash').

The current output of the DeepSeek Web remote config shows the following web modes:

  • default / UI Quick — works; supports thinking_enabled and search_enabled.
  • expert / UI Expert — works via the current web contract (x-client-version=2.0.0) and supports thinking_enabled. In /v1/models, deepseek-expert is returned without reasoning and deepseek-v4-pro as Expert reasoning.
  • vision / UI Recognition — visible in remote config, but currently the direct Web API returns backend_err_by_model (Vision is temporarily unavailable). Therefore, deepseek-vision is hidden from /v1/models.

Search for Expert via remote config is unavailable, so deepseek-expert-search remains unsupported.


🔌 Endpoints

Method Path Purpose
GET / or /health proxy status
GET /v1/models list of working OpenAI-compatible aliases
GET /v1/model-capabilities full mapping of aliases, real model, capabilities
POST /v1/chat/completions OpenAI-compatible Chat Completions
POST /v1/messages Anthropic Messages API shim
POST /v1/responses OpenAI Responses API shim
GET /v1/sessions active local agent sessions
POST /reset-session?agent=<id> reset one session
POST /reset-session?agent=all reset all sessions

🖥 Open WebUI

Base URL for Open WebUI in Docker:

http://host.docker.internal:9655/v1

For local launch without Docker:

http://localhost:9655/v1
```If `PROXY_API_KEY` is not set, you can specify any API key. If a key is set, the client must provide exactly that one — the proxy checks the bearer token before accessing models, sessions, and completions.

---

## 🔐 Update login

```bash
npm run auth
npm start

If DeepSeek starts responding with 401, 403, or asks for a new PoW/session — repeat npm run auth and update the saved browser session.

Local authorization files should not be pushed to GitHub:

  • deepseek-auth.json
  • .chrome-profile-deepseek/
  • .env

They are already added to .gitignore.


🧪 Tests

Syntactic check of the project:

npm test

Live smoke tests against the running local proxy:

BASE_URL=http://127.0.0.1:9655 MODEL=deepseek-chat npm run test:live

📌 Project status

FreeDeepseekAPI is an experimental web-chat proxy for local use and integrations.. It depends on the current DeepSeek Web Chat contract, so when changes occur on DeepSeek's side, updating the auth/session logic or model mapping may be required.

If something has stopped working:

  1. update login via npm run auth;
  2. check /v1/model-capabilities;
  3. retry the request with a fresh session;
  4. if the problem persists — DeepSeek has probably changed the internal Web API.

ForgetMeAI · Telegram

About

Local API proxy for DeepSeek Web Chat with support for OpenAI/Anthropic API, streaming, tool calling, Responses API, and Open WebUI

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages