Bug
Mistral() with no api_key and no MISTRAL_API_KEY env var constructs successfully with api_key=None. No env var lookup happens at init time. Misconfiguration is only discovered when the first API call fails — the opposite of how OpenAI and Anthropic SDKs behave.
Reproduce (mistralai 2.4.5, no API key needed)
import os, inspect
from mistralai.client import Mistral
os.environ.pop('MISTRAL_API_KEY', None)
client = Mistral() # No exception raised
print('Client created with no key') # This prints
sig = inspect.signature(Mistral.__init__)
print(sig.parameters['api_key'].default) # None — no env var fallback
Expected
Check MISTRAL_API_KEY at construction time. Raise ValueError immediately if no key found — matching OpenAI and Anthropic SDK behavior.
Suggested Fix
def __init__(self, api_key=None, ...):
if api_key is None:
api_key = os.environ.get('MISTRAL_API_KEY')
if api_key is None:
raise ValueError(
'No API key provided. Pass api_key=... or set MISTRAL_API_KEY env var.'
)
Happy to open a PR.
— Youssef Ibrahim | github.com/YousefZahran1
Bug
Mistral()with noapi_keyand noMISTRAL_API_KEYenv var constructs successfully withapi_key=None. No env var lookup happens at init time. Misconfiguration is only discovered when the first API call fails — the opposite of how OpenAI and Anthropic SDKs behave.Reproduce (mistralai 2.4.5, no API key needed)
Expected
Check
MISTRAL_API_KEYat construction time. RaiseValueErrorimmediately if no key found — matching OpenAI and Anthropic SDK behavior.Suggested Fix
Happy to open a PR.
— Youssef Ibrahim | github.com/YousefZahran1