Python SDK for Lunary, the open-source platform where GenAI teams manage and improve LLM chatbots.
Actively maintained. Last release 4 weeks ago. A safe choice.
pip install lunaryUse it with any LLM model and custom agents (not limited to OpenAI).
To get started, get a project ID by registering here.
🛠️ Installation
pip install lunary
🤖 Anthropic Integration
from anthropic import Anthropic
import lunary
client = Anthropic()
lunary.monitor(client)
parsed = client.messages.parse(
model="claude-sonnet-4-5-20250929",
max_tokens=256,
messages=[{"role": "user", "content": "Return JSON with an answer field for 2 + 2."}],
output_format=dict,
)
with client.messages.stream(
model="claude-sonnet-4-5-20250929",
max_tokens=256,
messages=[{"role": "user", "content": "Stream one sentence about Lunary."}],
) as stream:
for event in stream:
pass
Diagnosing event delivery errors
Keep LUNARY_VERBOSE unset or false in production and capture ERROR logs from lunary.consumer. Each failed send produces one line explaining what happened and whether the SDK will retry. It includes the exception type, HTTP status when available, and the number of events in the batch.
Error sending events. Invalid API key. Batch will not be retried. error_type=HTTPError http_status=401 batch_size=3.
Error sending events. The endpoint rate-limited the request. Batch will not be retried. error_type=HTTPError http_status=429 batch_size=3.
Error sending events. The ingestion service or gateway is unavailable. Batch will not be retried. error_type=HTTPError http_status=503 batch_size=3.
Error sending events. The endpoint did not respond in time. Batch will not be retried. error_type=ReadTimeout http_status=n/a batch_size=3.
| Diagnostic | First checks |
|---|---|
| HTTP 401 / 403 | Project API key and access configuration. |
| HTTP 402 | Project ID format or account billing/access status; the ingestion API also uses this status for a malformed project ID. |
| HTTP 400 / 422 |