In-memory concurrent-request admission for LLMProxy API keys.
Add LLMProxy.Limit.concurrent_requests/1 to a key's budget_limits to
enable the gate. Admission and release do not query storage. Limits apply to
one LLMProxy runtime instance; deployments with multiple instances must size
each instance accordingly.
A lease follows a stream into the process that consumes it. The lease is released when the request or stream ends, when stream enumeration halts, or when the process that owns the lease exits.
Summary
Functions
Tries to acquire one request lease for an API key.
Returns the stable public message for an admission refusal.
Releases a request lease. Repeated release calls are safe.
Returns the retry delay advertised by HTTP admission refusals.
Runs a non-streaming request while holding its configured lease.
Returns aggregate content-free counters for limited requests.
Returns the current active count and configured limit for one key.
Wraps a stream so its lease follows the consumer and is always released.
Types
@type lease() :: LLMProxy.ConcurrencyLimiter.Lease.t() | :unlimited
@type status() :: %{ active: non_neg_integer(), admitted: non_neg_integer(), rejected: non_neg_integer(), released: non_neg_integer() }
Functions
@spec acquire(map(), pid()) :: {:ok, lease()} | {:error, {:limit_exceeded, non_neg_integer()}}
Tries to acquire one request lease for an API key.
Keys without a concurrent-request limit receive an unlimited no-op lease.
@spec child_spec(keyword()) :: Supervisor.child_spec()
@spec error_message() :: String.t()
Returns the stable public message for an admission refusal.
@spec release(lease()) :: :ok
Releases a request lease. Repeated release calls are safe.
@spec retry_after_seconds() :: pos_integer()
Returns the retry delay advertised by HTTP admission refusals.
@spec run(map(), (-> result)) :: result | {:error, {:limit_exceeded, non_neg_integer()}} when result: term()
Runs a non-streaming request while holding its configured lease.
@spec start_link(keyword()) :: GenServer.on_start()
@spec status() :: status()
Returns aggregate content-free counters for limited requests.
Returns the current active count and configured limit for one key.
@spec wrap_stream(Enumerable.t(), lease()) :: Enumerable.t()
Wraps a stream so its lease follows the consumer and is always released.