KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Validating Model Aliases at Startup with `OpenAIProviders.modelAliases()
PRODUCT: 4D | VERSION: 21 R | PLATFORM: Mac & Win
Published On: December 2, 2026
Model aliases provide short, convenient names for AI models. For example, an application can use `"chat"` instead of specifying a provider and model every time. These aliases are defined in the `AIProviders.json` file.

However, a typo in an alias name or a reference to a non-existent provider can go unnoticed until the application sends its first request.

To catch these configuration issues earlier, a validation method can be executed at application startup using `OpenAIProviders.modelAliases()`.

The following method checks a collection of required aliases against the configured aliases and verifies that each referenced provider exists.

#DECLARE($required : Collection) : Collection

var $providers : cs.AIKit.OpenAIProviders
$providers:=cs.AIKit.OpenAIProviders.new()

var $aliases : Collection
$aliases:=$providers.modelAliases()

var $problems : Collection
$problems:=[]

var $alias : Text
var $matches : Collection

For each ($alias; $required)
  $matches:=$aliases.query("name = :1"; $alias)

  If ($matches.length=0)
    $problems.push("Alias not found: "+$alias)
  Else
    If ($providers.get($matches[0].provider)=Null)
      $problems.push("Alias '"+$alias+"' points to unknown provider '"+$matches[0].provider+"'")
    End if
  End if
End for each

return $problems


Call the method with the aliases required by the application:

$problems:=ValidateAliases(["chat"; "vision"])

The returned collection contains one message for each configuration issue. An empty collection means that all requested aliases exist and reference configured providers.

Running a validation check at startup helps detect missing aliases and invalid provider references before the application starts making AI requests. This makes configuration issues easier to identify and troubleshoot.