Skip to main content

OpenCredit

SurfDino Logo

Credit management for pay-per-use applications
Explore the docs »

View Demo · Report Bug · Request Feature


Installation

pip install opencredit

Usage

Connect

Get an API key

opencredit login https://foo.bar

Connect the Python client

import os
from opencredit import Client

client = Client(addr="https://foo.bar", api_key=os.getenv("OPENCREDIT_API_KEY"))

Define a credit type

Define a credit type for your application.

client.create_credit(
        name="MyAppCredit",
        description="Credit for my awesome application"
        user_minimum=-20.00,
        user_maximum=10000.00,
        user_start=10.00,
    )

user_minimum is the default minimum credit a user can have.
user_maximum is the default maximum credit a user can have.
user_start is the default starting credit a user has.

Per user configuration

Add credits for a user

client.add_user_credit(credit="MyAppCredit", email="dolores@agentsea.ai", amount=100.00)

Set per user limits

client.set_user_limits(
        credit="MyAppCredit",
        email="dolores@agentsea.ai",
        user_minimum=-20.00,
        user_maximum=10000.00,
        user_start=200.00
    )

Set automatic top up

client.set_user_topup(
        credit="MyAppCredit",
        email="dolores@agentsea.ai",
        min_balance=5.00,
        topup_amount=10.00
    )

Use credits

See how many credits the user currently has

client.get_balance(credit="MyAppCredit", email="dolores@agentsea.ai")

Create a meter to charge credits based on type of usage

client.create_meter(
        credit="MyAppCredit",
        name="llm_tokens",
        unit="token",
        cost=0.0004,
        description="LLM generated tokens"
    )

Tik the meter to use credits

client.tik_meter(name="llm_tokens", amount=200, email="dolores@agentsea.ai")

Reporting

Get a report of credit usage

client.get_report(
        credit="MyAppCredit",
        email="dolores@agentsea.ai",
        start="2020-01-01",
        end="2020-01-31"
    )

Hosting a credit server

Run locally

from opencredit import Server

server = Server(backend="postgres")

server.serve()

Run on Kubernetes

helm install open-credit-server --set backend=postgres open-credit

Release files for opencredit 0.1.1

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

Source distribution (sdist)

Source distribution for opencredit 0.1.1
File Size Uploaded
opencredit-0.1.1.tar.gz 15.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opencredit 0.1.1
File Interpreter ABI Platform
opencredit-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 34.2 kB

Release files / opencredit-0.1.1.tar.gz

Download URL opencredit-0.1.1.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
71ec580c6d97121ebd76c595f6f9b228c5b02eb24a6e4235a7bbcbe8f15ef0f9
BLAKE2b-256 checksum
How to use checksums
426f420ca005305e132977e3beb098b4084d3d15703a20cc1e424602ce6df139
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.1 Darwin/22.6.0

Release files / opencredit-0.1.1-py3-none-any.whl

Download URL opencredit-0.1.1-py3-none-any.whl
Size 19.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
774d37fb5b8788fa52ef83abeca1c43fa3209ed3b5660bd2d013a70f45d30062
BLAKE2b-256 checksum
How to use checksums
c0f15cb7f29fa1990e623f1572f5af78423dc8649fe0d587758f1fa1e3443bc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.1 Darwin/22.6.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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