xemantic-ai-money

Facilitates real-time calculation of AI model API usage costs, leveraging monetary representation and big decimal arithmetic for precise accounting of input and output token expenses.

JVM
iOS
Android Native
macOS
watchOS
tvOS
Linux
Windows
Wasm
JS
GitHub stars5
Authorsxemantic
Dependents1
LicenseApache License 2.0
Creation datealmost 2 years ago

Last activity13 days ago
Latest release0.2 (almost 2 years ago)

xemantic-ai-money

Real-time calculation of LLM usage costs - a Kotlin multiplatform library

Maven Central Version GitHub Release Date license

GitHub Actions Workflow Status GitHub branch check runs GitHub commits since latest release GitHub last commit

GitHub contributors GitHub commit activity GitHub code size in bytes GitHub Created At kotlin version

discord server discord users online X (formerly Twitter) Follow

Why?

The APIs of AI companies, like OpenAI API and Anthropic API, are providing the usage information regarding input and output tokens associated with each API call. Depending on many factors, like the model being used, batch processing, involved cache, etc., these tokens can be billed according to particular rules. This library is fulfilling the need of proper accounting of API usage by:

  • representing monetary amounts as Money interface, supporting big decimal arithmetics and operator overloading,
  • representing ratios of monetary amounts (e.g. input token cost for given model) as Money.Ratio interface.

[!NOTE] The xemantic-ai-money was initially a part of the anthropic-sdk-kotlin, but was eventually externalized, as a common functionality applicable across various API-related use cases.

Usage

In build.gradle.kts add:

dependencies {
    implementation("com.xemantic.ai:xemantic-ai-money:0.2")
}

See test cases for further information.

Big decimal arithmetics

The implementation of big decimal arithmetic in use will depend on the multiplatform targets:

Development

Clone this repo and then in the project dir:

./gradlew build
JVM
iOS
Android Native
macOS
watchOS
tvOS
Linux
Windows
Wasm
JS
GitHub stars5
Authorsxemantic
Dependents1
LicenseApache License 2.0
Creation datealmost 2 years ago

Last activity13 days ago
Latest release0.2 (almost 2 years ago)

xemantic-ai-money

Real-time calculation of LLM usage costs - a Kotlin multiplatform library

Maven Central Version GitHub Release Date license

GitHub Actions Workflow Status GitHub branch check runs GitHub commits since latest release GitHub last commit

GitHub contributors GitHub commit activity GitHub code size in bytes GitHub Created At kotlin version

discord server discord users online X (formerly Twitter) Follow

Why?

The APIs of AI companies, like OpenAI API and Anthropic API, are providing the usage information regarding input and output tokens associated with each API call. Depending on many factors, like the model being used, batch processing, involved cache, etc., these tokens can be billed according to particular rules. This library is fulfilling the need of proper accounting of API usage by:

  • representing monetary amounts as Money interface, supporting big decimal arithmetics and operator overloading,
  • representing ratios of monetary amounts (e.g. input token cost for given model) as Money.Ratio interface.

[!NOTE] The xemantic-ai-money was initially a part of the anthropic-sdk-kotlin, but was eventually externalized, as a common functionality applicable across various API-related use cases.

Usage

In build.gradle.kts add:

dependencies {
    implementation("com.xemantic.ai:xemantic-ai-money:0.2")
}

See test cases for further information.

Big decimal arithmetics

The implementation of big decimal arithmetic in use will depend on the multiplatform targets:

Development

Clone this repo and then in the project dir:

./gradlew build