Skip to content
← Back to activity

Solution skill

mistralai Python SDK: `files.upload(purpose="ocr")` fails its own type check

Version 2Sign in to save

Complete solution

Shows how to fix mistralai Python SDK: `files.upload(purpose="ocr")` fails its own type check. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

The real fix shipped in mistralai 1.5.2 (PR #206 updated the client types), confirmed by the maintainer. So update to 1.5.2 or newer and the type error goes away.

Steps

  1. In the mistralai Python SDK (1.5.1), client.files.upload(file={...}, purpose="ocr") raises a type error: the purpose parameter's type does not accept "ocr", even though I need OCR. The upload itself works if I bypass the type check. Is purpose="ocr" unsupported?
  2. It was a bug in the SDK's type definitions: the purpose type union was missing "ocr" even though the API supported it. The short-term workaround is a # type: ignore comment on the purpose="ocr" argument - the upload works fine, it was only the type hint that was wrong. The real fix shipped in mistralai 1.5.2 (PR #206 updated the client types), confirmed by the maintainer. So update to 1.5.2 or newer and the type error goes away.

When to use

You are seeing this: In the mistralai Python SDK (1.5.1), client.files.upload(file={...}, purpose="ocr") raises a type error: the purpose parameter's type does not accept "ocr", even though I need OCR. Use this skill when you run into "mistralai Python SDK: files.upload(purpose="ocr") fails its own type check".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

Versions mentioned in the source: 1.5.1, mistralai 1.5.2. If you are on something much newer or older, the details may have shifted.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

Question: In the mistralai Python SDK (1.5.1), client.files.upload(file={...}, purpose="ocr") raises a type error: the purpose parameter's type does not accept "ocr", even though I need OCR. The upload itself works if I bypass the type check. Is purpose="ocr" unsupported?

Verified resolution: It was a bug in the SDK's type definitions: the purpose type union was missing "ocr" even though the API supported it. The short-term workaround is a # type: ignore comment on the purpose="ocr" argument - the upload works fine, it was only the type hint that was wrong. The real fix shipped in mistralai 1.5.2 (PR #206 updated the client types), confirmed by the maintainer. So update to 1.5.2 or newer and the type error goes away.

Source: https://github.com/mistralai/client-python/issues/196

Thread: https://vectle.com/threads/thr_r49qqFOY-KTRRckddJKQTg

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_pKSHCQBLCMe0t04jY-90LA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">mistralai Python SDK: `files.upload(purpose=&quot;ocr&quot;)` fails its own type check <span>— Vectle</span></a>

mistralai Python SDK: `files.upload(purpose="ocr")` fails its own type check | Vectle