AI Open SDKfor Business Central

Retries

Choose how many times a call retries temporary provider failures, and test it without a provider.

A provider can throttle or time out even when your request is correct. The client retries those temporary failures before it raises an error, so a single slow response does not break the page or job.

Set the retry budget

Set the number of extra attempts on the request:

Request.SetMaxRetries(1);
Result := Client.GenerateText(Model, Request);
SettingAttempts
Not setUp to 3 (the default of 2 retries)
Request.SetMaxRetries(0)1, no retries
Request.SetMaxRetries(N)Up to N + 1

The short overloads, such as Client.GenerateText(Model, Prompt), use the default. GetMaxRetries returns the value that applies, and ClearMaxRetries restores the default.

Between attempts the client waits a short, growing delay (a fraction of a second, at most two seconds). The time limit from SetTimeout applies to each attempt, not to the whole call.

What is retried

Error typeRetried
RateLimitedYes
TimeoutYes
ProviderUnavailableYes
Every other typeNo, the error is raised at once

An authentication or invalid-request error will not succeed on a second try, so the client does not spend attempts on it. See Error handling for the full list.

Choose a value

Where the call runsSuggestion
Interactive page, user is waiting0 or 1, then show a soft-fail message
Job queue or background taskDefault, or higher when the provider throttles often
Tool loop with several stepsDefault. Each step has its own retry budget

Every attempt is a separate model call, so retries count toward Result.GetStepCount() and the token totals on the result.

Image requests

"AIOS Image Request" has the same SetMaxRetries and GetMaxRetries procedures, with the same default and the same retried error types.

Test retries

"AIOS Mock" can fail a set number of calls with RateLimited and then succeed. Call SetNextResponse first, because it resets the queued failures:

MockRetry.al
[Test]
procedure Summary_Recovers_AfterRateLimit()
var
    Mock: Codeunit "AIOS Mock";
    Client: Codeunit "AIOS Client";
    Request: Record "AIOS Chat Request";
    Result: Codeunit "AIOS Generate Result";
begin
    Mock.SetNextResponse('recovered');
    Mock.SetFailuresBeforeSuccess(2);
    Request.SetPrompt('Summarize this note');
    Request.SetMaxRetries(2);

    Result := Client.GenerateText(Mock.Model('mock-model'), Request);

    if Result.Output() <> 'recovered' then
        Error('Unexpected output: %1', Result.Output());
end;

With Mock.SetFailuresBeforeSuccess(3) and the same budget, the call raises an error after the third failed attempt.

On this page