Waterlight AI SDK — OpenAI-compatible client for the Waterlight API
Project description
Waterlight Python SDK
OpenAI-compatible Python client for the Waterlight API. Zero external dependencies.
Install
pip install waterlight
Quick Start
from waterlight import Waterlight
client = Waterlight(api_key="wl-...")
response = client.chat.completions.create(
model="mist-1-turbo",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
Drop-in OpenAI Replacement
Change two lines:
# Before
from openai import OpenAI
client = OpenAI(api_key="sk-...")
# After
from waterlight import Waterlight
client = Waterlight(api_key="wl-...")
# Everything else stays the same
response = client.chat.completions.create(
model="mist-1-turbo",
messages=[{"role": "user", "content": "Explain quantum computing"}],
)
Streaming
stream = client.chat.completions.create(
model="mist-1-turbo",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True,
)
for chunk in stream:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)
Tool Calling
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"},
},
"required": ["location"],
},
},
}]
response = client.chat.completions.create(
model="mist-1-turbo",
messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
tools=tools,
)
Embeddings
response = client.embeddings.create(input="Hello world")
print(len(response.data[0].embedding))
Models
models = client.models.list()
for model in models.data:
print(model.id)
Available Models
| Model | Best For |
|---|---|
mist-1 |
Highest quality reasoning and analysis |
mist-1-turbo |
Fast, high quality all-rounder |
mist-1-flash |
Fastest responses, triage, summarization |
mist-1-reason |
Deep reasoning and math |
mist-1-code |
Code generation and review |
mist-1-vision |
Multimodal / image understanding |
Billing
billing = client.billing.get()
print(billing) # plan, spent_usd, balance, limits
Error Handling
from waterlight import (
AuthenticationError,
RateLimitError,
InsufficientCreditsError,
APIError,
)
try:
response = client.chat.completions.create(
model="mist-1-turbo",
messages=[{"role": "user", "content": "Hello"}],
)
except AuthenticationError:
print("Invalid API key")
except RateLimitError as e:
print(f"Rate limited — retry after {e.retry_after}s")
except InsufficientCreditsError:
print("Add credits at https://waterlight.io")
except APIError as e:
print(f"API error {e.status_code}: {e.message}")
Configuration
| Parameter | Env Var | Default |
|---|---|---|
api_key |
WATERLIGHT_API_KEY |
— (required) |
base_url |
WATERLIGHT_BASE_URL |
https://api.waterlight.io |
timeout |
— | 120.0 |
max_retries |
— | 2 |
client = Waterlight(
api_key="wl-...", # or set WATERLIGHT_API_KEY env var
base_url="https://...", # or set WATERLIGHT_BASE_URL env var
timeout=120.0, # request timeout in seconds
max_retries=2, # retries on transient errors
)
Requirements
- Python 3.9+
- No external dependencies
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
waterlight-0.2.1.tar.gz
(12.1 kB
view details)
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 waterlight-0.2.1.tar.gz.
File metadata
- Download URL: waterlight-0.2.1.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf93a5cc7c9b0a39d8771fa0c170130d0a963bac216f82126e7d42fc1083ec53
|
|
| MD5 |
21e4eadeb90817aa1e98efa9b444334d
|
|
| BLAKE2b-256 |
3649dab07ad5d906ce8aa3a4b176e95d0028c2f2dcbd3535e10f3fb96552b1d1
|
File details
Details for the file waterlight-0.2.1-py3-none-any.whl.
File metadata
- Download URL: waterlight-0.2.1-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96fb597693244aa6f95c667b1cff081e4a42100666a965efb2bfd0d7062db47b
|
|
| MD5 |
d9ac180e8a1c0f01eea75001b2860f9a
|
|
| BLAKE2b-256 |
16683700af779515ac8642245988258afd3f039695c8d06e3c0ec30ed5521ce7
|