noodelapi 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- noodelapi-0.1.0/LICENSE +21 -0
- noodelapi-0.1.0/PKG-INFO +105 -0
- noodelapi-0.1.0/README.md +81 -0
- noodelapi-0.1.0/noodelapi/__init__.py +3 -0
- noodelapi-0.1.0/noodelapi/__main__.py +4 -0
- noodelapi-0.1.0/noodelapi/browser.py +219 -0
- noodelapi-0.1.0/noodelapi/cli.py +490 -0
- noodelapi-0.1.0/noodelapi/client.py +500 -0
- noodelapi-0.1.0/noodelapi/config.py +182 -0
- noodelapi-0.1.0/noodelapi/hash.py +242 -0
- noodelapi-0.1.0/noodelapi/pow.py +28 -0
- noodelapi-0.1.0/noodelapi/server.py +573 -0
- noodelapi-0.1.0/noodelapi.egg-info/PKG-INFO +105 -0
- noodelapi-0.1.0/noodelapi.egg-info/SOURCES.txt +20 -0
- noodelapi-0.1.0/noodelapi.egg-info/dependency_links.txt +1 -0
- noodelapi-0.1.0/noodelapi.egg-info/entry_points.txt +2 -0
- noodelapi-0.1.0/noodelapi.egg-info/requires.txt +1 -0
- noodelapi-0.1.0/noodelapi.egg-info/top_level.txt +1 -0
- noodelapi-0.1.0/pyproject.toml +36 -0
- noodelapi-0.1.0/setup.cfg +4 -0
- noodelapi-0.1.0/tests/test_core.py +120 -0
- noodelapi-0.1.0/tests/test_hash.py +31 -0
noodelapi-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 noodelTech
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
noodelapi-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: noodelapi
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Local OpenAI-compatible API publisher for chat.deepseek.com
|
|
5
|
+
Author: noodelTech
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: deepseek,openai,api,llm,local
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: MacOS
|
|
11
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: numpy>=1.21
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# noodelapi
|
|
26
|
+
|
|
27
|
+
Local OpenAI-compatible API for chat.deepseek.com.
|
|
28
|
+
|
|
29
|
+
noodelapi uses your existing DeepSeek web session and exposes
|
|
30
|
+
`/v1/chat/completions` on your machine. Any agent harness that accepts an
|
|
31
|
+
OpenAI-compatible base URL can use it.
|
|
32
|
+
|
|
33
|
+
## Requirements
|
|
34
|
+
|
|
35
|
+
- Windows, macOS, or Linux
|
|
36
|
+
- Python 3.9 or newer
|
|
37
|
+
- A browser profile logged in at https://chat.deepseek.com. Supported:
|
|
38
|
+
Brave, Chrome, Edge, Chromium, Vivaldi, Arc.
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
pipx install noodelapi
|
|
43
|
+
|
|
44
|
+
or:
|
|
45
|
+
|
|
46
|
+
python3 -m pip install --user noodelapi
|
|
47
|
+
|
|
48
|
+
On Windows use `py -m pip install --user noodelapi`.
|
|
49
|
+
|
|
50
|
+
## Setup
|
|
51
|
+
|
|
52
|
+
1. Open https://chat.deepseek.com in your browser and sign in.
|
|
53
|
+
2. Run:
|
|
54
|
+
|
|
55
|
+
noodelapi setup
|
|
56
|
+
|
|
57
|
+
3. Paste the `ds_session_id` cookie value when asked. The CLI finds the
|
|
58
|
+
`userToken` from the browser profile automatically. If it cannot find
|
|
59
|
+
it, the CLI asks for that value instead.
|
|
60
|
+
4. Start the server:
|
|
61
|
+
|
|
62
|
+
noodelapi start
|
|
63
|
+
|
|
64
|
+
The command prints the base URL, API key, and model names.
|
|
65
|
+
|
|
66
|
+
## Use
|
|
67
|
+
|
|
68
|
+
Base URL: `http://127.0.0.1:8787/v1`
|
|
69
|
+
|
|
70
|
+
API key: printed by `noodelapi setup` and `noodelapi status`.
|
|
71
|
+
|
|
72
|
+
Models:
|
|
73
|
+
|
|
74
|
+
- `deepseek-v4.1-flash`
|
|
75
|
+
- `deepseek-v4.1-flash-thinking`
|
|
76
|
+
|
|
77
|
+
Example:
|
|
78
|
+
|
|
79
|
+
curl http://127.0.0.1:8787/v1/chat/completions \
|
|
80
|
+
-H "Authorization: Bearer $NOODELAPI_KEY" \
|
|
81
|
+
-H "Content-Type: application/json" \
|
|
82
|
+
-d '{"model":"deepseek-v4.1-flash","messages":[{"role":"user","content":"hello"}]}'
|
|
83
|
+
|
|
84
|
+
Streaming is supported with `"stream": true`.
|
|
85
|
+
|
|
86
|
+
## Commands
|
|
87
|
+
|
|
88
|
+
noodelapi setup save browser credentials
|
|
89
|
+
noodelapi start start in the background
|
|
90
|
+
noodelapi stop stop the background server
|
|
91
|
+
noodelapi status show status and base URL
|
|
92
|
+
noodelapi logs -f follow logs
|
|
93
|
+
noodelapi check verify saved credentials
|
|
94
|
+
noodelapi config show config with secrets masked
|
|
95
|
+
noodelapi models list model names
|
|
96
|
+
|
|
97
|
+
## Notes
|
|
98
|
+
|
|
99
|
+
This is an unofficial bridge. It uses the same web endpoints as the
|
|
100
|
+
DeepSeek chat app and can stop working when DeepSeek changes them.
|
|
101
|
+
|
|
102
|
+
Sessions are deleted after each request by default. Set `keep_sessions`
|
|
103
|
+
to true in the config if you want to keep them in your DeepSeek history.
|
|
104
|
+
|
|
105
|
+
Only use it with your own account.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# noodelapi
|
|
2
|
+
|
|
3
|
+
Local OpenAI-compatible API for chat.deepseek.com.
|
|
4
|
+
|
|
5
|
+
noodelapi uses your existing DeepSeek web session and exposes
|
|
6
|
+
`/v1/chat/completions` on your machine. Any agent harness that accepts an
|
|
7
|
+
OpenAI-compatible base URL can use it.
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Windows, macOS, or Linux
|
|
12
|
+
- Python 3.9 or newer
|
|
13
|
+
- A browser profile logged in at https://chat.deepseek.com. Supported:
|
|
14
|
+
Brave, Chrome, Edge, Chromium, Vivaldi, Arc.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
pipx install noodelapi
|
|
19
|
+
|
|
20
|
+
or:
|
|
21
|
+
|
|
22
|
+
python3 -m pip install --user noodelapi
|
|
23
|
+
|
|
24
|
+
On Windows use `py -m pip install --user noodelapi`.
|
|
25
|
+
|
|
26
|
+
## Setup
|
|
27
|
+
|
|
28
|
+
1. Open https://chat.deepseek.com in your browser and sign in.
|
|
29
|
+
2. Run:
|
|
30
|
+
|
|
31
|
+
noodelapi setup
|
|
32
|
+
|
|
33
|
+
3. Paste the `ds_session_id` cookie value when asked. The CLI finds the
|
|
34
|
+
`userToken` from the browser profile automatically. If it cannot find
|
|
35
|
+
it, the CLI asks for that value instead.
|
|
36
|
+
4. Start the server:
|
|
37
|
+
|
|
38
|
+
noodelapi start
|
|
39
|
+
|
|
40
|
+
The command prints the base URL, API key, and model names.
|
|
41
|
+
|
|
42
|
+
## Use
|
|
43
|
+
|
|
44
|
+
Base URL: `http://127.0.0.1:8787/v1`
|
|
45
|
+
|
|
46
|
+
API key: printed by `noodelapi setup` and `noodelapi status`.
|
|
47
|
+
|
|
48
|
+
Models:
|
|
49
|
+
|
|
50
|
+
- `deepseek-v4.1-flash`
|
|
51
|
+
- `deepseek-v4.1-flash-thinking`
|
|
52
|
+
|
|
53
|
+
Example:
|
|
54
|
+
|
|
55
|
+
curl http://127.0.0.1:8787/v1/chat/completions \
|
|
56
|
+
-H "Authorization: Bearer $NOODELAPI_KEY" \
|
|
57
|
+
-H "Content-Type: application/json" \
|
|
58
|
+
-d '{"model":"deepseek-v4.1-flash","messages":[{"role":"user","content":"hello"}]}'
|
|
59
|
+
|
|
60
|
+
Streaming is supported with `"stream": true`.
|
|
61
|
+
|
|
62
|
+
## Commands
|
|
63
|
+
|
|
64
|
+
noodelapi setup save browser credentials
|
|
65
|
+
noodelapi start start in the background
|
|
66
|
+
noodelapi stop stop the background server
|
|
67
|
+
noodelapi status show status and base URL
|
|
68
|
+
noodelapi logs -f follow logs
|
|
69
|
+
noodelapi check verify saved credentials
|
|
70
|
+
noodelapi config show config with secrets masked
|
|
71
|
+
noodelapi models list model names
|
|
72
|
+
|
|
73
|
+
## Notes
|
|
74
|
+
|
|
75
|
+
This is an unofficial bridge. It uses the same web endpoints as the
|
|
76
|
+
DeepSeek chat app and can stop working when DeepSeek changes them.
|
|
77
|
+
|
|
78
|
+
Sessions are deleted after each request by default. Set `keep_sessions`
|
|
79
|
+
to true in the config if you want to keep them in your DeepSeek history.
|
|
80
|
+
|
|
81
|
+
Only use it with your own account.
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import re
|
|
5
|
+
import sys
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Iterable, List, Optional
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class BrowserToken:
|
|
13
|
+
profile: Path
|
|
14
|
+
token: str
|
|
15
|
+
modified: float
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _varint(buf: bytes, index: int):
|
|
19
|
+
value = 0
|
|
20
|
+
shift = 0
|
|
21
|
+
while index < len(buf) and shift < 64:
|
|
22
|
+
byte = buf[index]
|
|
23
|
+
index += 1
|
|
24
|
+
value |= (byte & 0x7F) << shift
|
|
25
|
+
if not (byte & 0x80):
|
|
26
|
+
return value, index
|
|
27
|
+
shift += 7
|
|
28
|
+
return None, index
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _snappy_decode(buf: bytes, start: int, limit: int = 4_000_000) -> Optional[bytes]:
|
|
32
|
+
"""Decode a raw Snappy block at ``start``. Returns None if it is not valid."""
|
|
33
|
+
length, pos = _varint(buf, start)
|
|
34
|
+
if not length or length <= 0 or length > limit:
|
|
35
|
+
return None
|
|
36
|
+
out = bytearray()
|
|
37
|
+
while len(out) < length and pos < len(buf):
|
|
38
|
+
tag = buf[pos]
|
|
39
|
+
pos += 1
|
|
40
|
+
kind = tag & 3
|
|
41
|
+
if kind == 0:
|
|
42
|
+
size = tag >> 2
|
|
43
|
+
if size < 60:
|
|
44
|
+
size += 1
|
|
45
|
+
else:
|
|
46
|
+
extra = size - 59
|
|
47
|
+
if pos + extra > len(buf):
|
|
48
|
+
return None
|
|
49
|
+
size = int.from_bytes(buf[pos : pos + extra], "little") + 1
|
|
50
|
+
pos += extra
|
|
51
|
+
if pos + size > len(buf) or size > limit:
|
|
52
|
+
return None
|
|
53
|
+
out += buf[pos : pos + size]
|
|
54
|
+
pos += size
|
|
55
|
+
else:
|
|
56
|
+
if kind == 1:
|
|
57
|
+
if pos >= len(buf):
|
|
58
|
+
return None
|
|
59
|
+
size = 4 + ((tag >> 2) & 7)
|
|
60
|
+
offset = ((tag & 0xE0) << 3) | buf[pos]
|
|
61
|
+
pos += 1
|
|
62
|
+
elif kind == 2:
|
|
63
|
+
if pos + 2 > len(buf):
|
|
64
|
+
return None
|
|
65
|
+
size = (tag >> 2) + 1
|
|
66
|
+
offset = int.from_bytes(buf[pos : pos + 2], "little")
|
|
67
|
+
pos += 2
|
|
68
|
+
else:
|
|
69
|
+
if pos + 4 > len(buf):
|
|
70
|
+
return None
|
|
71
|
+
size = (tag >> 2) + 1
|
|
72
|
+
offset = int.from_bytes(buf[pos : pos + 4], "little")
|
|
73
|
+
pos += 4
|
|
74
|
+
if offset == 0 or offset > len(out):
|
|
75
|
+
return None
|
|
76
|
+
for _ in range(size):
|
|
77
|
+
out.append(out[-offset])
|
|
78
|
+
return bytes(out) if len(out) == length else None
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
_TOKEN_RE = re.compile(rb"userToken.{0,300}?\"value\":\"([^\"]+)\"", re.S)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _extract_token_from_blob(blob: bytes) -> Optional[str]:
|
|
85
|
+
match = _TOKEN_RE.search(blob)
|
|
86
|
+
if match:
|
|
87
|
+
try:
|
|
88
|
+
value = match.group(1).decode("utf-8")
|
|
89
|
+
except UnicodeDecodeError:
|
|
90
|
+
return None
|
|
91
|
+
if value and len(value) < 4096:
|
|
92
|
+
return value
|
|
93
|
+
return None
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _read_file(path: Path) -> Optional[bytes]:
|
|
97
|
+
"""Read a browser database, copying it first if the OS locks it."""
|
|
98
|
+
try:
|
|
99
|
+
return path.read_bytes()
|
|
100
|
+
except OSError:
|
|
101
|
+
pass
|
|
102
|
+
try:
|
|
103
|
+
import shutil
|
|
104
|
+
import tempfile
|
|
105
|
+
|
|
106
|
+
target = Path(tempfile.gettempdir()) / f"noodelapi-{path.name}"
|
|
107
|
+
shutil.copyfile(path, target)
|
|
108
|
+
data = target.read_bytes()
|
|
109
|
+
try:
|
|
110
|
+
target.unlink()
|
|
111
|
+
except OSError:
|
|
112
|
+
pass
|
|
113
|
+
return data
|
|
114
|
+
except OSError:
|
|
115
|
+
return None
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def extract_token_from_leveldb(leveldb: Path) -> Optional[str]:
|
|
119
|
+
files = sorted(
|
|
120
|
+
[p for p in leveldb.iterdir() if p.suffix in {".ldb", ".log"} and p.is_file()],
|
|
121
|
+
key=lambda p: p.stat().st_mtime,
|
|
122
|
+
reverse=True,
|
|
123
|
+
)
|
|
124
|
+
for path in files:
|
|
125
|
+
data = _read_file(path)
|
|
126
|
+
if not data:
|
|
127
|
+
continue
|
|
128
|
+
|
|
129
|
+
token = _extract_token_from_blob(data)
|
|
130
|
+
if token:
|
|
131
|
+
return token
|
|
132
|
+
|
|
133
|
+
# LevelDB table blocks are Snappy-compressed. The key is near the start
|
|
134
|
+
# of the block, so only try starts shortly before each occurrence.
|
|
135
|
+
for match in re.finditer(b"userToken", data):
|
|
136
|
+
begin = max(0, match.start() - 256)
|
|
137
|
+
for start in range(begin, match.start() + 1):
|
|
138
|
+
decoded = _snappy_decode(data, start)
|
|
139
|
+
if not decoded or b"userToken" not in decoded:
|
|
140
|
+
continue
|
|
141
|
+
token = _extract_token_from_blob(decoded)
|
|
142
|
+
if token:
|
|
143
|
+
return token
|
|
144
|
+
return None
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _profile_roots() -> List[Path]:
|
|
148
|
+
home = Path.home()
|
|
149
|
+
override = os.environ.get("NOODELAPI_BROWSER_PROFILE")
|
|
150
|
+
if override:
|
|
151
|
+
return [Path(override).expanduser()]
|
|
152
|
+
|
|
153
|
+
if sys.platform == "darwin":
|
|
154
|
+
base = home / "Library" / "Application Support"
|
|
155
|
+
return [
|
|
156
|
+
base / "BraveSoftware" / "Brave-Browser",
|
|
157
|
+
base / "Google" / "Chrome",
|
|
158
|
+
base / "Microsoft Edge",
|
|
159
|
+
base / "Chromium",
|
|
160
|
+
base / "Arc",
|
|
161
|
+
base / "Vivaldi",
|
|
162
|
+
]
|
|
163
|
+
|
|
164
|
+
if sys.platform == "win32":
|
|
165
|
+
local = Path(os.environ.get("LOCALAPPDATA") or (Path.home() / "AppData" / "Local"))
|
|
166
|
+
return [
|
|
167
|
+
local / "BraveSoftware" / "Brave-Browser" / "User Data",
|
|
168
|
+
local / "Google" / "Chrome" / "User Data",
|
|
169
|
+
local / "Microsoft" / "Edge" / "User Data",
|
|
170
|
+
local / "Chromium" / "User Data",
|
|
171
|
+
local / "Vivaldi" / "User Data",
|
|
172
|
+
local / "Arc" / "User Data",
|
|
173
|
+
]
|
|
174
|
+
|
|
175
|
+
base = Path(os.environ.get("XDG_CONFIG_HOME", home / ".config"))
|
|
176
|
+
return [
|
|
177
|
+
base / "BraveSoftware" / "Brave-Browser",
|
|
178
|
+
base / "google-chrome",
|
|
179
|
+
base / "microsoft-edge",
|
|
180
|
+
base / "chromium",
|
|
181
|
+
base / "vivaldi",
|
|
182
|
+
]
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _leveldb_dirs(root: Path) -> Iterable[Path]:
|
|
186
|
+
if root.name == "leveldb" and root.is_dir():
|
|
187
|
+
yield root
|
|
188
|
+
return
|
|
189
|
+
if not root.is_dir():
|
|
190
|
+
return
|
|
191
|
+
direct = root / "Local Storage" / "leveldb"
|
|
192
|
+
if direct.is_dir():
|
|
193
|
+
yield direct
|
|
194
|
+
try:
|
|
195
|
+
for child in root.iterdir():
|
|
196
|
+
if child.is_dir():
|
|
197
|
+
candidate = child / "Local Storage" / "leveldb"
|
|
198
|
+
if candidate.is_dir():
|
|
199
|
+
yield candidate
|
|
200
|
+
except OSError:
|
|
201
|
+
return
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def find_browser_tokens() -> List[BrowserToken]:
|
|
205
|
+
found: List[BrowserToken] = []
|
|
206
|
+
seen = set()
|
|
207
|
+
for root in _profile_roots():
|
|
208
|
+
for leveldb in _leveldb_dirs(root):
|
|
209
|
+
token = extract_token_from_leveldb(leveldb)
|
|
210
|
+
if not token or token in seen:
|
|
211
|
+
continue
|
|
212
|
+
seen.add(token)
|
|
213
|
+
try:
|
|
214
|
+
modified = max(p.stat().st_mtime for p in leveldb.iterdir() if p.is_file())
|
|
215
|
+
except OSError:
|
|
216
|
+
modified = 0.0
|
|
217
|
+
found.append(BrowserToken(profile=leveldb, token=token, modified=modified))
|
|
218
|
+
found.sort(key=lambda item: item.modified, reverse=True)
|
|
219
|
+
return found
|