Skip to main content

A premium Python client wrapper for the Loopers AI budget & rate-limit proxy.

Project description

Loopers Python Client SDK (loopers-client)

The loopers-client package provides a drop-in wrapper around official OpenAI and Anthropic SDK clients to make integration with the Loopers cost firewall seamless.

Installation

pip install loopers-client

Additionally, install the official provider package you plan to use:

pip install openai
# or
pip install anthropic

Features

  • Automatic Headers Injection: Automatically handles injection of Loopers proxy keys (Authorization), upstream provider keys (X-Loopers-Provider-Key), and session budget limits.
  • Custom Attributes: Intercepts response headers and attaches cost metadata directly to the returned objects.

Usage

OpenAI Integration

Replace openai.OpenAI with LoopersOpenAI:

from loopers_client import LoopersOpenAI

# Initialize client
client = LoopersOpenAI(
    loopers_url="http://localhost:8080",
    loopers_key="lp-xxx",          # Loopers proxy key
    provider_key="sk-proj-xxx",    # Upstream OpenAI key
    session_id="agent-run-123",    # Optional: track steps and budget for an agent session
    session_budget=2.50,           # Optional: limit session to $2.50
    max_steps=20                   # Optional: limit session to 20 steps
)

# Call completions exactly like the official client
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)

# Inspect budget/cost metadata attached to response
print(f"Request Cost: ${response.loopers_cost} USD")
print(f"Estimated Cost: ${response.loopers_cost_estimated} USD")
print(f"Session Spend: ${response.loopers_session_spend} USD")
print(f"Session Steps: {response.loopers_session_steps}")
print(f"Session Remaining: ${response.loopers_session_remaining} USD")

Async OpenAI

import asyncio
from loopers_client import LoopersAsyncOpenAI

async def main():
    client = LoopersAsyncOpenAI(
        loopers_url="http://localhost:8080",
        loopers_key="lp-xxx",
        provider_key="sk-proj-xxx"
    )
    
    response = await client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": "Hello!"}]
    )
    print(response.loopers_cost)

asyncio.run(main())

Anthropic Integration

from loopers_client import LoopersAnthropic

client = LoopersAnthropic(
    loopers_url="http://localhost:8080",
    loopers_key="lp-xxx",
    provider_key="sk-ant-xxx"
)

response = client.messages.create(
    model="claude-3-5-sonnet-latest",
    max_tokens=1000,
    messages=[{"role": "user", "content": "Hello!"}]
)

print(response.loopers_cost)

Other Providers (Groq, Mistral, DeepSeek, Together)

Because these providers are OpenAI-compatible, they share the exact same interface as LoopersOpenAI. Simply substitute the class name:

from loopers_client import LoopersGroq, LoopersMistral, LoopersDeepSeek, LoopersTogether

# Example using Groq
client = LoopersGroq(
    loopers_url="http://localhost:8080",
    loopers_key="lp-xxx",
    provider_key="gsk_xxx"
)

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

loopers_client-1.3.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

loopers_client-1.3.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file loopers_client-1.3.0.tar.gz.

File metadata

  • Download URL: loopers_client-1.3.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for loopers_client-1.3.0.tar.gz
Algorithm Hash digest
SHA256 bba6b6ed05f4b2cde21498d77a33bfde16222b716497e14f08b36d57c45a135e
MD5 4ac4e0bfe03b1b3d641116cd1bc4602e
BLAKE2b-256 903b3b38976ab7b45a2c5e425d1b165568e47476d19f2c39175e95f1858efc44

See more details on using hashes here.

Provenance

The following attestation bundles were made for loopers_client-1.3.0.tar.gz:

Publisher: publish-python-sdk.yml on CURSED-ME/loopers-oss

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file loopers_client-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: loopers_client-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for loopers_client-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ded12b47f3bf3c178e6fa061012411523b206ad1849295a7111253878fa827b
MD5 c2f781ce13b7d8dae44af1d0e2d8f852
BLAKE2b-256 94b6352bb2c2ea89017f4081c85384d30c215d90d7ead360a7bc4e7811676add

See more details on using hashes here.

Provenance

The following attestation bundles were made for loopers_client-1.3.0-py3-none-any.whl:

Publisher: publish-python-sdk.yml on CURSED-ME/loopers-oss

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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