Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

List AI Models

See more AI Examples

Returns a sorted list of AI models available to your account for the specified AI provider, such as GPT-4o and GPT-5.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Ai,
  Chilkat.StringTable;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  ai: TAi;
  st: TStringTable;
  count: Integer;
  i: Integer;

begin
  success := False;

  //  This example assumes the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  ai := TAi.Create;

  //  The provider can be "openai", "google", "claude", "deepseek", "xai", or "perplexity".
  //  Support for additional providers will be added in future versions of Chilkat.
  ai.Provider := 'openai';

  //  Use your provider's API key.
  ai.ApiKey := 'MY_API_KEY';

  //  Note: Chilkat currently uses a hard-coded list of available models for Perplexity and XAi (Grok) 
  //  because these AI providers do not offer an API endpoint to list models. 
  //  If they introduce such a REST API call in the future, Chilkat will update to incorporate it in a later version.

  st := TStringTable.Create;
  success := ai.GetModels(st);
  if (success = False) then
    begin
      WriteLn(ai.LastErrorText);
      Exit;
    end;

  count := st.Count;
  i := 0;
  while i < count do
    begin
      WriteLn(st.StringAt(i));
      i := i + 1;
    end;

  //  Sample output:
  //  (The exact list varies by account, and changes as providers add and retire models.)

  //  babbage-002
  //  chatgpt-4o-latest
  //  codex-mini-latest
  //  dall-e-2
  //  dall-e-3
  //  davinci-002
  //  daybreak-blue-latest
  //  daybreak-red-latest
  //  gpt-3.5-turbo
  //  gpt-3.5-turbo-instruct
  //  gpt-4
  //  gpt-4-turbo
  //  gpt-4.1
  //  gpt-4.1-mini
  //  gpt-4.1-nano
  //  gpt-4o
  //  gpt-4o-audio-preview
  //  gpt-4o-mini
  //  gpt-4o-mini-transcribe
  //  gpt-4o-mini-tts
  //  gpt-4o-transcribe
  //  gpt-5
  //  gpt-5-chat-latest
  //  gpt-5-codex
  //  gpt-5-mini
  //  gpt-5-nano
  //  gpt-5.3-chat-latest
  //  gpt-5.4-mini
  //  gpt-5.4-nano
  //  gpt-5.4-pro
  //  gpt-5.5-pro
  //  gpt-5.6-cyber
  //  gpt-5.6-luna
  //  gpt-5.6-sol
  //  gpt-5.6-terra
  //  gpt-audio
  //  gpt-image-1
  //  gpt-image-2
  //  gpt-live-transcribe
  //  gpt-realtime
  //  gpt-realtime-1.5
  //  gpt-realtime-2
  //  gpt-realtime-2.1
  //  gpt-realtime-2.1-mini
  //  gpt-realtime-mini
  //  gpt-realtime-translate
  //  gpt-realtime-whisper
  //  gpt-transcribe
  //  o1
  //  o1-pro
  //  o3
  //  o3-mini
  //  o4-mini
  //  o4-mini-deep-research
  //  omni-moderation-latest
  //  text-embedding-3-large
  //  text-embedding-3-small
  //  text-embedding-ada-002
  //  tts-1
  //  tts-1-hd
  //  whisper-1


  ai.Free;
  st.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.