Installation
Configuration
Basic Setup
from limitry import Limitry
# Using API key directly
client = Limitry(api_key="limitry_sk_...")
# Using environment variable (recommended)
import os
client = Limitry(api_key=os.environ.get("LIMITRY_API_KEY"))
The SDK automatically reads from the LIMITRY_API_KEY environment variable if no key is provided.
Configuration Options
from limitry import Limitry
client = Limitry(
api_key="limitry_sk_...",
# Custom base URL (for self-hosted or testing)
base_url="https://api.limitry.com/v1",
# Request timeout in seconds
timeout=30,
# Custom headers
default_headers={"X-Custom-Header": "value"}
)
Quick Example
from limitry import Limitry
client = Limitry()
# Check if request is allowed
check = client.limits.check(customer_id="cust_123")
if check.allowed:
# Make your API/LLM call here...
response = call_your_api()
# Record the usage
client.events.record(
customer_id="cust_123",
event_type="api_call",
values={"requests": 1, "tokens": 150},
dimensions={"endpoint": "/chat"}
)
Async Support
For async applications, use the AsyncLimitry client:
import asyncio
from limitry import AsyncLimitry
async def main():
async with AsyncLimitry() as client:
check = await client.limits.check(customer_id="cust_123")
if check.allowed:
# Your async API/LLM call here...
response = await call_your_api()
await client.events.record(
customer_id="cust_123",
event_type="api_call",
values={"requests": 1, "tokens": 150},
dimensions={"endpoint": "/chat"}
)
asyncio.run(main())
The async client uses async with for proper connection management. You can also instantiate it directly and call await client.close() when done.
Next Steps