Python SDK
OpenAI-compatible Python client with E2E encryption.
Installation
pip install alphachat
Chat Completions
from alphachat import AlphaChat
client = AlphaChat(api_key="sk-alphachat-xxxxx")
# Non-streaming
response = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{"role": "user", "content": "hello"}],
temperature=0.7,
max_tokens=1000,
)
print(response.choices[0].message.content)
print(f"Tokens: {response.usage.total_tokens}")
# Streaming
for chunk in client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{"role": "user", "content": "explain quantum computing"}],
stream=True,
):
print(chunk.choices[0].delta.content or "", end="")Training
# Estimate cost
estimate = client.training.estimate("deepseek-v4-flash", mode="lora")
print(f"Estimated: ${estimate['estimated_cost_usd']}")
# Submit job
job = client.training.create_job(
base_model="deepseek-v4-flash",
training_data_url="s3://bucket/data.jsonl",
mode="lora",
security_mode="private",
budget_usd=50.0,
config={"epochs": 3, "lora_rank": 32},
)
print(f"Job {job.job_id}: {job.status}")
# Check status
job = client.training.get_job(job.job_id)
# List all jobs
jobs = client.training.list_jobs()
# Cancel
client.training.cancel_job(job.job_id)Other Methods
# List models
models = client.models()
for m in models:
print(m.id)
# Check balance
balance = client.balance()
print(f"${balance['balance_usd']}")
# Context manager
with AlphaChat(api_key="sk-...") as client:
response = client.chat.completions.create(...)Constructor Options
| Parameter | Default | Description |
|---|---|---|
| api_key | required | Your AlphaChat API key |
| base_url | https://api.alphachat.com | API base URL |
| timeout | 120 | Request timeout in seconds |