Packages
Mistral Provider
Public exports from @anvia/mistral.
Import from @anvia/mistral.
MistralClient
type MistralClientOptions = {
apiKey?: string;
serverURL?: string;
client?: Mistral;
};
class MistralClient {
readonly client: Mistral;
constructor(options?: MistralClientOptions);
listModels(): Promise<ModelList>;
completionModel(model?: MistralCompletionModelName): MistralCompletionModel;
embeddingModel(
model?: MistralEmbeddingModelName,
options?: MistralEmbeddingModelOptions,
): MistralEmbeddingModel;
ocrModel(model?: MistralOcrModelName): MistralOcrModel;
}
Purpose: factory for Mistral completion, embedding, OCR, and model listing.
Return behavior: creates or uses a Mistral SDK client, then returns normalized Anvia model adapters. listModels() fetches Mistral’s model list and returns a normalized ModelList.
Notable errors: constructor throws when neither client nor apiKey is supplied; listModels() rejects with ModelListingError when the provider request fails.
Model Name Types
type MistralCompletionModelName = ModelId<KnownMistralCompletionModelName>;
type MistralEmbeddingModelName = ModelId<KnownMistralEmbeddingModelName>;
type MistralOcrModelName = ModelId<KnownMistralOcrModelName>;
Known model unions: KnownMistralCompletionModelName, KnownMistralEmbeddingModelName, and KnownMistralOcrModelName.
Purpose: typed model identifiers for autocomplete while preserving support for custom strings.
MistralCompletionModel
class MistralCompletionModel implements StreamingCompletionModel {
constructor(client: Mistral, defaultModel?: MistralCompletionModelName);
completion(request: CompletionRequest): Promise<CompletionResponse>;
streamCompletion(request: CompletionRequest): AsyncIterable<CompletionStreamEvent>;
}
Purpose: adapter for Mistral chat completions.
Return behavior: returns normalized completion responses and stream events.
Notable errors: rejects unsupported image inputs and document file inputs before provider calls; rejects or yields Mistral SDK/provider errors for transport failures.
MistralEmbeddingModel
type MistralEmbeddingModelOptions = {
dimensions?: number;
maxBatchSize?: number;
};
class MistralEmbeddingModel implements EmbeddingModel {
readonly dimensions?: number;
readonly maxBatchSize: number;
constructor(
client: Mistral,
model: MistralEmbeddingModelName,
options?: MistralEmbeddingModelOptions,
);
embedTexts(texts: string[]): Promise<Embedding[]>;
}
Purpose: Mistral embedding adapter.
Return behavior: returns one Embedding per input text.
Notable errors: rejects on Mistral SDK errors or mismatched embedding counts.
MistralOcrModel
const MISTRAL_OCR_LATEST = "mistral-ocr-latest";
type MistralOcrRequest = {
source: MistralOcrSource;
};
type MistralOcrSource =
| { type: "document_url"; url: string; documentName?: string }
| { type: "image_url"; url: string }
| { type: "file_id"; fileId: string }
| {
type: "bytes";
data: Uint8Array | ArrayBuffer;
filename: string;
expiry?: number | null;
visibility?: "workspace" | "user";
};
type MistralOcrPage = {
index: number;
markdown: string;
images: unknown[];
tables?: unknown[];
hyperlinks?: string[];
header?: string | null;
footer?: string | null;
dimensions?: unknown;
confidenceScores?: unknown;
};
type MistralOcrUploadedFile = {
id: string;
filename?: string;
sizeBytes?: number;
purpose?: string;
rawResponse: unknown;
};
class MistralOcrModel {
constructor(client: Mistral, defaultModel?: MistralOcrModelName);
ocr(request: MistralOcrRequest): Promise<MistralOcrResponse>;
}
Purpose: adapter for Mistral OCR document processing.
Return behavior: returns combined markdown/text, normalized page entries, upload metadata for byte sources, and the raw Mistral OCR response.
Notable errors: rejects empty byte sources before upload; rejects or yields Mistral SDK/provider errors for upload and OCR failures.
mistral Namespace
namespace mistral {
MistralClient;
MistralCompletionModel;
MistralEmbeddingModel;
MistralOcrModel;
MISTRAL_OCR_LATEST;
toMistralChatParams;
fromMistralChatResponse;
fromMistralChatStreamChunk;
mistralMessageHelpers;
}
Purpose: namespaced access to the same public Mistral exports.
Return behavior: export namespace only.
Notable errors: none directly.
Mapping Helpers
function toMistralChatParams(defaultModel: string, request: CompletionRequest): unknown;
function fromMistralChatResponse(response: unknown): CompletionResponse;
function fromMistralChatStreamChunk(chunk: unknown): CompletionStreamEvent[];
const mistralMessageHelpers: {
messageToMistralMessages(message: Message): unknown[];
toolDefinitionToMistral(tool: ToolDefinition): unknown;
};
Purpose: low-level request and response mappers used by MistralCompletionModel.
Return behavior: exported for tests, custom adapters, and compatibility layers that need the same normalized mapping.
Notable errors: malformed provider payloads can produce empty normalized content or throw while parsing tool arguments.
