No project description provided
Project description
Paid is the all-in-one, drop-in Business Engine for AI Agents that handles your pricing, subscriptions, margins, billing, and renewals with just 5 lines of code. The Paid Python library provides convenient access to the Paid API from Python applications.
Documentation
See the full API docs here
Installation
You can install the package using pip:
pip install paid-python
Usage
The client needs to be configured with your account's API key, which is available in the Paid dashboard.
from paid import Client
client = Paid(token="API_KEY")
client.customers.create(
name="name"
)
Request And Response Types
The SDK provides Python classes for all request and response types. These are automatically handled when making API calls.
# Example of creating a customer
response = client.customers.create(
name="John Doe",
)
# Access response data
print(response.name)
print(response.email)
Exception Handling
When the API returns a non-success status code (4xx or 5xx response), the SDK will raise an appropriate error.
try:
client.customers.create(...)
except paid.Error as e:
print(e.status_code)
print(e.message)
print(e.body)
print(e.raw_response)
Logging
Supported log levels are DEBUG, INFO, WARNING, ERROR, and CRITICAL.
For example, to set the log level to debug, you can set the environment variable:
export PAID_LOG_LEVEL=DEBUG
Falls back to INFO
Cost Tracking
As of now, the following OpenAI python APIs are supported:
chat.completions.create()
responses.create()
images.generate()
embeddings.create()
Example usage:
import os
from openai import OpenAI
import dotenv
from paid import Paid
from paid.tracing.wrappers import PaidOpenAI
# Initialize Paid SDK
client = Paid(token="PAID_API_KEY")
# Initialize OpenAI client
_ = dotenv.load_dotenv()
openAIClient = PaidOpenAI(OpenAI(
# This is the default and can be omitted
api_key=os.getenv("OPENAI_KEY"),
))
# Initialize tracing, must be after initializeing Paid SKD
client.initialize_tracing()
# Capture chat request in telemetry
def chat_complete1():
response = openAIClient.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a coding assistant that talks like a pirate."},
{"role": "user", "content": "How do I check if a Python object is an instance of a class?"}
]
)
return response
def chat_complete2():
response = openAIClient.responses.create(
model="gpt-4o",
instructions="You are a historian.",
input="When did Boston tea party happen?",
)
return response
def embeddings():
response = openAIClient.embeddings.create(
model="text-embedding-3-small",
input=["Hello world", "How are you?"]
)
return response
def image_generate():
response = openAIClient.images.generate(
model="dall-e-3",
prompt="A sunset over mountains",
size="1024x1024",
quality="hd",
style="vivid",
n=1
)
return response
def do_agent_work():
chat_complete1()
chat_complete2()
image_generate()
embeddings()
# Finally, Capture the traces!
_ = client.capture("your_external_customer_id", do_agent_work)
Contributing
While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
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 paid_python-0.0.5a2.tar.gz.
File metadata
- Download URL: paid_python-0.0.5a2.tar.gz
- Upload date:
- Size: 36.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/6.11.0-1015-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b774e015388ac5c76a0ee43d02e93cd015d63e8eaf7681b3de28f0e2b7ecd177
|
|
| MD5 |
e318640eba86512227f61c6876afaee7
|
|
| BLAKE2b-256 |
694ba983a73bc6e15d910f1aa7b55ac3f89bd9b0489514e9edcfa4884b6732b1
|
File details
Details for the file paid_python-0.0.5a2-py3-none-any.whl.
File metadata
- Download URL: paid_python-0.0.5a2-py3-none-any.whl
- Upload date:
- Size: 61.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/6.11.0-1015-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aac53f63055241d6956afebafcb8feb698e7e66adb31b78767fe385ad0efc094
|
|
| MD5 |
c0c1827ca7c2fb97a8bf0032fb993730
|
|
| BLAKE2b-256 |
64dd450446acde04a2da38e5f029ce5e97e6994bc5215bb4e4036f31aa0fbaa1
|