Token counting, model quotas, and sliding window rate limiter
Find a file
Virgil b3a6279f35 docs(ratelimit): add exported API RFC
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-27 20:33:40 +00:00
.core chore: add .core/ build and release configs 2026-03-06 18:52:37 +00:00
.forgejo/workflows ci: add Forgejo Actions test and security scan workflows 2026-02-23 03:28:08 +00:00
.github/workflows ci: add Core ecosystem CI workflow with CodeRabbit auto-fix 2026-03-17 14:05:50 +00:00
docs fix(ratelimit): align module metadata and repo guidance 2026-03-27 04:23:34 +00:00
specs docs(ratelimit): add exported API RFC 2026-03-27 20:33:40 +00:00
.editorconfig chore: add Go repo norms (badges, contributing, lint, taskfile, editorconfig) 2026-02-23 06:45:45 +00:00
.gitignore chore: add .core/ and .idea/ to .gitignore 2026-03-15 10:17:50 +00:00
.golangci.yml chore: add Go repo norms (badges, contributing, lint, taskfile, editorconfig) 2026-02-23 06:45:45 +00:00
CLAUDE.md fix(ratelimit): align module metadata and repo guidance 2026-03-27 04:23:34 +00:00
CONTRIBUTING.md fix(ratelimit): align module metadata and repo guidance 2026-03-27 04:23:34 +00:00
error_test.go fix(ratelimit): align module metadata and repo guidance 2026-03-27 04:23:34 +00:00
go.mod fix(ratelimit): align module metadata and repo guidance 2026-03-27 04:23:34 +00:00
go.sum refactor(ratelimit): upgrade to core v0.8.0-alpha.1 2026-03-26 15:41:11 +00:00
iter_test.go fix(ratelimit): align module metadata and repo guidance 2026-03-27 04:23:34 +00:00
ratelimit.go fix(ratelimit): align module metadata and repo guidance 2026-03-27 04:23:34 +00:00
ratelimit_test.go fix(ratelimit): align module metadata and repo guidance 2026-03-27 04:23:34 +00:00
README.md fix(ratelimit): align module metadata and repo guidance 2026-03-27 04:23:34 +00:00
sqlite.go fix(ratelimit): align module metadata and repo guidance 2026-03-27 04:23:34 +00:00
sqlite_test.go fix(ratelimit): align module metadata and repo guidance 2026-03-27 04:23:34 +00:00

Go Reference Licence: EUPL-1.2 Go Version

go-ratelimit

Provider-agnostic sliding window rate limiter for LLM API calls. Enforces requests per minute (RPM), tokens per minute (TPM), and requests per day (RPD) quotas per model using an in-memory sliding window. Ships with default quota profiles for Gemini, OpenAI, Anthropic, and a local inference provider. State persists across process restarts via YAML (single-process) or SQLite (multi-process, WAL mode). Includes a Gemini-specific token counting helper and a YAML-to-SQLite migration path.

Module: dappco.re/go/core/go-ratelimit Licence: EUPL-1.2 Language: Go 1.26

Quick Start

import "dappco.re/go/core/go-ratelimit"

// YAML backend (default, single-process)
rl, err := ratelimit.New()
if err != nil {
    log.Fatal(err)
}

// SQLite backend (multi-process)
rl, err = ratelimit.NewWithSQLite("/tmp/ratelimits.db")
if err != nil {
    log.Fatal(err)
}
defer rl.Close()

if rl.CanSend("gemini-2.0-flash", 1500) {
    rl.RecordUsage("gemini-2.0-flash", 1000, 500)
}

if err := rl.Persist(); err != nil {
    log.Fatal(err)
}

Documentation

  • Architecture — sliding window algorithm, provider quotas, YAML and SQLite backends
  • Development Guide — prerequisites, test patterns, coding standards
  • Project History — completed phases with commit hashes, known limitations

Build & Test

go build ./...
go test ./...
go test -race ./...
go vet ./...
go test -cover ./...
go mod tidy

Licence

European Union Public Licence 1.2.