Skip to main content

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.ai")
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.ai
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


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.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

waterlight-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file waterlight-0.1.0.tar.gz.

File metadata

  • Download URL: waterlight-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for waterlight-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a7a5e7a512a6d876cf20f1518685fa3409f7f8b36810cdf63a79c684603a69c7
MD5 8ee5b4c70b43885fa6faad40366a52d9
BLAKE2b-256 109265c2d83ab1072d0e931753210493ef7afa461d49824f42ad2b5e9fedeca8

See more details on using hashes here.

File details

Details for the file waterlight-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: waterlight-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for waterlight-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1588ba049cd60e3c41c0a8de988b5db66b06f3f0152a8ae0cdd6bf42dedb449e
MD5 74bf260d595b482bba2d05b0c409739b
BLAKE2b-256 6ba5fcd1e1d90f2a2d549f9bbaec2f1e62fcd7b0c5e0d1fd10e04a754c696dc4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page