Your first AI call in AL
From SecretText to GenerateText: a short walkthrough with structured output.
This tutorial gets you from zero to a validated JSON response using AI Open SDK.
1. Add the dependencies
Reference AI Open SDK (core) and a provider extension such as AI Open SDK Anthropic from GuillemPM/AL-AI-Toolkit. Compile against Business Central Application 28.x.
See Providers for the full packaging model.
2. Store the API key as SecretText
Load keys from Isolated Storage or a setup table into SecretText so the debugger never shows them.
3. Call the model
Anthropic: Codeunit "AIOS Anthropic";
Client: Codeunit "AIOS Client";
Result: Codeunit "AIOS Generate Result";
ApiKey: SecretText;
begin
Result := Client.GenerateText(
Anthropic.Model('claude-sonnet-4-5', ApiKey),
'Say hello in one sentence');
Message(Result.Output());
end;
4. Add structured output
Schema: Codeunit "AIOS Schema";
Fields: List of [JsonObject];
Request: Record "AIOS Chat Request";
begin
Fields.Add(Schema.Field('greeting', Schema.String()));
Request.SetPrompt('Return a short greeting');
Request.SetOutput(Schema.Object(Fields));
Result := Client.GenerateText(Model, Request);
// Result.Output() is validated JSON
end;
5. Test with Mock
Use "AIOS Mock" from Core in your test app so CI never needs live keys. See Mock.