Skip to main content

Lunar SDK

Lunar is a Python SDK that provides a simple, OpenAI-compatible interface to access multiple LLM providers through the PureAI API. It features intelligent fallback mechanisms, per-request cost tracking, and a built-in evaluation framework.

Key Features

OpenAI-Compatible

Drop-in replacement for OpenAI SDK. Migrate existing code with minimal changes.

Intelligent Fallbacks

Automatic retry with fallback models when providers experience issues.

Cost Tracking

Real-time cost tracking for every request with token-level granularity.

Built-in Evals

Comprehensive evaluation framework with 15+ built-in scorers.

Architecture

┌─────────────────────────────────────────────────┐
│                  Your Application               │
├─────────────────────────────────────────────────┤
│                   Lunar SDK                     │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────┐ │
│  │    Chat     │  │ Completions │  │  Evals  │ │
│  └─────────────┘  └─────────────┘  └─────────┘ │
├─────────────────────────────────────────────────┤
│                  PureAI API                     │
├─────────────────────────────────────────────────┤
│   OpenAI   │  Anthropic  │  Groq  │  Together  │
└─────────────────────────────────────────────────┘

API Endpoints

EnvironmentBase URL
Productionhttps://api.pureai-api.com
Developmenthttps://dev-api.pureai-api.com

Clients

The SDK provides two client classes:
ClientDescription
LunarSynchronous client for standard applications
AsyncLunarAsynchronous client for high-performance applications

Quick Example

from lunar import Lunar

client = Lunar(api_key="your-api-key")

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello!"}]
)

print(response.choices[0].message.content)
print(f"Cost: ${response.usage.total_cost_usd}")

Resources

The SDK exposes these resources:
ResourceDescription
client.chat.completionsChat completion API (messages-based)
client.completionsText completion API (prompt-based)
client.modelsList available models
client.providersList available providers
client.evalsRun evaluations
client.datasetsManage evaluation datasets

Next Steps