Skip to main content

Lunar SDK

Lunar provides SDKs for Python and TypeScript with 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.

Clients

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

Both SDKs expose the same 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