⚠️ Use at your own risk. Read DISCLAIMER.md before running this.This project talks to the undocumented web API of chat.deepseek.com. Using it may violate DeepSeek's Terms of Service and get your account permanently banned. The author takes no responsibility for banned accounts, blocked IPs, incorrect model output, or any other consequences. The software is provided AS IS. Use a throwaway account you don't mind losing.
An OpenAI-compatible local proxy in front of
chat.deepseek.com. Drops any OpenAI SDK or
curl script straight onto DeepSeek's free web-API — the proxy handles
the proof-of-work challenge, AWS-WAF cookies and the streaming format
quirks for you.
┌─────────────────────────────────────────┐
┌──────┐ │ POST /v1/chat/completions (OpenAI) │ ┌────────────┐
│ your │───▶│ POST /admin/refresh-cookies (admin) │───▶│ chat.deep │
│ app │ │ GET /v1/models │ │ seek.com │
└──────┘ │ │ └────────────┘
│ session pool, POW solver, │
│ auto cookie refresh (Chrome+xvfb) │
└─────────────────────────────────────────┘
- OpenAI-compatible
/v1/chat/completions— blocking and SSE streaming. - Supports both DeepSeek models:
deepseek-chat— V3, no reasoningdeepseek-reasoner— R1, with thinking traces
- Session pool with rotation — every DeepSeek completion normally
needs a
create_chat_sessioncall first. We keep one session per(token, thinking, search)tuple and rotate afterDEEPSEEK_SESSION_REUSE_LIMITcalls. Amortises RTT and keeps the model's context clean. - Correct system-prompt handling — DeepSeek's web API has no
systemrole; we prepend system messages into the prompt so SDK behaviour matches OpenAI. - Admin endpoints for self-healing —
POST /admin/refresh-cookiesre-runs the Chrome-based WAF bypass and clears session caches;GET /admin/healthexposes cookie freshness and pool sizes. Auth via the same Bearer token as the DeepSeek proxy. - Both SSE formats supported — legacy OpenAI-style
choices[].deltaand the newer JSON-Patch operations ({"p":"response/content","o":"APPEND","v":"tok"}). If DeepSeek flips again, only_iter_parsedindsk/api.pyneeds to learn the new shape. - Docker image with Chrome + Xvfb baked in — cookie refresh works on a headless server without any host setup.
- Logging via the stdlib
loggingmodule, configurable viaLOG_LEVEL=DEBUG.
- Open https://chat.deepseek.com and log in.
- DevTools (F12) → Console →
JSON.parse(localStorage.getItem("userToken")).value
- Copy the ~60-character string.
git clone https://github.com/afterburnerr/FreeDeepSeekAPI.git
cd FreeDeepSeekAPI
cp .env.example .env
$EDITOR .env # set DEEPSEEK_AUTH_TOKEN
docker build -t freedeepseekapi .
docker run -d --name deepseek \
--restart unless-stopped \
-p 127.0.0.1:8080:8080 \
--env-file .env \
--shm-size=512m \
-v deepseek-cookies:/app/dsk \
freedeepseekapi
# smoke-test
curl http://127.0.0.1:8080/v1/modelsThe image ships Chrome + Xvfb + DrissionPage, so
POST /admin/refresh-cookies works out-of-the-box on any headless host.
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env && $EDITOR .env
python main.py
# -> listens on http://127.0.0.1:8080For cookie refresh on the host you'll also need Chrome and an X display
(real one or xvfb-run). ./refresh_cookies.sh handles the rest.
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="unused")
resp = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)Or via curl:
curl http://127.0.0.1:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-chat",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": false
}'Streaming works just like with OpenAI ("stream": true, SSE data: frames).
python smoke_test.py
# or
TOKEN="$DEEPSEEK_AUTH_TOKEN" BASE=http://127.0.0.1:8080 python smoke_test.py| Method | Path | Auth | Purpose |
|---|---|---|---|
POST |
/v1/chat/completions |
Bearer or DEEPSEEK_AUTH_TOKEN env |
OpenAI-compatible completion (stream + non-stream). Extra non-OpenAI field: search_enabled (bool). |
GET |
/v1/models |
— | Lists deepseek-chat and deepseek-reasoner. |
POST |
/admin/refresh-cookies |
Bearer = ADMIN_SECRET (fallback: DEEPSEEK_AUTH_TOKEN) |
Run refresh_cookies.sh, clear session/client caches. |
GET |
/admin/health |
Bearer = ADMIN_SECRET |
Cookie presence + pool sizes. |
Non-OpenAI response field: every /v1/chat/completions response includes
a deepseek_session object with chat_id, use, limit so callers can
tell whether they're on a fresh or reused session.
All configuration is via environment variables; see .env.example
for the full list with defaults.
Key ones:
| Env | Default | Notes |
|---|---|---|
DEEPSEEK_AUTH_TOKEN |
(empty) | Fallback token if client omits Authorization. |
DEEPSEEK_SESSION_REUSE_LIMIT |
30 |
Completions per DeepSeek chat session before rotating. |
DEEPSEEK_SEARCH_DEFAULT |
false |
Default for search_enabled if not in request. |
ADMIN_SECRET |
= DEEPSEEK_AUTH_TOKEN |
Bearer secret for /admin/*. |
HOST / PORT |
127.0.0.1 / 8080 |
In Docker usually HOST=0.0.0.0. |
LOG_LEVEL |
INFO |
DEBUG shows stream parsing. |
DeepSeek's edge protection (was Cloudflare, now AWS WAF) hands out a short-lived clearance cookie. When it expires, every completion starts returning an empty body or a 403 challenge page.
This repo has two recovery paths:
./refresh_cookies.sh— spawns a one-shotdsk/server.pybypass server, solves the challenge via DrissionPage + Chrome, writesdsk/cookies.json, exits. Works on any host with Chrome + a display (physical orxvfb-run). The Docker image setsDOCKERMODE=trueand bundles Xvfb, so nothing extra is required.POST /admin/refresh-cookies— runsrefresh_cookies.shinside the proxy process and clears its caches, so callers that only have HTTP access (e.g. a Telegram bot in a separate container) can trigger recovery remotely.
Both flush dsk/_session_pool and dsk/_client_cache when done so the
next completion starts fresh.
main.py FastAPI app; env config; request → session pool
│
└── dsk/ "deepseek4free" core
├── api.py DeepSeekAPI client (POW + streaming parser)
├── pow.py Proof-of-work challenge solver (wasm)
├── wasm/sha3.wasm WASM module for POW
├── bypass.py CLI wrapper around server.py → cookies.json
├── server.py FastAPI service that uses DrissionPage+Chrome
├── CloudflareBypasser.py DrissionPage-based CF/WAF solver
└── cookies.json (runtime, .gitignored)
ответ AI не распознан / empty completions.
Cookies expired. Hit POST /admin/refresh-cookies or run
./refresh_cookies.sh.
401 Invalid or expired authentication token.
Your DEEPSEEK_AUTH_TOKEN is stale. Re-grab it from
chat.deepseek.com localStorage.
Warning: curl-cffi version mismatch.
DeepSeek browser-impersonates against chrome120, which curl-cffi==0.8.1b9
produces. Newer versions sometimes fail. Pin the version.
Chrome crashes in Docker.
Increase shared memory: --shm-size=1g (or shm_size: "1g" in compose).
Failed to bypass edge protection after multiple attempts.
The automatic refresh kicked in and still failed. Check
/tmp/kwork-bot-logs/bypass-server.log / container stdout. Common cause:
VPS in a geography blocked by DeepSeek — try a different region.
This is a modernised fork of
LeadroyaL/FreeDeepSeekAPI,
which itself wraps deepseek4free.
The dsk/ module, the POW WASM and the Chrome-based bypass are all from
the upstream projects. My changes are in:
main.py— session pool, system-prompt handling, admin endpoints, structured logging, FastAPI lifespan.dsk/api.py— support for the new JSON-Patch streaming format that DeepSeek switched to in late 2025,importlib.metadatainstead of the deprecatedpkg_resources, cleaner_iter_parsed, proper logging.dsk/bypass.py— acceptaws-waf-token(in addition to the now-gonecf_clearance) as a valid clearance cookie.refresh_cookies.sh— portable one-shot wrapper (works inside Docker too).Dockerfile— Chrome + Xvfb + Drission stack for autonomous cookie refresh on headless servers.
MIT (see LICENSE). Keeps upstream attribution to
deepseek4free and FreeDeepSeekAPI.
Please read DISCLAIMER.md before using this project.
Short version:
- This project uses the undocumented web API of chat.deepseek.com and is not affiliated with DeepSeek.
- Using it may violate DeepSeek's Terms of Service and DeepSeek may ban your account at any time without notice.
- DeepSeek may change or remove the API at any time, breaking this project without warning.
- Provided AS IS, with no warranty and no liability for banned accounts, blocked IPs, incorrect output, financial loss, or any other consequences.
- Use a throwaway DeepSeek account you're OK with losing.
- Do not use this for commercial resale of DeepSeek access, spam, disinformation, or anything illegal in your jurisdiction.
If you run this software, you do so at your own risk.