HengRoute Python SDK
HengRoute(OpenAI 兼容 AI 网关)官方 Python SDK。一个 Key 调所有模型,流式/非流式都支持。
安装
pip install hengroute
快速开始
from hengroute import Hengroute
client = Hengroute(api_key="sk-xxx", base_url="https://gw.example.com")
# 非流式
resp = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "你好"}],
)
print(resp["choices"][0]["message"]["content"])
# 流式(SSE)
for chunk in client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "讲个笑话"}],
stream=True,
):
delta = chunk["choices"][0]["delta"].get("content", "")
print(delta, end="", flush=True)
# 模型列表
for m in client.models.list():
print(m["id"])
# 向量
resp = client.embeddings.create(model="text-embedding-v3", input="你好")
配置
api_key/base_url也可通过环境变量HENGROUTE_API_KEY/HENGROUTE_BASE_URL提供。- 调用方不需要任何上游厂商 Key;网关统一错误码会映射为异常:
AuthenticationError(401)、RateLimitError(429)、ApiError(其他)。
Metadata
Release files for hengroute 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hengroute-0.4.0.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hengroute-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.0 kB
Release files / hengroute-0.4.0.tar.gz
| Download URL | hengroute-0.4.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd154c6e50535d9c1600b40253cb83d92896a52aa1d69a0a015795a19adf0b30
|
|
BLAKE2b-256 checksum How to use checksums |
b49f562bad95a2a8ad1c0959f78d110f0743d7c0d05333d595791d288fcbb118
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / hengroute-0.4.0-py3-none-any.whl
| Download URL | hengroute-0.4.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
719165494c0e28031ddb0f9685af506ba65b78548f4d5cedf966f9b7c08f0e26
|
|
BLAKE2b-256 checksum How to use checksums |
96ee127e0ad50aac53579abf1c108fbd7809b2295943bdbf04e7e035b2fdbc0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|