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.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hengroute-0.4.2.tar.gz | 4.1 kB | Without provenance | Details for hengroute-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hengroute-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for hengroute-0.4.2-py3-none-any.whl |
Total release size: 9.0 kB
Release files / hengroute-0.4.2.tar.gz
| Download URL | hengroute-0.4.2.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56a6c256c596931cbac06baf42bfaef46fa9295a5246c2ca6d0f6573e3801e9e
|
|
BLAKE2b-256 checksum How to use checksums |
02f92beba467b3e47242dd35ef163567d2dff8702cb6d34221c79999b14c9624
|
| 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.2-py3-none-any.whl
| Download URL | hengroute-0.4.2-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
675386a34efd0073272dcd958f1d1401946659c5c999d54aca233f13a906723f
|
|
BLAKE2b-256 checksum How to use checksums |
63070e5d30861b678c96bcda3a017dc0d60db9e10ab5d3f9bdd2cfcf40968d88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for hengroute 0.4.2
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.