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 1.4.0

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 1.4.0
File Size Uploaded Provenance Actions
loopers_client-1.4.0.tar.gz 8.8 kB With provenance Details for loopers_client-1.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 17.1 kB

Release files / loopers_client-1.4.0.tar.gz

Download URL loopers_client-1.4.0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
11ee0808bada6ea25c707467df52a30a72e2ac2b77166fab3a51b98b38e2a355
BLAKE2b-256 checksum
How to use checksums
92a8c2f0764a75dac24073429096e2c89e43b32076cafbf0ec773a7ee4320a69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 3, 2026.

Transparency log

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

Download URL loopers_client-1.4.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
377724b7f7366e8c09ee55271eaa82472db076164d389998c61e1b30ae3d4106
BLAKE2b-256 checksum
How to use checksums
26f706e569acd539671d54ad51ce8345958b9be30ac96002131963b4e0190b38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 3, 2026.

Transparency log

Security for loopers-client 1.4.0

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-1.4.0.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 3, 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