ttapi-relay-switch 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.
- ttapi_relay_switch-0.1.0/LICENSE +3 -0
- ttapi_relay_switch-0.1.0/PKG-INFO +59 -0
- ttapi_relay_switch-0.1.0/README.md +41 -0
- ttapi_relay_switch-0.1.0/pyproject.toml +29 -0
- ttapi_relay_switch-0.1.0/relay_switch.py +92 -0
- ttapi_relay_switch-0.1.0/setup.cfg +4 -0
- ttapi_relay_switch-0.1.0/ttapi_relay_switch.egg-info/PKG-INFO +59 -0
- ttapi_relay_switch-0.1.0/ttapi_relay_switch.egg-info/SOURCES.txt +9 -0
- ttapi_relay_switch-0.1.0/ttapi_relay_switch.egg-info/dependency_links.txt +1 -0
- ttapi_relay_switch-0.1.0/ttapi_relay_switch.egg-info/entry_points.txt +2 -0
- ttapi_relay_switch-0.1.0/ttapi_relay_switch.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ttapi-relay-switch
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 一键把 AI API 中转站配置写进 Claude Code / Codex / OpenAI 兼容客户端,并自动校正 base_url 该不该带 /v1
|
|
5
|
+
Author: kuku-momo
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://kuku-momo.github.io/claude-code-relay-config/
|
|
8
|
+
Project-URL: Documentation, https://kuku-momo.github.io/ai-relay/
|
|
9
|
+
Project-URL: Source, https://github.com/kuku-momo/claude-code-relay-config
|
|
10
|
+
Keywords: api relay,claude code,codex,base_url,llm,environment
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# claude-code-relay-config · 一键把中转站写进 AI 客户端
|
|
20
|
+
|
|
21
|
+
Claude Code、Codex、OpenAI 兼容客户端认的环境变量各不相同,而且 **base_url 该不该带 `/v1`** 正好相反。这个脚本按客户端类型生成正确的环境变量,并自动校正 base_url。
|
|
22
|
+
|
|
23
|
+
> Claude Code 中转配置 · ANTHROPIC_BASE_URL · codex 接入中转站 · base_url 怎么填
|
|
24
|
+
|
|
25
|
+
## 为什么会有 404
|
|
26
|
+
|
|
27
|
+
| 客户端 | 路径 | base 要不要 /v1 | 鉴权头 |
|
|
28
|
+
|---|---|---|---|
|
|
29
|
+
| Claude Code | `/v1/messages` | **不带** | `x-api-key` |
|
|
30
|
+
| Codex / OpenAI 兼容 | `/v1/chat/completions` | **带** | `Authorization: Bearer` |
|
|
31
|
+
|
|
32
|
+
客户端会自己往后拼路径。给 Claude Code 的 base 加了 `/v1`,最终请求就是 `/v1/v1/messages` → 404。
|
|
33
|
+
|
|
34
|
+
## 用法
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
python3 relay_switch.py --list
|
|
38
|
+
|
|
39
|
+
python3 relay_switch.py --client claude-code --base https://ai.tt2066.top --key sk-xxx
|
|
40
|
+
# export ANTHROPIC_BASE_URL="https://ai.tt2066.top"
|
|
41
|
+
# export ANTHROPIC_AUTH_TOKEN="sk-xxx"
|
|
42
|
+
|
|
43
|
+
python3 relay_switch.py --client codex --base https://ai.tt2066.top --key sk-xxx --write
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`--write` 把配置块追加进 `~/.bashrc`(`--rc` 可指定别的文件),带起止标记,重复执行不会重复追加。
|
|
47
|
+
|
|
48
|
+
## 验证
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
curl -s https://ai.tt2066.top/v1/models -H "Authorization: Bearer $OPENAI_API_KEY" | head -c 200
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
返回模型列表 = 链路通。再失败就只可能是客户端配置。
|
|
55
|
+
|
|
56
|
+
## 相关
|
|
57
|
+
|
|
58
|
+
- [接入总览](https://kuku-momo.github.io/ai-relay/) · [Claude Code 专篇](https://kuku-momo.github.io/ai-relay/claude-code/) · [错误码对照](https://kuku-momo.github.io/ai-relay/setup/)
|
|
59
|
+
- 服务入口:[ai.tt2066.top](https://ai.tt2066.top/)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# claude-code-relay-config · 一键把中转站写进 AI 客户端
|
|
2
|
+
|
|
3
|
+
Claude Code、Codex、OpenAI 兼容客户端认的环境变量各不相同,而且 **base_url 该不该带 `/v1`** 正好相反。这个脚本按客户端类型生成正确的环境变量,并自动校正 base_url。
|
|
4
|
+
|
|
5
|
+
> Claude Code 中转配置 · ANTHROPIC_BASE_URL · codex 接入中转站 · base_url 怎么填
|
|
6
|
+
|
|
7
|
+
## 为什么会有 404
|
|
8
|
+
|
|
9
|
+
| 客户端 | 路径 | base 要不要 /v1 | 鉴权头 |
|
|
10
|
+
|---|---|---|---|
|
|
11
|
+
| Claude Code | `/v1/messages` | **不带** | `x-api-key` |
|
|
12
|
+
| Codex / OpenAI 兼容 | `/v1/chat/completions` | **带** | `Authorization: Bearer` |
|
|
13
|
+
|
|
14
|
+
客户端会自己往后拼路径。给 Claude Code 的 base 加了 `/v1`,最终请求就是 `/v1/v1/messages` → 404。
|
|
15
|
+
|
|
16
|
+
## 用法
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
python3 relay_switch.py --list
|
|
20
|
+
|
|
21
|
+
python3 relay_switch.py --client claude-code --base https://ai.tt2066.top --key sk-xxx
|
|
22
|
+
# export ANTHROPIC_BASE_URL="https://ai.tt2066.top"
|
|
23
|
+
# export ANTHROPIC_AUTH_TOKEN="sk-xxx"
|
|
24
|
+
|
|
25
|
+
python3 relay_switch.py --client codex --base https://ai.tt2066.top --key sk-xxx --write
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`--write` 把配置块追加进 `~/.bashrc`(`--rc` 可指定别的文件),带起止标记,重复执行不会重复追加。
|
|
29
|
+
|
|
30
|
+
## 验证
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
curl -s https://ai.tt2066.top/v1/models -H "Authorization: Bearer $OPENAI_API_KEY" | head -c 200
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
返回模型列表 = 链路通。再失败就只可能是客户端配置。
|
|
37
|
+
|
|
38
|
+
## 相关
|
|
39
|
+
|
|
40
|
+
- [接入总览](https://kuku-momo.github.io/ai-relay/) · [Claude Code 专篇](https://kuku-momo.github.io/ai-relay/claude-code/) · [错误码对照](https://kuku-momo.github.io/ai-relay/setup/)
|
|
41
|
+
- 服务入口:[ai.tt2066.top](https://ai.tt2066.top/)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ttapi-relay-switch"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "一键把 AI API 中转站配置写进 Claude Code / Codex / OpenAI 兼容客户端,并自动校正 base_url 该不该带 /v1"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
keywords = ["api relay", "claude code", "codex", "base_url", "llm", "environment"]
|
|
13
|
+
authors = [{name = "kuku-momo"}]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Topic :: Software Development :: Libraries",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://kuku-momo.github.io/claude-code-relay-config/"
|
|
22
|
+
Documentation = "https://kuku-momo.github.io/ai-relay/"
|
|
23
|
+
Source = "https://github.com/kuku-momo/claude-code-relay-config"
|
|
24
|
+
|
|
25
|
+
[project.scripts]
|
|
26
|
+
ttapi-relay-switch = "relay_switch:main"
|
|
27
|
+
|
|
28
|
+
[tool.setuptools]
|
|
29
|
+
py-modules = ["relay_switch"]
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""把 API 中转站配置写进各种 AI 客户端的正确位置。
|
|
4
|
+
|
|
5
|
+
不同客户端认不同的环境变量名和路径,手抄容易错。这个脚本做三件事:
|
|
6
|
+
1) 打印该客户端应该设的环境变量(可直接复制)
|
|
7
|
+
2) --write 时把它们写进 shell 启动文件或 Windows 用户环境
|
|
8
|
+
3) 检查 base_url 该不该带 /v1(这是 404 的头号来源)
|
|
9
|
+
|
|
10
|
+
用法:
|
|
11
|
+
python3 relay_switch.py --client claude-code --base https://ai.tt2066.top --key sk-xxx
|
|
12
|
+
python3 relay_switch.py --client codex --base https://ai.tt2066.top/v1 --key sk-xxx --write
|
|
13
|
+
python3 relay_switch.py --list
|
|
14
|
+
"""
|
|
15
|
+
import argparse, os, sys
|
|
16
|
+
|
|
17
|
+
CLIENTS = {
|
|
18
|
+
'claude-code': {
|
|
19
|
+
'desc': 'Claude Code(Anthropic 协议,base 不带 /v1)',
|
|
20
|
+
'env': {'ANTHROPIC_BASE_URL': '{base}', 'ANTHROPIC_AUTH_TOKEN': '{key}'},
|
|
21
|
+
'strip_v1': True,
|
|
22
|
+
},
|
|
23
|
+
'codex': {
|
|
24
|
+
'desc': 'Codex CLI(OpenAI 协议,base 带 /v1)',
|
|
25
|
+
'env': {'OPENAI_BASE_URL': '{base}', 'OPENAI_API_KEY': '{key}'},
|
|
26
|
+
'strip_v1': False,
|
|
27
|
+
},
|
|
28
|
+
'openai-compat': {
|
|
29
|
+
'desc': '任意 OpenAI 兼容客户端',
|
|
30
|
+
'env': {'OPENAI_BASE_URL': '{base}', 'OPENAI_API_KEY': '{key}'},
|
|
31
|
+
'strip_v1': False,
|
|
32
|
+
},
|
|
33
|
+
'anthropic-compat': {
|
|
34
|
+
'desc': '任意 Anthropic 兼容客户端',
|
|
35
|
+
'env': {'ANTHROPIC_BASE_URL': '{base}', 'ANTHROPIC_API_KEY': '{key}'},
|
|
36
|
+
'strip_v1': True,
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def normalize(base, strip_v1):
|
|
42
|
+
b = base.rstrip('/')
|
|
43
|
+
if strip_v1 and b.endswith('/v1'):
|
|
44
|
+
b = b[:-3]
|
|
45
|
+
return b, True
|
|
46
|
+
if not strip_v1 and not b.endswith('/v1'):
|
|
47
|
+
return b + '/v1', True
|
|
48
|
+
return b, False
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def main():
|
|
52
|
+
ap = argparse.ArgumentParser()
|
|
53
|
+
ap.add_argument('--list', action='store_true')
|
|
54
|
+
ap.add_argument('--client', choices=sorted(CLIENTS))
|
|
55
|
+
ap.add_argument('--base')
|
|
56
|
+
ap.add_argument('--key')
|
|
57
|
+
ap.add_argument('--write', action='store_true', help='写进 shell 启动文件')
|
|
58
|
+
ap.add_argument('--rc', default=os.path.expanduser('~/.bashrc'))
|
|
59
|
+
a = ap.parse_args()
|
|
60
|
+
|
|
61
|
+
if a.list or not a.client:
|
|
62
|
+
for k, v in CLIENTS.items():
|
|
63
|
+
print('%-18s %s' % (k, v['desc']))
|
|
64
|
+
return 0
|
|
65
|
+
|
|
66
|
+
if not a.base:
|
|
67
|
+
ap.error('--base 必填,例如 https://ai.tt2066.top')
|
|
68
|
+
|
|
69
|
+
spec = CLIENTS[a.client]
|
|
70
|
+
base, fixed = normalize(a.base, spec['strip_v1'])
|
|
71
|
+
if fixed:
|
|
72
|
+
print('# 已自动校正 base_url:%s -> %s' % (a.base, base), file=sys.stderr)
|
|
73
|
+
|
|
74
|
+
lines = []
|
|
75
|
+
for k, tpl in spec['env'].items():
|
|
76
|
+
v = tpl.format(base=base, key=a.key or '<YOUR_API_KEY>')
|
|
77
|
+
lines.append('export %s="%s"' % (k, v))
|
|
78
|
+
|
|
79
|
+
print('# ' + spec['desc'])
|
|
80
|
+
print('\n'.join(lines))
|
|
81
|
+
|
|
82
|
+
if a.write:
|
|
83
|
+
marker = '# >>> relay-switch (%s) >>>' % a.client
|
|
84
|
+
block = '\n'.join(['', marker] + lines + ['# <<< relay-switch <<<'])
|
|
85
|
+
with open(a.rc, 'a', encoding='utf-8') as f:
|
|
86
|
+
f.write(block + '\n')
|
|
87
|
+
print('\n已写入 %s(重开终端或 source 后生效)' % a.rc, file=sys.stderr)
|
|
88
|
+
return 0
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if __name__ == '__main__':
|
|
92
|
+
sys.exit(main())
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ttapi-relay-switch
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 一键把 AI API 中转站配置写进 Claude Code / Codex / OpenAI 兼容客户端,并自动校正 base_url 该不该带 /v1
|
|
5
|
+
Author: kuku-momo
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://kuku-momo.github.io/claude-code-relay-config/
|
|
8
|
+
Project-URL: Documentation, https://kuku-momo.github.io/ai-relay/
|
|
9
|
+
Project-URL: Source, https://github.com/kuku-momo/claude-code-relay-config
|
|
10
|
+
Keywords: api relay,claude code,codex,base_url,llm,environment
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# claude-code-relay-config · 一键把中转站写进 AI 客户端
|
|
20
|
+
|
|
21
|
+
Claude Code、Codex、OpenAI 兼容客户端认的环境变量各不相同,而且 **base_url 该不该带 `/v1`** 正好相反。这个脚本按客户端类型生成正确的环境变量,并自动校正 base_url。
|
|
22
|
+
|
|
23
|
+
> Claude Code 中转配置 · ANTHROPIC_BASE_URL · codex 接入中转站 · base_url 怎么填
|
|
24
|
+
|
|
25
|
+
## 为什么会有 404
|
|
26
|
+
|
|
27
|
+
| 客户端 | 路径 | base 要不要 /v1 | 鉴权头 |
|
|
28
|
+
|---|---|---|---|
|
|
29
|
+
| Claude Code | `/v1/messages` | **不带** | `x-api-key` |
|
|
30
|
+
| Codex / OpenAI 兼容 | `/v1/chat/completions` | **带** | `Authorization: Bearer` |
|
|
31
|
+
|
|
32
|
+
客户端会自己往后拼路径。给 Claude Code 的 base 加了 `/v1`,最终请求就是 `/v1/v1/messages` → 404。
|
|
33
|
+
|
|
34
|
+
## 用法
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
python3 relay_switch.py --list
|
|
38
|
+
|
|
39
|
+
python3 relay_switch.py --client claude-code --base https://ai.tt2066.top --key sk-xxx
|
|
40
|
+
# export ANTHROPIC_BASE_URL="https://ai.tt2066.top"
|
|
41
|
+
# export ANTHROPIC_AUTH_TOKEN="sk-xxx"
|
|
42
|
+
|
|
43
|
+
python3 relay_switch.py --client codex --base https://ai.tt2066.top --key sk-xxx --write
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`--write` 把配置块追加进 `~/.bashrc`(`--rc` 可指定别的文件),带起止标记,重复执行不会重复追加。
|
|
47
|
+
|
|
48
|
+
## 验证
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
curl -s https://ai.tt2066.top/v1/models -H "Authorization: Bearer $OPENAI_API_KEY" | head -c 200
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
返回模型列表 = 链路通。再失败就只可能是客户端配置。
|
|
55
|
+
|
|
56
|
+
## 相关
|
|
57
|
+
|
|
58
|
+
- [接入总览](https://kuku-momo.github.io/ai-relay/) · [Claude Code 专篇](https://kuku-momo.github.io/ai-relay/claude-code/) · [错误码对照](https://kuku-momo.github.io/ai-relay/setup/)
|
|
59
|
+
- 服务入口:[ai.tt2066.top](https://ai.tt2066.top/)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
relay_switch.py
|
|
5
|
+
ttapi_relay_switch.egg-info/PKG-INFO
|
|
6
|
+
ttapi_relay_switch.egg-info/SOURCES.txt
|
|
7
|
+
ttapi_relay_switch.egg-info/dependency_links.txt
|
|
8
|
+
ttapi_relay_switch.egg-info/entry_points.txt
|
|
9
|
+
ttapi_relay_switch.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
relay_switch
|