Skip to main content

llm-api-adapter-mistral

An optional Mistral organization package for LLM API Adapter, a Python SDK with one shared interface for calling LLM APIs.

Uses the official Mistral API directly.

Installation

Install through the core package extra (recommended):

pip install "llm-api-adapter[mistral]"

Direct installation remains supported when the core package is already managed separately:

pip install llm-api-adapter-mistral

Quick start

import os

from llm_api_adapter.models.messages.chat_message import UserMessage
from llm_api_adapter.universal_adapter import UniversalLLMAPIAdapter

adapter = UniversalLLMAPIAdapter(
    organization="mistral",
    model="mistral-large-4",
    api_key=os.environ["MISTRAL_API_KEY"],
)

response = adapter.chat(messages=[UserMessage("Explain retrieval-augmented generation.")])
print(response.content)

Capabilities

  • Chat, tool calling, structured JSON output, and image input.
  • Synchronous and asynchronous chat and streaming.
  • PDF URLs and bytes through Mistral OCR.
  • Tool loops use explicit message history: append the assistant tool calls and ToolMessage results before the next request. The previous_response parameter is accepted for the shared API contract but is not sent to Mistral, whose Chat Completions API is stateless.

See the main llm-api-adapter README for the shared API contract and examples.

Structured-output portability

The package uses the Core portable profile for json_schema and Pydantic response_model. See the main Structured Output guide for schema validation, parsed results, refusal, and incomplete responses.

Supported models

  • mistral-large-4 (Public Preview)
  • mistral-small-2603
  • mistral-medium-3-5
  • mistral-large-2512
  • glm-5.3-flash through Mistral (zai-glm-5-3-flash on the wire)

For Mistral's native models listed above, the output limit is an upper bound under the shared context budget; Mistral publishes no independent generation maximum.

mistral-large-2512 has no reasoning control: a supplied reasoning_level emits a warning and is not sent to Mistral.

The canonical Mistral registry records capabilities, request rules, limits, and exceptions.

GLM 5.3 Flash through Mistral

Install llm-api-adapter[mistral]; this route needs only MISTRAL_API_KEY:

import os
from llm_api_adapter.universal_adapter import UniversalLLMAPIAdapter
adapter = UniversalLLMAPIAdapter(
    organization="zai",
    service_provider="mistral",
    model="glm-5.3-flash",
    api_key=os.environ["MISTRAL_API_KEY"],
)

Canonical ID glm-5.3-flash maps to Mistral wire ID zai-glm-5-3-flash; no fallback occurs. Without the provider override, organization="zai" selects the independent direct Z.ai route, which still requires the Z.ai package and key. Supports chat(), stream_chat(), achat(), and astream_chat(). Sync uses requests by default; [httpx] with transport="httpx" selects the other sync transport. Install [async] for async; combine extras with pip install "llm-api-adapter[mistral,async,httpx]".

See Capabilities, Structured-output portability, and PDF input for tool calling, images, schemas, and OCR.

max_output_tokens=128000 conservatively interprets Mistral's published “128k”; it is not a measured server maximum. Reasoning accepts low, high, or max (default low); reasoning_level="none" warns and resolves to low. capture_reasoning=True opts in to capture, separate from visible text; missing provider reasoning is not synthesized.

Hosted Flash uses the selected Mistral profile's standard-rate estimates, not direct Z.ai rates; see Automatic cache usage and pricing and PDF input for cost details and boundaries.

PDF input

DocumentPart supports PDF URLs and bytes. The selected Mistral chat model does not receive PDF DocumentPart directly; the package OCRs each PDF first with Mistral OCR 4.1 (mistral-ocr-4-1) and supplies the resulting Markdown to the selected chat model. This creates a separate OCR API request. The adapter reads usage_info.pages_processed from each OCR response and records an ocr page line in ChatResponse.cost_breakdown at the registered standard rate.

For every currently registered Mistral model, PDF URLs and bytes are declared pass exceptions: the OCR adaptation preserves the public PDF contract.

from llm_api_adapter.models.messages.chat_message import UserMessage
from llm_api_adapter.models.messages.file_parts import DocumentPart

# `adapter` is configured as shown in Quick start.
response = adapter.chat(
    messages=[
        UserMessage(
            "Compare these reports.",
            files=[
                DocumentPart(url="https://example.com/report-a.pdf"),
                DocumentPart(url="https://example.com/report-b.pdf"),
            ],
        )
    ]
)

print(response.content)
ocr_line_items = [
    item
    for item in response.cost_breakdown or ()
    if item.operation == "ocr"
]
if ocr_line_items:
    for document_number, item in enumerate(ocr_line_items, start=1):
        print(f"PDF {document_number}: {item.cost} {item.currency}")
    ocr_cost = sum(item.cost for item in ocr_line_items)
    print(f"All PDFs: {ocr_cost} {ocr_line_items[0].currency}")

Each PDF produces an ocr line item. ocr_cost is the OCR-only estimate for all PDFs; response.cost_total, when available, includes both the selected chat model's token cost and OCR cost.

ChatResponse.usage, cost_input, and cost_output remain the selected chat model's token values. cost_total combines those token costs and OCR lines only when token pricing is complete, every OCR response has a valid page count, and the OCR meter uses the same currency. Otherwise known OCR lines remain visible but cost_total is None; page counts are never inferred from Markdown or document bytes. These are standard-rate estimates, not an invoice, and apply consistently to sync, async, and streaming calls.

Automatic cache usage and pricing

usage.prompt_tokens_details.cached_tokens becomes Usage.cached_tokens, a subset of total Usage.input_tokens. Every currently registered Mistral model uses ordinary and cache-read rates from its registry tiers. There is no separately priced automatic cache write, so cache_write_tokens remains None.

An omitted cache-read count leaves cost_input and cost_total unknown; known output and OCR costs can still be exposed. The package accounts for provider-managed automatic reads without enabling opt-in cache modes, TTLs, or storage pricing. Cache hits are provider-reported and not guaranteed. See the shared usage and pricing guide.

Multi-turn requests

Mistral's previous_response parameter is accepted for Core API compatibility but ignored. The package sends no provider continuation ID, so callers supply the message history they want the next request to use. Captured native thinking is not automatically replayed. Leaving out prior messages or thinking may reduce quality on later turns.

Metadata

Release files for llm-api-adapter-mistral 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-api-adapter-mistral 0.1.5
File Size Uploaded Provenance Actions
llm_api_adapter_mistral-0.1.5.tar.gz 45.5 kB Without provenance Details for llm_api_adapter_mistral-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llm-api-adapter-mistral 0.1.5
File Interpreter ABI Platform Actions
llm_api_adapter_mistral-0.1.5-py3-none-any.whl Python 3 none any Details for llm_api_adapter_mistral-0.1.5-py3-none-any.whl

Total release size: 65.9 kB

Release files / llm_api_adapter_mistral-0.1.5.tar.gz

Download URL llm_api_adapter_mistral-0.1.5.tar.gz
Size 45.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fef85ab79c7dcbef88e43f6afd9e98c205da373014cea7d3ad210d36ee2c260d
BLAKE2b-256 checksum
How to use checksums
de74ff191533c89f6f89cef7691f291be21702a42bc3ba0a615967adefb4c84c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / llm_api_adapter_mistral-0.1.5-py3-none-any.whl

Download URL llm_api_adapter_mistral-0.1.5-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1999128537bd769522d82a7d8013d17032aa397ff4d4c29d5b9f00d4b68f7a3e
BLAKE2b-256 checksum
How to use checksums
467b25183aaa003b6837afe83c2fddb83c81a17f91173358cfafa5ffa0a62b61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for llm-api-adapter-mistral 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page