llm-api-adapter-mistral
Official direct-API support for Mistral in llm-api-adapter.
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-2512",
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
ToolMessageresults before the next request.previous_responseis 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
This package requires llm-api-adapter>=0.9.2,<1.0.0 and enforces the same
Core portable JSON Schema profile as OpenAI, Anthropic, Google, and xAI. The
profile guarantees that every object is strict, every property is required,
optional values are nullable, and only direct,
non-recursive local #/$defs/... references are resolved before the request.
Use json_schema for parsed JSON only. Use a Pydantic response_model when
the final result must also be locally validated and returned as
ChatResponse.parsed_model; each nested Pydantic model must use
ConfigDict(extra="forbid"). Refusal and incomplete terminal responses set
ChatResponse.refusal or ChatResponse.incomplete_reason and leave parsed
fields unset. Invalid completed JSON or failed Pydantic validation raises
JSONSchemaError.
The complete schema vocabulary and examples are in the main Structured Output guide.
Supported models
mistral-small-2603mistral-medium-3-5mistral-large-2512
PDF input
DocumentPart supports PDF URLs and bytes. Before the chat request, the
selected Mistral chat model cannot consume DocumentPart directly. The package
therefore sends each PDF to 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.
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 every OCR response has a valid page count and the OCR meter is
available. 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.
Metadata
Release files for llm-api-adapter-mistral 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llm_api_adapter_mistral-0.1.2.tar.gz | 19.7 kB | Without provenance | Details for llm_api_adapter_mistral-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llm_api_adapter_mistral-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for llm_api_adapter_mistral-0.1.2-py3-none-any.whl |
Total release size: 38.1 kB
Release files / llm_api_adapter_mistral-0.1.2.tar.gz
| Download URL | llm_api_adapter_mistral-0.1.2.tar.gz |
|---|---|
| Size | 19.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e27e299e3629fbef98f17a22231064e6ed00093384d142a223f3d237946cdb0f
|
|
BLAKE2b-256 checksum How to use checksums |
e7bea1c2a473970d9fb9ae7a112d88cf955b0d5997ef1448bd759950b207d76f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / llm_api_adapter_mistral-0.1.2-py3-none-any.whl
| Download URL | llm_api_adapter_mistral-0.1.2-py3-none-any.whl |
|---|---|
| Size | 18.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c90d4c0beebac2c6279651d2bdcb8cd3c18b106d7d86f44a48d68b2b376dfff
|
|
BLAKE2b-256 checksum How to use checksums |
9b33606cf09111003388f190b0a9b1968380b4de1e3d2e225b0e89091217515f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for llm-api-adapter-mistral 0.1.2
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.