Brain Docs

Reference

Rust SDKInstallationHTTP clientWire client
ErrorsRetriesPagination
Brain/Docs
✦ ASKBrain on GitHubDashboard
Rust SDKRetries

Retries

Both retry layers — the HTTP client's automatic policy with its idempotent-only verb list, and the wire tier's with_retry combinator.

PURPOSE

The HTTP client retries for you, on a list of verbs it considers safe to repeat. The wire client does not retry at all — it ships a combinator you wrap a call in. This page documents both, and the server hint that overrides your backoff.

HTTP tier

BrainHttpClient applies an HttpRetryPolicy, replaceable at construction with with_retry_policy.

ParameterTypeRequired
max_attemptsu32optional
Total attempts including the first. 1 disables retry.
base_delayDurationoptional
First backoff; doubles each attempt.
max_delayDurationoptional
Upper bound on any single backoff — and it also caps a server Retry-After.

What is retried

ConditionRetried
status == 0 — transport failure or timeout, never reached the edgeYes
503 — service unavailableYes
429 — rate limitedYes
Every other statusNo, terminal
Not every verb is retried, and the choices are deliberate

Only idempotent verbs retry. put_llm_credential is excluded because a PUT that may have landed is not safe to repeat blind against a live credential, and subscribe because a retry would reopen the feed at the original position and re-deliver everything already seen.

Wire tier

The wire client does not retry. brain_db_sdk::retry provides:

ParameterTypeRequired
with_retry(&policy, op)Result<T>required

Call op until it succeeds or the policy is exhausted. Retries only what BrainError::is_retryable approves. The policy comes first — unlike Python's and TypeScript's with_retry/withRetry, which take the operation first and the policy as an optional second argument.

with_default_retry(op)Result<T>optional

with_retry against RetryPolicy::default().

RetryPolicystructoptional

max_attempts, base_delay, max_delay. Default is 3 attempts, a 100 ms base and a 5 s cap — note the cap differs from the HTTP tier's 2 s. RetryPolicy::none() is a single attempt.

use brain_db_sdk::{with_default_retry, with_retry, EncodeBuilder, RetryPolicy};

let request = EncodeBuilder::new("...").build();   // build ONCE
let res = with_default_retry(|| client.encode(&request)).await?;

// The same thing with an explicit policy — note the policy argument is first.
let res = with_retry(&RetryPolicy::default(), || client.encode(&request)).await?;

Because the verbs borrow their request, the closure can capture it by reference and every attempt sends the same bytes — which is exactly what makes the retry idempotent.

Jitter

The server's retry_after_ms is a floor, not a target: the combinator waits a random interval between that floor and the computed backoff, so a fleet told to retry after the same hint does not return as one wave. If you write your own loop, add the same jitter — synchronised retries are how a recovering shard is knocked back over.

Idempotency on the wire

Retrying a wire write is only safe because the request carries a request_id. The builders generate a fresh one on every .build(), so re-building is not retrying — it produces a new id and the server sees a second, distinct write. Build once, outside the retry loop.

Replaying the same request_id with different parameters is IdempotencyConflict.

See also
ErrorsWire clientHTTP client

Was this page helpful?

Errors

Both taxonomies — the wire BrainError enum with its nine categories and eighty-odd codes, and the HTTP tier's BrainHttpError.

Pagination

Cursor-based enumeration on the HTTP tier, frame-based streaming on the wire, and the terminator each one uses.

On this page

HTTP tierWhat is retriedWire tierJitterIdempotency on the wire
Suggest an editOpen in Playground