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)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file loopers_client-0.4.6.tar.gz.
File metadata
- Download URL: loopers_client-0.4.6.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
989990c1ef4fe24d4fa1384fec6d3a196f5a56dc498ae836066ccf3947924ab1
|
|
| MD5 |
43479563b9348c31f4551f8835e213d2
|
|
| BLAKE2b-256 |
ce8e34d91c59719fb5a869f1908b4103dce713414201303dec01c5f4d0a9d435
|
Provenance
The following attestation bundles were made for loopers_client-0.4.6.tar.gz:
Publisher:
publish-sdks.yml on CURSED-ME/loopers-oss
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
loopers_client-0.4.6.tar.gz -
Subject digest:
989990c1ef4fe24d4fa1384fec6d3a196f5a56dc498ae836066ccf3947924ab1 - Sigstore transparency entry: 1676114147
- Sigstore integration time:
-
Permalink:
CURSED-ME/loopers-oss@4d3147704db87b8c11e988ddd17b06f18a658c9d -
Branch / Tag:
refs/tags/v0.4.6 - Owner: https://github.com/CURSED-ME
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdks.yml@4d3147704db87b8c11e988ddd17b06f18a658c9d -
Trigger Event:
push
-
Statement type:
File details
Details for the file loopers_client-0.4.6-py3-none-any.whl.
File metadata
- Download URL: loopers_client-0.4.6-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3690dd0bca3a1e79cbf22abb84819179b3b1ccdfeb53cfdaffce3d477b21c370
|
|
| MD5 |
4cfa0b18b02cd5d732a0de76bc634fa4
|
|
| BLAKE2b-256 |
73aacdb4f9a795a71233a1d2c859fe28fa32bfde39f3cad12789e2d70da0f57e
|
Provenance
The following attestation bundles were made for loopers_client-0.4.6-py3-none-any.whl:
Publisher:
publish-sdks.yml on CURSED-ME/loopers-oss
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
loopers_client-0.4.6-py3-none-any.whl -
Subject digest:
3690dd0bca3a1e79cbf22abb84819179b3b1ccdfeb53cfdaffce3d477b21c370 - Sigstore transparency entry: 1676114154
- Sigstore integration time:
-
Permalink:
CURSED-ME/loopers-oss@4d3147704db87b8c11e988ddd17b06f18a658c9d -
Branch / Tag:
refs/tags/v0.4.6 - Owner: https://github.com/CURSED-ME
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdks.yml@4d3147704db87b8c11e988ddd17b06f18a658c9d -
Trigger Event:
push
-
Statement type: