LLMProxy.Limit (llm_proxy v0.2.0)

Copy Markdown View Source

Composable usage and runtime limits for API keys.

Summary

Types

metric()

@type metric() ::
  :concurrent_requests
  | :requests
  | :cache_write_tokens
  | :cache_read_tokens
  | :output_tokens
  | :input_tokens
  | :cost_usd

t()

@type t() :: %LLMProxy.Limit{max: number(), metric: metric(), window: window() | nil}

window()

@type window() :: :month | :week | :day | :four_hours | :hour | :minute

Functions

cache_read_tokens(window, max)

@spec cache_read_tokens(window(), non_neg_integer()) :: t()

cache_write_tokens(window, max)

@spec cache_write_tokens(window(), non_neg_integer()) :: t()

check(arg1)

@spec check(map()) :: :ok | {:error, String.t()}

concurrent_request_limit(arg1)

@spec concurrent_request_limit(map()) :: non_neg_integer() | nil

Returns the most restrictive concurrent-request limit for an API key.

Concurrent limits do not use a stored usage window. Runtime admission uses this value without a storage query.

concurrent_requests(max)

@spec concurrent_requests(non_neg_integer()) :: t()

cost(window, max)

@spec cost(window(), number()) :: t()

input_tokens(window, max)

@spec input_tokens(window(), non_neg_integer()) :: t()

new(metric, window, max)

@spec new(metric(), window() | nil, number()) :: t()

normalize(limits)

@spec normalize(term()) :: {:ok, [t()]} | {:error, String.t()}

output_tokens(window, max)

@spec output_tokens(window(), non_neg_integer()) :: t()

requests(window, max)

@spec requests(window(), non_neg_integer()) :: t()

valid?(limits)

@spec valid?(term()) :: boolean()