Guaranteed availability
Your agent shouldn’t break because of a single failed network call. The SDK has two layers of protection built in — an in-memory cache and a hardcoded fallback — so your agent always has a configuration to work with.
Caching layer
The SDK caches the last successfully fetched configuration in memory with a default TTL of 300 seconds (5 minutes). A background thread refreshes stale entries before they expire, so your agent never blocks on a network call during normal operation.
If Opik is unreachable during a refresh, the SDK keeps serving the cached value — your agent keeps running.
You can tune the cache TTL by setting the OPIK_CONFIG_TTL_SECONDS environment variable:
Fallback configuration
On the very first call (cold start), or if the cache is empty and Opik is unreachable, you can provide a hardcoded fallback. The SDK returns it instead of raising an error, so your agent can start serving requests right away — even before it has contacted the backend.
Define your fallback as a top-level constant so it stays consistent across calls and is easy to spot in code review.
Detecting fallback usage
The returned config has an is_fallback (Python) / isFallback (TypeScript) property. It’s true when the SDK used your local fallback instead of a backend-fetched configuration. Useful for logging or alerting.
In practice you’ll rarely hit the fallback. Once the first successful fetch populates the cache, the SDK keeps it fresh in the background. The fallback only kicks in during a cold start when the backend isn’t reachable.