#!/usr/bin/env perl
# ABSTRACT: Simple script to check the model list on an OpenAI compatible API
# PODNAME: langertha_list_models

use strict;
use warnings;
use Langertha::Engine::OpenAI;
use Carp qw( croak );
use Time::HiRes qw( time );
use Path::Tiny;
use JSON::MaybeXS;
use URI;

binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");

my $base = shift @ARGV;
my $api_key = shift @ARGV;

die "Requires base url" unless $base;

my $engine = Langertha::Engine::OpenAI->new(
  url => $base,
  api_key => ($api_key||""),
);

my $start = time;
my $request = $engine->generate_request( listModels => sub {});
my $response = $engine->user_agent->request($request);
my $data = decode_json($response->content);
if ($response->is_success) {
  my @list = map { $_->{id} } @{$data->{data}};
  print($_."\n") for sort { $a cmp $b } @list;
} else {
  print($data->{error}->{message}."\n");
}
my $end = time;
printf("\n -- %.3f seconds (%s)\n", ($end - $start), (ref $engine)) unless $ENV{LANGERTHA_NO_TIME};

__END__

=pod

=encoding UTF-8

=head1 NAME

langertha_list_models - Simple script to check the model list on an OpenAI compatible API

=head1 VERSION

version 0.100

=head1 SYNOPSIS

  $ langertha_list_models https://api.openai.com $OPENAI_API_KEY

  $ langertha_list_models https://api.mistral.ai $MISTRAL_API_KEY

=head1 DESCRIPTION

Simple transcription with a Whisper compatible server, Groq or OpenAI.

=head1 HOW TO INSTALL FASTER WHISPER

L<https://github.com/fedirz/faster-whisper-server>

=head1 SUPPORT

Repository

  https://github.com/Getty/langertha
  Pull request and additional contributors are welcome

Issue Tracker

  https://github.com/Getty/langertha/issues

Discord

  https://discord.gg/Y2avVYpquV 🤖

IRC

  irc://irc.perl.org/ai 🤖

=cut

=head1 SUPPORT

=head2 Issues

Please report bugs and feature requests on GitHub at
L<https://github.com/Getty/langertha/issues>.

=head1 CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

=head1 AUTHOR

Torsten Raudssus <torsten@raudssus.de> L<https://raudss.us/>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
