Help us shape the future of Go! Take the 2026 Go Developer Survey

ratelimit

package
v0.3.45 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package ratelimit provides request and token rate limiting for LLM sources. Supports both Redis-backed shared counters and in-memory per-node fallback.

Index

Constants

This section is empty.

Variables

View Source
var ErrRateLimitExceeded = errors.New("rate limit exceeded")

Functions

This section is empty.

Types

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

Limiter enforces per-minute request and token limits for an LLM source. When a StoreSource is provided, counters are shared via Redis keys. Otherwise, counters are tracked in-memory (per-node only).

func New

func New(sourceName string, rpm, tpm int, store sources.StoreSource) *Limiter

New creates a rate limiter for the given source. If store is nil, uses in-memory counters.

func (*Limiter) Check

func (l *Limiter) Check(ctx context.Context) error

Check verifies that the current request is within rate limits. Call before making an API request.

func (*Limiter) Record

func (l *Limiter) Record(ctx context.Context, totalTokens int) error

Record updates token counters after a successful API call. Returns an error if the token limit has been exceeded (informational — request already completed).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL