Codestral

New
Popular
Mistral
Code

Mistral's code-specialized model. Optimized for code generation, completion, and understanding across 80+ languages.

Examples

See what Codestral can generate

TypeScript API Handler

Write a type-safe Express middleware for JWT authentication in TypeScript

import { Request, Response, NextFunction } from 'express';
import jwt from 'jsonwebtoken';

interface JwtPayload {
  userId: string;
  email: string;
  role: 'admin' | 'user';
}

declare global {
  namespace Express {
    interface Request {
      user?: JwtPayload;
    }
  }
}

export const authenticate = (
  req: Request,
  res: Response,
  next: NextFunction
): void => {
  const token = req.headers.authorization?.split(' ')[1];

  if (!token) {
    res.status(401).json({ error: 'No token provided' });
    return;
  }

  try {
    const decoded = jwt.verify(
      token,
      process.env.JWT_SECRET!
    ) as JwtPayload;
    req.user = decoded;
    next();
  } catch (err) {
    res.status(403).json({ error: 'Invalid or expired token' });
  }
};
Rust Error Handling

Write a Rust function that reads a JSON config file and returns a parsed struct with proper error handling

use serde::Deserialize;
use std::fs;
use std::path::Path;
use thiserror::Error;

#[derive(Debug, Deserialize)]
pub struct AppConfig {
    pub host: String,
    pub port: u16,
    pub database_url: String,
    pub max_connections: Option<u32>,
}

#[derive(Error, Debug)]
pub enum ConfigError {
    #[error("Failed to read config file: {0}")]
    IoError(#[from] std::io::Error),
    #[error("Failed to parse config JSON: {0}")]
    ParseError(#[from] serde_json::Error),
    #[error("Config file not found: {0}")]
    NotFound(String),
}

pub fn load_config(path: &str) -> Result<AppConfig, ConfigError> {
    if !Path::new(path).exists() {
        return Err(ConfigError::NotFound(path.to_string()));
    }
    let contents = fs::read_to_string(path)?;
    let config: AppConfig = serde_json::from_str(&contents)?;
    Ok(config)
}

// Usage:
// let config = load_config("config.json")?;
Try Codestral

0.2

// Generated code will appear here...
Sign up free to start generating
Get Started

Pricing

Price per Generation
Per generationFree

API Integration

Use our OpenAI-compatible API to integrate Codestral into your application.

Install
npm install railwail
JavaScript / TypeScript
import railwail from "railwail";

const rw = railwail("YOUR_API_KEY");

// Simple — just pass a string
const reply = await rw.run("codestral", "Hello! What can you do?");
console.log(reply);

// With message history
const reply2 = await rw.run("codestral", [
  { role: "system", content: "You are a helpful assistant." },
  { role: "user", content: "Explain quantum computing simply." },
]);
console.log(reply2);

// Full response with usage info
const res = await rw.chat("codestral", [
  { role: "user", content: "Hello!" },
], { temperature: 0.7, max_tokens: 500 });
console.log(res.choices[0].message.content);
console.log(res.usage);
Specifications
Context window
256,000 tokens
Max output
8,192 tokens
Avg. latency
1.5s
Provider
Mistral
Category
Code
Tags
coding
fast
multilanguage
Try this model

Free credits on sign-up

Start using Codestral today

Get started with free credits. No credit card required. Access Codestral and 100+ other models through a single API.