惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
N
Netflix TechBlog - Medium
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
V
Visual Studio Blog
H
Help Net Security
Engineering at Meta
Engineering at Meta
Hugging Face - Blog
Hugging Face - Blog
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
博客园 - 【当耐特】
B
Blog
Stack Overflow Blog
Stack Overflow Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
博客园 - 司徒正美
博客园 - 叶小钗
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

Hacker News - Newest: "AI"

AI can't read an investor deck AI as an attorney? Student uses ChatGPT, Gemini to sue UW over alleged racial discrimination Hacking MCP Servers in AI Systems – The Rug Pull: Tool Changes After Approval GitHub - MeepCastana/KubeezCut: Free Web based video editor Can AI judge journalism? A Thiel-backed startup says yes, even if it risks chilling whistleblowers Coming soon: 10 Things That Matter in AI Right Now DARPA built an AI to fact-check enemy weapons claims What explains heterogeneity in AI adoption? When AI Meets Muscle: Context-Aware Electrical Stimulation Promises a New Way to Guide Human Movements - Department of Computer Science AI Changed How We Build. It Did Not Change What Matters. Linux rules on using AI-generated code - Copilot is OK, but humans must take 'full responsibility for the… Meta spins up AI version of Mark Zuckerberg to engage with employees Code Mode: Let Your AI Write Programs, Not Just Call Tools | TanStack Blog GitHub - Delavalom/graft: Go framework for building AI agents. Type-safe tools, multi-provider (OpenAI, Anthropic, Gemini, Bedrock), zero vendor SDKs. India's TCS tops estimates, says new AI models did not dent services demand Gen Z's fading AI hype Strong feeling: we are in a folded AI reality GitHub - machinarii/total-recall-catalog: A reference catalog of latest knowledge retrieval, memory & RAG systems GitHub - mensfeld/code-on-incus: Give each AI agent its own isolated machine with root, Docker, and systemd. Active defense detects and stops threats automatically.. Quantization, LoRA, and the 8% Problem: Benchmarking Local LLMs for Production AI Iran war: We spoke to the man making Lego-style AI videos that experts say are powerful propaganda Powell, Bessent discussed Anthropic's Mythos AI cyber threat with major U.S. banks GitHub - immartian/bellamem: Persistent belief-graph memory for AI agents. Retrieves decisive context by importance — not recency, not RAG, not /compact. recursive-mode: The Repo-Native Operating System for AI Engineering After the attack on Sam Altman's home, will AI CEO's go on the offensive? The biggest advance in AI since the LLM Opus 4.6 vs GPT 5.4 One Prompt Unity World Generation Test “AI polls” are fake polls Client Challenge Can AI be a 'child of God'? Inside Anthropic's meeting with Christian leaders
GitHub - baseledger-io/baseledger
minjibir · 2026-05-11 · via Hacker News - Newest: "AI"

BaseLedger Engine (Open Core)

A high-integrity, high-performance usage and budget firewall for AI agents. Built with Scala 3, Pekko, and PostgreSQL.

Autonomous LLM agents and concurrent API calls create a unique financial risk: API Budget Bankruptcy.

Traditional "balance" columns in a user table are vulnerable to race conditions and double-charging during network retries. BaseLedger solves this using three mathematically proven mechanics:

  1. The Reservation Pattern: Lock funds (or usage units) before starting an LLM call. Only deduct them once the job succeeds.
  2. The Idempotency Shield: Every command is tagged with a key. Network retries are automatically ignored, ensuring you never charge a user twice for the same prompt.
  3. The Dead-Man's Switch: Reservations automatically expire (and refund) if an AI job crashes or hangs, preventing "frozen" units.

Prerequisites

Depending on how you intend to run BaseLedger, you will need:

  • For the Quick Start: Docker (with Docker Compose) OR Podman (with Podman Compose).
  • For Local Development: JDK 17+ (GraalVM recommended) a running PostgreSQL instance, and Flyway CLI (or use the docker-compose to run the migrations for you).

Quick Start

The fastest way to get started is spinning up the pre-configured PostgreSQL instance and the BaseLedger API via containers.

Using Docker:

docker-compose up -d

Using Podman (Daemonless alternative to Docker):

podman-compose up -d

Core Lifecycle Example

1. Add Credits (or Usage Units) to a Wallet

curl -X POST http://localhost:8000/wallet/user-123/add \
  -H "Content-Type: application/json" \
  -d '{
    "idempotencyKey": "topup-1",
    "amount": 1000,
    "metadata": {"source": "stripe-checkout"}
  }'

2. Reserve Tokens for an LLM Prompt

curl -X POST http://localhost:8000/wallet/user-123/reserve \
  -H "Content-Type: application/json" \
  -d '{
    "idempotencyKey": "prompt-1", 
    "holdId": "hold-abc", 
    "amount": 400, 
    "ttlSeconds": 30,
    "metadata": {"model": "gpt-4-turbo"}
  }'

3. Settle the Charge (LLM Success)

curl -X POST http://localhost:8000/wallet/user-123/spend \
  -H "Content-Type: application/json" \
  -d '{
    "idempotencyKey": "spend-1", 
    "holdId": "hold-abc",
    "amount": 123,
    "metadata": {"feature": "image_generation"}
  }'

4. Release a Reservation (LLM Failure / Cancellation)

curl -X POST http://localhost:8000/wallet/user-123/release \
  -H "Content-Type: application/json" \
  -d '{
    "idempotencyKey": "release-1",
    "holdId": "hold-abc",
    "metadata": {"reason": "timeout"}
  }'

5. Query Wallet Balance

curl http://localhost:8000/wallet/user-123

All write endpoints return the current wallet state:

{"id": "user-123", "availableBalance": 877, "reservedBalance": 0}

Health Endpoints

# Liveness probe (is the process running?)
curl http://localhost:8000/health/live

# Readiness probe (is the database reachable?)
curl http://localhost:8000/health/ready

How it Works (The Integrity Core)

BaseLedger is designed for absolute correctness. It uses Event Sourcing and Monotonic Timestamps to ensure a perfect, immutable audit trail of every credit and debit.

  • Event Sourced: Every balance change is derived from a sequence of events.
  • R2DBC Journal: High-performance, non-blocking persistence.
  • Projected Read Side: A separate SQL table for instant balance queries.

Configuration

Variable Description Default
POSTGRES_HOST Database host localhost
POSTGRES_PORT Database port 3210
POSTGRES_DB Database name baseledger
POSTGRES_USER Database user baseledger
POSTGRES_PASSWORD Database password password
HTTP_PORT API Port 8000

Local Development (From Source)

Ensure you have JDK 17+ installed and a local PostgreSQL database running on port 3210.

1. Apply Database Migrations: BaseLedger requires the database schema to be initialized before booting. Use the Flyway CLI to run the migrations located in the resources directory:

flyway -url=jdbc:postgresql://localhost:3210/baseledger -user=baseledger -password=password -locations=filesystem:src/main/resources/db/migrations migrate

(Alternatively, you can just run docker-compose up -d db migrations to spin up the DB and run the migrations, then run ./sbtx run locally).

2. Start the Application: With the schema in place, you can now run the application:

./sbtx run

Running Tests

Integration tests use Testcontainers to spin up a real PostgreSQL instance.

./sbtx test

Building the Native Image

To build the highly optimized GraalVM standalone binary:

./sbtx "GraalVMNativeImage / packageBin"

Built for the next generation of autonomous AI applications.


Enterprise & Cloud

The Open-Source engine uses PostgreSQL for zero-friction local deployment. If your AI agents go viral and you need to scale past Postgres limitations, we offer a fully-managed Serverless Cloud tier (powered by DynamoDB).

For massive scale, we offer a BYOC (Bring Your Own Cloud) Enterprise License powered by ScyllaDB for 10,000+ TPS and 99.999% SLA.

Learn more at baseledger.io