# Mistral Codestral

Mistral's purpose-built coding model for instruction-driven code generation, fill-in-the-middle completion, and test and documentation authoring across more than 80 languages.

- **Model ID:** `mistral/codestral`
- **Type:** chat
- **Providers:** mistral
- **Context window:** 128,000
- **Maximum output tokens:** 4,000
- **Pricing:** $0.3/1M input tokens, $0.9/1M output tokens
- **Canonical page:** https://vercel.com/ai-gateway/models/codestral

## Supported parameters

Detailed capability metadata has not been reported for this model.

## Example

```ts
import { streamText } from 'ai'

const result = streamText({
  model: 'mistral/codestral',
  prompt: 'Why is the sky blue?'
})
```

## About

Announced May 29, 2024, Mistral Codestral was the first model Mistral dedicated entirely to code. With 22 billion parameters and training across more than 80 programming languages, including Python, Java, C, C++, JavaScript, Bash, Swift, and Fortran, Mistral Codestral covers the breadth of languages developers encounter in production.

Mistral Codestral's defining technical feature is fill-in-the-middle (FIM) support. Unlike instruction-only models that generate code from a prompt, FIM lets Mistral Codestral complete code within a partial snippet. Mistral Codestral can insert a function body, finish a conditional branch, or complete a class method given the surrounding context. This makes Mistral Codestral a natural fit for IDE integrations like Continue.dev and Tabnine, where code above and below the cursor is provided as context.

Beyond completion, Mistral Codestral handles test generation and documentation authoring. Its context window of 128K tokens was over four times larger than those of competing models at launch, so Mistral Codestral can process full files rather than truncated snippets.

## What to consider

Mistral Codestral's context window of 128K tokens was over four times larger than the 4K to 16K windows typical of competing code models at release. You can reason over entire files or multi-file snippets in a single request.

## When to use

### Best For

- IDE and editor plugins requiring fill-in-the-middle code completion
- Automated test generation from existing source code
- Documentation generation for functions, classes, and modules
- Code translation between languages (e.g., Python to TypeScript)
- Applications that need broad language coverage in a single model

### Consider Alternatives When

- You need agentic software engineering with multi-file orchestration (consider Devstral)
- Your primary requirement is semantic code search rather than generation (consider Codestral Embed)
- You need reasoning-heavy problem solving alongside coding (consider Magistral)

## Best for

- **IDE and editor plugins:** Requiring fill-in-the-middle code completion
- **Automated test generation:** Producing unit or integration tests from existing source code
- **Documentation generation:** Writing inline docs and reference material for functions, classes, and modules
- **Code translation between languages:** Converting source across languages, for example Python to TypeScript
- **Broad language coverage:** Applications that need wide support in a single model

## Consider alternatives

- **Agentic software engineering:** You need multi-file orchestration (consider Devstral)
- **Semantic code search:** Your primary requirement is search rather than generation (consider Codestral Embed)
- **Reasoning-heavy problem solving:** You need deep reasoning alongside coding (consider Magistral)

## Frequently asked questions

### What is fill-in-the-middle (FIM) and how does Mistral Codestral use it?

FIM allows Mistral Codestral to complete code given both a prefix (code before the cursor) and a suffix (code after the cursor). Mistral Codestral uses this to insert completions inside partial functions or expressions, which is the dominant pattern in IDE plugins.

### How many programming languages does Mistral Codestral support?

Mistral Codestral was trained on over 80 programming languages. Benchmarked languages include Python, C++, Bash, Java, PHP, TypeScript, C#, SQL, Swift, and Fortran.

### What is Mistral Codestral's context window?

128K tokens. At launch this was over four times larger than the 4K to 16K windows typical of competing code models.

### Can Mistral Codestral write unit tests?

Yes. Test generation is an explicit use case in Mistral's documentation for Mistral Codestral alongside code completion and documentation authoring.

### Is Mistral Codestral available as an open-weight model?

Yes. Weights are available on HuggingFace under the Mistral Non-Production License (MNPL). Commercial API access is available through La Plateforme and AI Gateway.

### How does Mistral Codestral integrate with IDEs?

Mistral Codestral integrates with Continue.dev and Tabnine plugins for VS Code and JetBrains, using the FIM API for in-editor completions.

### How is Mistral Codestral different from Devstral?

Mistral Codestral is a code generation and completion model focused on individual file-level tasks. Devstral is an agentic model designed to navigate entire codebases, resolve GitHub issues, and orchestrate multi-file changes autonomously.

## Links

- [Model page](https://vercel.com/ai-gateway/models/codestral)
- [AI Gateway documentation](https://vercel.com/docs/ai-gateway)
- [Provider model documentation](https://mistral.ai/technology/)
- [Provider pricing](https://docs.mistral.ai/platform/pricing/)
