Skip to main content

claude-code-relay-config · 一键把中转站写进 AI 客户端

Claude Code、Codex、OpenAI 兼容客户端认的环境变量各不相同,而且 base_url 该不该带 /v1 正好相反。这个脚本按客户端类型生成正确的环境变量,并自动校正 base_url。

Claude Code 中转配置 · ANTHROPIC_BASE_URL · codex 接入中转站 · base_url 怎么填

为什么会有 404

客户端 路径 base 要不要 /v1 鉴权头
Claude Code /v1/messages 不带 x-api-key
Codex / OpenAI 兼容 /v1/chat/completions 带 Authorization: Bearer

客户端会自己往后拼路径。给 Claude Code 的 base 加了 /v1,最终请求就是 /v1/v1/messages → 404。

用法

python3 relay_switch.py --list

python3 relay_switch.py --client claude-code --base https://ai.tt2066.top --key sk-xxx
# export ANTHROPIC_BASE_URL="https://ai.tt2066.top"
# export ANTHROPIC_AUTH_TOKEN="sk-xxx"

python3 relay_switch.py --client codex --base https://ai.tt2066.top --key sk-xxx --write

--write 把配置块追加进 ~/.bashrc(--rc 可指定别的文件),带起止标记,重复执行不会重复追加。

验证

curl -s https://ai.tt2066.top/v1/models -H "Authorization: Bearer $OPENAI_API_KEY" | head -c 200

返回模型列表 = 链路通。再失败就只可能是客户端配置。

相关

Metadata

Release files for ttapi-relay-switch 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ttapi-relay-switch 0.1.0
File Size Uploaded Provenance Actions
ttapi_relay_switch-0.1.0.tar.gz 3.8 kB Without provenance Details for ttapi_relay_switch-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ttapi-relay-switch 0.1.0
File Interpreter ABI Platform Actions
ttapi_relay_switch-0.1.0-py3-none-any.whl Python 3 none any Details for ttapi_relay_switch-0.1.0-py3-none-any.whl

Total release size: 8.3 kB

Release files / ttapi_relay_switch-0.1.0.tar.gz

Download URL ttapi_relay_switch-0.1.0.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
304d42ac60bf2a74bfa5dd3be4ba41c87e3c674b630f28a54ca3cce01cc74b36
BLAKE2b-256 checksum
How to use checksums
35741439534006c104930fb123bbe7437a576cbed2868e46459769d9129cea6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / ttapi_relay_switch-0.1.0-py3-none-any.whl

Download URL ttapi_relay_switch-0.1.0-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
37d72ebdfb1c461d47769a62fb9bb809442fd4f96ed817842f2ba865d7386287
BLAKE2b-256 checksum
How to use checksums
d4e6e142f3ba90a7e162a3b25d8a2d417d85da776b5e5dbf698f21095627925e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for ttapi-relay-switch 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page