Official Qufas Python Platform SDK for models, usage, billing, and API key management.
Project description
Qufas Python SDK
Official Python SDK for managing Qufas AI Platform.
The Qufas Python SDK is a platform management SDK. It is designed for account and developer workflows such as listing models, reading usage, checking billing balance, and listing API key metadata.
For chat completions and model inference, use the official OpenAI SDK with the Qufas OpenAI-compatible endpoint:
from openai import OpenAI
client = OpenAI(
api_key="qf_sk_xxxxx",
base_url="https://api.qufas.ai/v1",
)
Installation
pip install qufas
Quick Start
from qufas import Qufas
client = Qufas(
api_key="qf_sk_xxxxx"
)
client.models.list()
client.usage.list()
client.billing.balance()
client.api_keys.list()
You can also load the API key from an environment variable:
export QUFAS_API_KEY="qf_sk_xxxxx"
from qufas import Qufas
client = Qufas()
print(client.billing.balance())
Platform APIs
Models
List models available to the authenticated Qufas API key.
models = client.models.list()
for model in models["data"]:
print(model["id"])
Usage
List recent usage records for the authenticated account.
usage = client.usage.list(limit=25)
print(usage["totals"]["total_tokens"])
print(usage["totals"]["cost"])
Billing
Read the current prepaid balance.
balance = client.billing.balance()
print(balance["balance"], balance["currency"])
API Keys
List API key metadata. Full API key values are never returned.
keys = client.api_keys.list()
for key in keys["data"]:
print(key["id"], key["prefix"], key["status"])
client.api_keys.create() and client.api_keys.delete() are included for
forward compatibility with the public API surface. They may return
501 not_implemented until Qufas enables public API key creation and deletion.
Chat Completions
Qufas AI is OpenAI-compatible. Use the official OpenAI SDK for model inference.
from openai import OpenAI
client = OpenAI(
api_key="qf_sk_xxxxx",
base_url="https://api.qufas.ai/v1",
)
response = client.chat.completions.create(
model="qwen-plus",
messages=[
{
"role": "user",
"content": "Write a haiku about artificial intelligence.",
}
],
)
print(response.choices[0].message.content)
The Qufas Python SDK intentionally does not duplicate chat completion methods. This keeps the primary developer experience compatible with existing OpenAI SDK applications.
Configuration
from qufas import Qufas
client = Qufas(
api_key="qf_sk_xxxxx",
base_url="https://api.qufas.ai",
timeout=30.0,
)
| Option | Description |
|---|---|
api_key |
Qufas API key. If omitted, QUFAS_API_KEY is used. |
base_url |
Qufas API origin. Defaults to https://api.qufas.ai. |
timeout |
Request timeout in seconds. Defaults to 30.0. |
Error Handling
from qufas import Qufas, QufasAPIError, QufasAuthenticationError
client = Qufas(api_key="qf_sk_xxxxx")
try:
print(client.billing.balance())
except QufasAuthenticationError:
print("Invalid or inactive API key.")
except QufasAPIError as error:
print(error.status_code, error.error_code, str(error))
Exception classes:
QufasErrorQufasAPIErrorQufasAuthenticationErrorQufasRateLimitErrorQufasServerErrorQufasConnectionError
Development
cd qufas-python
python -m pip install -e .
python -m unittest discover -s tests
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qufas-0.1.0.tar.gz.
File metadata
- Download URL: qufas-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb888da94ab7051330c625250107db2f5e5975675cc2754bbcab3f55f5c11a46
|
|
| MD5 |
0f5474d1555016ca0fa33f9cf9cc8940
|
|
| BLAKE2b-256 |
306b5fcb966dee8eb7ac04ce5e039a6df90d599ed9ad86a8ef57fbcb91431dbf
|
File details
Details for the file qufas-0.1.0-py3-none-any.whl.
File metadata
- Download URL: qufas-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
418440cf76fe144ea9085a09823f4a5e913692dbf0a9d2020d425bb70ab3e92a
|
|
| MD5 |
279c62b93341feb276ee65c01d010b64
|
|
| BLAKE2b-256 |
452d6564a29d9fe73d4f1b89e4e3acc62f5368059ac66279ecaf32c310564f9d
|