Codestral
Mistral's code-specialized model. Optimized for code generation, completion, and understanding across 80+ languages.
Examples
See what Codestral can generate
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' });
}
};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")?;0.2
// Generated code will appear here...Pricing
API Integration
Use our OpenAI-compatible API to integrate Codestral into your application.
npm install railwailimport 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);Free credits on sign-up
Related Models
View all CodeClaude Code
Anthropic's specialized coding agent. Autonomous code writing, debugging, and refactoring with deep codebase understanding.
Cursor (GPT-4o)
AI-powered code editor backed by GPT-4o. Inline code completion, chat-based editing, and codebase-aware suggestions.
GitHub Copilot
GitHub's AI pair programmer. Real-time code suggestions, chat assistance, and PR reviews powered by OpenAI models.
CodeLlama 70B
Meta's largest code-specialized Llama model. Trained on code-heavy data with strong performance on code generation and infilling.
Start using Codestral today
Get started with free credits. No credit card required. Access Codestral and 100+ other models through a single API.