NAME

Langertha::Engine::Mistral - Mistral API

VERSION

version 0.503

SYNOPSIS

use Langertha::Engine::Mistral;

my $mistral = Langertha::Engine::Mistral->new(
    api_key      => $ENV{MISTRAL_API_KEY},
    model        => 'mistral-large-latest',
    system_prompt => 'You are a helpful assistant',
    temperature  => 0.5,
);

print $mistral->simple_chat('Say something nice');

my $vector = $mistral->simple_embedding($content);
# async: await $mistral->simple_embedding_f($content)

# Voxtral transcription
my $text = $mistral->simple_transcription('/path/to/audio.mp3');
my $result = $mistral->simple_transcription_result('/path/to/audio.mp3',
    timestamp_granularities => ['segment'],
    diarize                 => 'true',
    context_bias            => [qw( Langertha Voxtral )],
);
print "$_->{speaker_id}: $_->{text}\n" for @{ $result->{segments} };
# async: await $mistral->simple_transcription_f(...)

DESCRIPTION

Provides access to Mistral AI's models via their API. Composes Langertha::Role::OpenAICompatible with Mistral's endpoint (https://api.mistral.ai) and its OpenAPI spec.

Popular models: mistral-small-latest (default, fast), mistral-large-latest (most capable, 675B parameters), codestral-latest (code generation), devstral-latest (development workflows), pixtral-large-latest (vision). Supports chat, embeddings (default embedding model mistral-embed), tool calling, and audio transcription with Voxtral: /v1/audio/transcriptions, default model voxtral-mini-latest, see "transcription_request". The audio is given as for every engine: a path, \$bytes or a filehandle (see "transcription_file_part" in Langertha::Role::Transcription).

"embedding_dimensions" in Langertha::Role::Embedding is sent as Mistral's output_dimension (not dimensions, which the embeddings endpoint rejects) for codestral-embed* models, the only ones Mistral documents it for. With any other embedding model, mistral-embed (fixed 1024) included, it is not sent and carps once.

Dynamic model listing via list_models(). Get your API key at https://docs.mistral.ai/getting-started/quickstart/ and set LANGERTHA_MISTRAL_API_KEY.

THIS API IS WORK IN PROGRESS

transcription_request

my $request = $mistral->transcription_request($audio,
    timestamp_granularities => ['segment'],
    diarize                 => 'true',
    context_bias            => [qw( Langertha Voxtral )],
);

Builds the Voxtral transcription request: POST /v1/audio/transcriptions as multipart/form-data, with transcription_model (default: voxtral-mini-latest). filename in %extra names the upload; the other pairs are sent as form fields:

  • timestamp_granularities - segment and/or word; the segments of the answer then carry start and end. Mistral does not accept it together with language.

  • diarize - 'true' labels each segment with a speaker_id. Form fields are text, so pass the string rather than a JSON boolean object.

  • context_bias - words or names the model should favour, each without commas or whitespace.

  • language, temperature.

timestamp_granularities and context_bias take an ArrayRef and send one part per element under the plain name, without [], which is how Mistral reads a list field (see the repeated marker of "generate_multipart_body" in Langertha::Role::HTTP); the [] spelling (timestamp_granularities[]) is accepted and sent the same way. Get the whole answer (text, language, segments, usage) with "simple_transcription_result" in Langertha::Role::Transcription, or the text alone with "simple_transcription" in Langertha::Role::Transcription; both have _f variants.

SEE ALSO

SUPPORT

Issues

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

IRC

Join #langertha on irc.perl.org or message Getty directly.

CONTRIBUTING

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

AUTHOR

Torsten Raudssus <getty@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus https://raudssus.de/.

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