文档中心/SDK 文档/Python SDK

Python SDK

AItiktak Python SDK 提供简单易用的接口,兼容 OpenAI SDK 风格。

安装

pip install aitiktak

快速开始

from aitiktak import AItiktak

# 初始化客户端
client = AItiktak(
    api_key="YOUR_API_KEY",
    base_url="https://api.aitiktak.com/v1"
)

# 对话补全
response = client.chat.completions.create(
    model="qwen-plus",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ],
    temperature=0.7,
    max_tokens=1000
)

print(response.choices[0].message.content)

流式输出

stream = client.chat.completions.create(
    model="qwen-plus",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

获取模型列表

models = client.models.list()
for model in models:
    print(model.id, model.provider, model.context_window)

查询使用量

usage = client.usage.get(
    start_date="2026-04-01",
    end_date="2026-04-30"
)
print(f"Total tokens: {usage.total_tokens}")
print(f"Total cost: {usage.total_cost}")

异步客户端

import asyncio
from aitiktak import AsyncAItiktak

async def main():
    client = AsyncAItiktak(api_key="YOUR_API_KEY")

    response = await client.chat.completions.create(
        model="qwen-plus",
        messages=[{"role": "user", "content": "Hello!"}]
    )

    print(response.choices[0].message.content)

asyncio.run(main())