Skip to main content

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.1

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

Source distribution (sdist)

Source distribution for hengroute 0.4.1
File Size Uploaded
hengroute-0.4.1.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hengroute 0.4.1
File Interpreter ABI Platform
hengroute-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 kB

Release files / hengroute-0.4.1.tar.gz

Download URL hengroute-0.4.1.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8fad49832910e4114f25369198c7c4e8294d02f84d61d0d374c27350ef10dbf2
BLAKE2b-256 checksum
How to use checksums
32394bb0ac0d3e7036d29774aab2515ac50d017ba14f93362a5523182c1d55d6
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.1-py3-none-any.whl

Download URL hengroute-0.4.1-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd397c55fcdec5614e2ffc11fb744e8fb47c86f65f2397a11f236c8619e69b41
BLAKE2b-256 checksum
How to use checksums
72d196cc862e8ef1c33a8dd669c87b76d680be17e0989e4afe5c8ff0e1cd5144
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.4.2

2 release files

This release

0.4.1 This release

2 release files

0.4.0

2 release files

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