
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.
Real-time calculation of LLM usage costs - a Kotlin multiplatform library
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:
[!NOTE] The
xemantic-ai-moneywas initially a part of the anthropic-sdk-kotlin, but was eventually externalized, as a common functionality applicable across various API-related use cases.
In build.gradle.kts add:
dependencies {
implementation("com.xemantic.ai:xemantic-ai-money:0.2")
}See test cases for further information.
The implementation of big decimal arithmetic in use will depend on the multiplatform targets:
java.math.BigDecimal for JVM target, for maximal performance and stability.Clone this repo and then in the project dir:
./gradlew buildReal-time calculation of LLM usage costs - a Kotlin multiplatform library
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:
[!NOTE] The
xemantic-ai-moneywas initially a part of the anthropic-sdk-kotlin, but was eventually externalized, as a common functionality applicable across various API-related use cases.
In build.gradle.kts add:
dependencies {
implementation("com.xemantic.ai:xemantic-ai-money:0.2")
}See test cases for further information.
The implementation of big decimal arithmetic in use will depend on the multiplatform targets:
java.math.BigDecimal for JVM target, for maximal performance and stability.Clone this repo and then in the project dir:
./gradlew build