Using Mistral Codestral for Free

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:

  1. Create an account on the Mistral platform;
  2. Accept the terms of use;
  3. 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:

  1. Access its settings (the classic gear icon);
  2. 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! šŸš€

Built with Hugo
Theme Stack designed by Jimmy