Skip to content

Configuration

Every option has a default. You only need this page when the defaults don’t fit.

from parry import Parry
guard = Parry(
cache=True,
cache_ttl=3600,
cache_size=10_000,
rate_limit=True,
on_rate_limit="wait",
max_wait=60.0,
cost_tracking=True,
max_cost_usd=None,
retry=True,
max_attempts=3,
retry_base_delay=0.5,
retry_max_delay=30.0,
storage=None,
)
OptionTypeDefaultMeaning
cacheboolTrueserve identical requests from the cache
cache_ttlfloat | None3600seconds an entry lives. None means it lives until evicted by size
cache_sizeint10_000maximum number of entries. The cache is always bounded, so None or 0 raises ValueError
rate_limitboolTrueapply per-model token buckets
on_rate_limit"wait" | "raise""wait"sleep until a slot frees, or raise RateLimited immediately
max_waitfloat60.0in "wait" mode, raise RateLimited once waiting would exceed this many seconds
cost_trackingboolTruerecord spend in the ledger
max_cost_usdfloat | NoneNonehard budget for this guard’s session. See Budgets
retryboolTrueretry transient failures
max_attemptsint3total attempts, including the first
retry_base_delayfloat0.5first backoff delay in seconds. It doubles on each attempt, with equal jitter
retry_max_delayfloat30.0cap for any single delay, including server Retry-After values
storagestr | Path | NoneNoneSQLite file for a persistent cache and ledger

cache, rate_limit, cost_tracking, retry, max_cost_usd, on_rate_limit and max_wait are plain attributes, so you can change them at runtime:

guard.cache = False
guard.max_cost_usd = 25.0
parry.install(guard=None, *, sync=True, async_=True, openai=True, anthropic=True, **options)
ArgumentDefaultMeaning
guardNoneinstall this Parry instead of creating one
syncTruehook sync clients
async_Truehook async clients (parry.install_async() hooks async only)
openaiTruehook the OpenAI SDK
anthropicTruehook the Anthropic SDK
**optionspassed to Parry(...) when a new guard is created
guard.set_rate_limit(model, requests_per_minute=None, tokens_per_minute=None, *, burst=None, provider=None)
guard.remove_rate_limit(model, *, provider=None)
guard.set_pricing(model, input_per_million, output_per_million)

See Rate limiting and Cost tracking.

guard.set_cache("memory") # default
guard.set_cache("sqlite", path="parry.db")
guard.storage("parry.db") # same as the line above

parry reads no environment variables and no config files. Everything is set in code. Your SDKs keep reading their own variables as usual (OPENAI_API_KEY, ANTHROPIC_BASE_URL, …).