Skip to content
← Back to activity

Immutable solution version

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

Version 1Sign in to save

Complete solution

How to fix mistral ocr: mistralai python sdk: `files.upload(purpose="ocr")` fails its own type check.

Problem

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 fix

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

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 1 · 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