ratelimiter

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ratelimiter provides rate limiting primitives for LLM calls, mirroring langchain_core.rate_limiters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RateLimited

func RateLimited(err error) bool

RateLimited reports whether err is the rate-limited sentinel.

Types

type InMemoryRateLimiter

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

InMemoryRateLimiter is a token-bucket style rate limiter, mirroring langchain_core.rate_limiters.InMemoryRateLimiter.

It enforces a maximum number of requests per time window. The implementation uses a simple sliding window with a mutex and is safe for concurrent use.

func NewInMemoryRateLimiter

func NewInMemoryRateLimiter(cfg InMemoryRateLimiterConfig) *InMemoryRateLimiter

NewInMemoryRateLimiter builds an InMemoryRateLimiter.

func (*InMemoryRateLimiter) Acquire

func (r *InMemoryRateLimiter) Acquire(ctx context.Context) error

Acquire blocks until a request is permitted.

type InMemoryRateLimiterConfig

type InMemoryRateLimiterConfig struct {
	// RequestsPerSecond is the maximum average number of requests per second.
	RequestsPerSecond float64
	// CheckEvery is how often the bucket is refilled. Defaults to 0.1s.
	CheckEvery time.Duration
	// MaxBucketSize is the maximum burst size. Defaults to the same as
	// RequestsPerSecond.
	MaxBucketSize float64
}

InMemoryRateLimiterConfig configures an InMemoryRateLimiter.

type RateLimiter

type RateLimiter interface {
	// Acquire blocks until a request is permitted, or the context is done.
	Acquire(ctx context.Context) error
}

RateLimiter is the interface for rate limiters that can gate requests.

Jump to

Keyboard shortcuts

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