ratelimit

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 2 Imported by: 1 module, 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

Index

Constants

View Source
const (
	OpenAIRPM     = 3500 // Requests per minute
	OpenAIBurst   = 10   // Burst allowance
	SentinelRPM   = 0    // Unlimited (OSS models)
	OllamaRPM     = 0    // Unlimited (local)
	HuggingFaceRP = 0    // Unlimited (local sentence-transformers)
)

OpenAI rate limits (per minute)

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

Limiter wraps rate.Limiter with provider-specific limits

func NewLimiter

func NewLimiter(embeddingModel string) *Limiter

NewLimiter creates a rate limiter for the given embedding provider

func NewUnlimitedLimiter

func NewUnlimitedLimiter() *Limiter

NewUnlimitedLimiter creates a limiter with no rate restrictions

func (*Limiter) Allow

func (l *Limiter) Allow() bool

Allow checks if an action can proceed without blocking

func (*Limiter) Burst

func (l *Limiter) Burst() int

Burst returns the maximum burst size

func (*Limiter) Enabled

func (l *Limiter) Enabled() bool

Enabled returns true if rate limiting is active

func (*Limiter) Limit

func (l *Limiter) Limit() rate.Limit

Limit returns the current rate limit (requests per second)

func (*Limiter) Provider

func (l *Limiter) Provider() string

Provider returns the detected provider name

func (*Limiter) SetRateLimit

func (l *Limiter) SetRateLimit(requestsPerMinute int)

SetRateLimit updates the rate limit dynamically

func (*Limiter) Tokens

func (l *Limiter) Tokens() float64

Tokens returns the current number of available tokens

func (*Limiter) Wait

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

Wait blocks until the rate limiter allows an action

Jump to

Keyboard shortcuts

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