Running Intro to Mistral AI locally
Use this page to run the extracted Intro to Mistral AI project on your computer. The project reads its API key the way Scrimba supplies it, so one line changes before it runs in Vite, and the function-calling result then appears in the browser console. The key handling matches Running Chef Claude locally, which solves the same problem for a different provider.
What you need first
Install a supported LTS version of Node.js. Node 24 is recommended and includes npm.
Check that Node and npm are available:
$ node --version
v24.18.0
$ npm --version
11.18.0You also need a Mistral API key. If you do not have one, follow Mistral's Studio key setup, create a key, and copy it when it is shown. You will add it to the local environment file later on this page.
Copy the key as soon as Studio shows it, and keep it somewhere safe until you add it to .env.
Open the project folder
Open a terminal in the extracted folder containing package.json:
$ cd path-to-your-downloaded-projectpackage.json, and run every npm command from there. The .env file you create later belongs in that same folder too. Make the API key work in Vite
The downloaded index.js reads the key with Scrimba's environment syntax:
const client = new MistralClient(process.env.MISTRAL_API_KEY)A stock Vite browser project does not provide that process.env value. Change the line to:
const client = new MistralClient(import.meta.env.VITE_MISTRAL_API_KEY)Create .env beside package.json:
VITE_MISTRAL_API_KEY=your-mistral-api-key-hereCreate .gitignore beside it and add:
.env
node_modules/The VITE_ prefix is required because Vite exposes only specially prefixed environment variables to browser code. Ignoring .env matters because a key added to Git by accident is not removed by deleting the file: the value stays in the repository history. The Git handbook covers the wider habit in ignoring files and good habits.
This key is visible in the browser
The VITE_ prefix deliberately puts the API key into the frontend bundle. Use a temporary, restricted key for local learning only. Never deploy or share this version, and never commit .env. A production application needs a backend or serverless function that keeps the key on the server.
.env, and keep that file out of Git. The browser can still read this key, so use one you are willing to delete afterwards. That exposure is a limit of frontend-only projects, not an error in your setup.
Install and run the project
Install the downloaded dependencies and start Vite:
$ npm install
$ npm startOpen the exact Local URL Vite prints, usually http://localhost:5173/. In the function-calling lesson, open your browser's developer tools and select Console. A returned Mistral response there is the visible success result; the lesson does not render that result on the page.
Restart Vite after changing .env. Stop it with Ctrl+C.
npm install, then npm start, and open the Local URL it prints. Then open the browser Console, because the function-calling lesson prints its answer there. An empty-looking page is the expected result, not a failure.
Troubleshooting
process is not defined: The Scrimba-style environment read remains in index.js. Replace it with the import.meta.env.VITE_MISTRAL_API_KEY form above and restart Vite.
The key is undefined or authentication fails: Confirm the exact VITE_ variable name, make sure .env is beside package.json, and restart the project. Check that the key is still active in your Mistral account.
The model is unavailable or the SDK request fails: The downloaded project pins an older Mistral SDK and asks for mistral-large-latest. Provider SDKs and model catalogs change. Compare the model ID in index.js against the models listed in Mistral's documentation, and change the ID before you change the pinned SDK version, since a renamed model is the more common cause.
Nothing appears on the page: Open the browser console. The function-calling lesson logs its final response there instead of rendering it on the page.
If you want to publish this project: Do not publish this frontend-only version. Move the Mistral call and credential to a backend first.
VITE_ name, where .env sits, the model ID, and the browser Console, then restart. Change one thing at a time. Do not publish this version, however well it runs on your machine.

