Hello! š
I found a way to use Codestral, Mistral AI’s code-focused model, for free. Let me show you how to set it up with Cline, an AI-powered code generation tool.
What is Codestral? š¤
Codestral is Mistral AI’s first model specifically designed for code generation. It supports over 80 programming languages, ranging from popular ones like Python, Java, and JavaScript to more niche ones like Swift or Fortran.
In practice, it enables you to:
- Complete code functions
- Generate tests
- Fill in partial code using a “fill-in-the-middle” mechanism
The tool that will help us: Cline š ļø
To use Codestral easily, weāll rely on Cline, a VSCode extension that simplifies the process. Itās a comprehensive coding assistant that can (according to the project’s GitHub documentation):
- Intelligently analyze your projects by understanding file structures
- Create and edit files (with your permission, of course)
- Execute commands in the terminal
- Even debug visual issues for web development!
Cline always asks for your permission before making changes unless you allow it to act freely (which I donāt recommend). Personally, Iāve granted it access to read all local files while manually approving code modifications and shell commands (Auto-approve: Read files and directories).
By the way, if you encounter shell integration issues like I did (yes, Cline doesnāt get along well with verbose shells full of emojis like Zsh + Oh-my-zsh ^^), hereās the link to the doc to fix it: shell-integration-problems. I now use a plain Bash shell without any frills.
Step-by-step setup āļø
Although Cline offers direct usage of a Mistral API key, it doesnāt currently work with the Codestral key (hopefully this will be fixed someday). The method relies on liteLLM, which acts as a proxy.
Iāll show you how to set it up for Codestral, but this proxy-based method can be used with any provider supported by LiteLLM, making it useful in many scenarios :).
1. Get a Mistral API key
The first essential step is obtaining a Mistral API key:
- Create an account on the Mistral platform;
- Accept the terms of use;
- Retrieve your API key from the settings (Codestral Menu -> Codestral).
Note that the code you send may be used by Mistralās team (so donāt send anything sensitive or secret!).
2. Install litellm
Start by installing liteLLM, which will serve as our bridge to Codestral:
pip install 'litellm[proxy]'
3. Configure and launch litellm
Once installed:
# Exportez votre clƩ API
export CODESTRAL_API_KEY=[votre_clƩ_API]
# Lancez le serveur
litellm --model codestral/codestral-latest
4. Install and configure Cline in VSCode
Installation
Since itās an extension, simply search for it in the marketplace.
Configuration
Open the Cline extension added to your sidebar and:
- Access its settings (the classic gear icon);
- For the values:
- Provider: “OpenAPI Compatible”
- Base URL:
http://0.0.0.0:4000
- API Key: enter at least one character (itās mandatory but not used)
- Model ID:
codestral-latest
Since Iām not fluent in English, I set Custom Instructions to Speak in French
so I can interact in French.
Click Done to save your settings.
And there you go! š
You now have an AI-powered development environment for free.
Iām still exploring Cline and using it in Act mode (selectable at the bottom right), with permission to read files while manually approving its suggestions.
Iāve been using these tools for a few days now, and I must say Iām quite impressedāitās a real productivity booster. The fact that it’s free and integrates seamlessly with VSCode makes it a very compelling solution for developers; AI is making incredible strides in this field š±!
Happy coding sessions! š