This project demonstrates how to use Mistral’s Document AI QnA API to extract structured data from uploaded documents — specifically invoices — using Elixir.
It serves as a learning and experimentation project to try out:
- How to interact with Mistral’s Document AI API.
- How to use structured output in chat completions.
- Language: Elixir
~> 1.18 - HTTP client: Req
- AI API: Mistral Document AI QnA
-
File Upload
The document (e.g. an invoice PDF) is first uploaded to Mistral’s AI blob store via their
/filesendpoint.This returns a
document_urlwhich can be referenced later. -
Chat Completion Request
The
document_urlis then passed to thechat/completionsAPI along with a short instruction message and a JSON schema defining the structured response format.Example schema fields:
amount_to_pay_centsinvoice_dateinvoice_numbercurrencyreason_for_paymentissuer
-
Structured Output
The API returns a JSON object matching the schema
- Elixir
~> 1.18 mixtoolchain- A valid Mistral API key
git clone <git@github.com:acramatte/trackit-ocr.git> cd trackit-ocr mix deps.get
Export your API key:
export MISTRAL_API_KEY="your_api_key_here"You can run the module or script directly via iex:
iex -S mixThen call the function passing it the path to the file to upload:
Trackit.processPDF("../2025-11-04_My_Invoice_080000463123.pdf")