Skip to main content

luanapi-sdk

OpenAI-compatible Python SDK for Luan API.

接口格式与 OpenAI Chat Completions 完全兼容,使用习惯接近 openai 官方 SDK:传入 api_key 后即可调用 client.chat.completions.create(...)。

安装

pip install luanapi-sdk

快速开始

from luanapi import LuanAI

client = LuanAI(api_key="YOUR_TOKEN")  # 也可设置环境变量 LUANAPI_API_KEY

# 非流式
resp = client.chat.completions.create(
    model="minimax-m2.5",
    messages=[
        {"role": "system", "content": "你是一个专业、友善的AI助手。"},
        {"role": "user", "content": "hello"},
    ],
    temperature=0.8,
    max_tokens=4096,
)
print(resp["choices"][0]["message"]["content"])

流式调用

stream = client.chat.completions.create(
    model="minimax-m2.5",
    messages=[{"role": "user", "content": "讲个笑话"}],
    stream=True,
    stream_options={"include_usage": True},
    top_p=1,
    temperature=0.8,
    presence_penalty=0.2,
    frequency_penalty=0.2,
)

for chunk in stream:
    choices = chunk.get("choices") or []
    if choices:
        delta = choices[0].get("delta") or {}
        if delta.get("content"):
            print(delta["content"], end="", flush=True)
    if chunk.get("usage"):
        print("\n[usage]", chunk["usage"])

API

LuanAI(api_key, *, base_url=..., timeout=60, default_headers=None)

参数 说明
api_key Bearer Token;不传则读取环境变量 LUANAPI_API_KEY。
base_url 默认 https://luanapi.xingluan.cn/runningai/open/v1。
timeout 默认 60s。
default_headers 注入到所有请求的额外 header。

client.chat.completions.create(**kwargs)

接受所有 OpenAI 风格参数:model、messages、temperature、top_p、max_tokens、presence_penalty、frequency_penalty、stream、stream_options、tools、…

  • stream=False → 返回 dict
  • stream=True → 返回生成器,逐条 yield 已解析的 JSON chunk(自动处理 data: 前缀与 [DONE])

异常

from luanapi import LuanAPIError, AuthenticationError, APIStatusError
  • AuthenticationError:401 或缺少 token
  • APIStatusError:非 2xx 响应,包含 status_code、response_body
  • LuanAPIError:所有错误的基类

发布到 PyPI

pip install --upgrade build twine
python -m build
python -m twine upload dist/*

发布到 TestPyPI:

python -m twine upload --repository testpypi dist/*
pip install --index-url https://test.pypi.org/simple/ luanapi-sdk

License

MIT

Metadata

Release files for luanapi-sdk 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 luanapi-sdk 0.1.0
File Size Uploaded Provenance Actions
luanapi_sdk-0.1.0.tar.gz 6.6 kB Without provenance Details for luanapi_sdk-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for luanapi-sdk 0.1.0
File Interpreter ABI Platform Actions
luanapi_sdk-0.1.0-py3-none-any.whl Python 3 none any Details for luanapi_sdk-0.1.0-py3-none-any.whl

Total release size: 13.4 kB

Release files / luanapi_sdk-0.1.0.tar.gz

Download URL luanapi_sdk-0.1.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a317692593d5b0c4666d86dbf8a025266dfe54754b15c60fc4b2eac72d78de2f
BLAKE2b-256 checksum
How to use checksums
c870d56a0dd53c217c6efc12e505e7bbb4ce6c3a80f20d53dd9c8a6c22cf06f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

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

Download URL luanapi_sdk-0.1.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6cf8fbd56780db6c9d291ccdb19e48f21732d21167ea3e5521e4eb1a33777a8b
BLAKE2b-256 checksum
How to use checksums
fa12a458395cdc9490e51bcbc97eb997e089b5483fc741bd97059aab6b8e2143
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Security for luanapi-sdk 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