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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opencredit-0.1.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opencredit-0.1.0-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file opencredit-0.1.0.tar.gz.

File metadata

  • Download URL: opencredit-0.1.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.1 Darwin/22.6.0

File hashes

Hashes for opencredit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1988782936c25a65dc8b876ff5452c079dca2fc1a809e21a35bafdf3ba34da4a
MD5 55722a3417e33dec9f1ba18c9639fbcb
BLAKE2b-256 7fccfbbef0f92ba464af3335e2efdb01857e50c8978add1a573cca535cb3d5d1

See more details on using hashes here.

File details

Details for the file opencredit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: opencredit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.1 Darwin/22.6.0

File hashes

Hashes for opencredit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9589c1640350ccf54c74190cc670100c948c3d7b4674d8337df38fda3584833
MD5 48d1628fc71f5069e54d3f06b7481e27
BLAKE2b-256 295cc43dd4b6fa05879b6ca37973d40fec1e466826a660b3f683a9d4446c1a07

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 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