MistralSubscriptionRequiredError
mistral.errors.MistralSubscriptionRequiredError
Stack trace
mistral.errors.MistralSubscriptionRequiredError: Subscription required to access model 'mistral-7b-v0.1'. Please upgrade your plan or check your API key permissions.
Why it happens
Mistral restricts access to certain models based on subscription tiers. When you attempt to use a model without the necessary subscription or permissions, the SDK raises this error to prevent unauthorized usage.
Detection
Monitor API responses for HTTP 401 errors with messages indicating subscription or access issues; log these errors immediately to identify missing subscription access.
Causes & fixes
Using an API key without the required subscription tier for the requested Mistral model
Upgrade your Mistral subscription plan to include access to the desired model or use an API key associated with an authorized subscription.
Incorrect or expired API key that lacks proper permissions
Verify your API key is current and correctly set in your environment variables; regenerate the key if necessary.
Requesting a model name that is misspelled or not available under your subscription
Double-check the model name for typos and confirm it is included in your subscription plan.
Code: broken vs fixed
import os
from mistral import Mistral
client = Mistral(api_key=os.environ['MISTRAL_API_KEY'])
# This line triggers the subscription error
response = client.chat.completions.create(model='mistral-7b-v0.1', messages=[{'role': 'user', 'content': 'Hello'}]) import os
from mistral import Mistral
client = Mistral(api_key=os.environ['MISTRAL_API_KEY']) # Ensure API key has subscription access
response = client.chat.completions.create(model='mistral-7b-v0.1', messages=[{'role': 'user', 'content': 'Hello'}])
print(response.choices[0].message.content) # Works if subscription is valid Workaround
Catch the MistralSubscriptionRequiredError exception and prompt the user to update their subscription or switch to a model accessible with their current plan.
Prevention
Implement subscription checks in your deployment pipeline and use environment variables for API keys tied to authorized subscriptions to avoid unauthorized model access errors.