Skip to content

Fail fast, or retry

onError(info) -> retry | fail runs on every failed LLM attempt. info carries { status?, error?, attempt, retryable }status on a non-ok response, error on a transport throw, attempt zero-based, retryable = whether it’s in the default retryable set. A retry is always capped by retries; there is no suspend tier — a failure never becomes a human-in-the-loop pause (that stays suspension, for genuine user actions).

Example policy below: fail fast on 402 (out of credits — retrying won’t help), retry everything else that’s retryable.

const agent = createClient({
baseUrl, style: "openai", model, apiKey,
onError: (info) => (info.status === 402 ? "fail" : info.retryable ? "retry" : "fail"),
})

Leave onError unset and you get today’s behavior byte-for-byte: retry the transient set within budget, fail the rest. See Resilience benchmark for how each port behaves under MCP crashes, network drops, and LLM errors.

Next: Multi-turn memory.