Skip to main content

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

Metadata

Release files for loopers-client 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for loopers-client 2.0.2
File Size Uploaded Provenance Actions
loopers_client-2.0.2.tar.gz 12.0 kB With provenance Details for loopers_client-2.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for loopers-client 2.0.2
File Interpreter ABI Platform Actions
loopers_client-2.0.2-py3-none-any.whl Python 3 none any Details for loopers_client-2.0.2-py3-none-any.whl

Total release size: 22.8 kB

Release files / loopers_client-2.0.2.tar.gz

Download URL loopers_client-2.0.2.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
fc5972c03a67465bc01c65b7896b76db0a0565ceca838e531f3e9cfd2689f74f
BLAKE2b-256 checksum
How to use checksums
e244cf1dc399cb7c73171995e435234e6ee8ff84b41c69ea71e1a340eeb3ed56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.

Transparency log

Release files / loopers_client-2.0.2-py3-none-any.whl

Download URL loopers_client-2.0.2-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31fd66af9687acddd42e6b49ab7b7e42a28415758d792f3e3dea567365c3277f
BLAKE2b-256 checksum
How to use checksums
217cc2e653a25af3d53a540997bbcab70e561f530611b9731781c48e05443a75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.

Transparency log

Security for loopers-client 2.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for loopers_client-2.0.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page