Skip to content

Mistral Ai

Mistral AI is a hosted service that offers an OpenAI-compatible API.

Mistral has a dedicated provider (MistralProvider) in src/providers/mistral.ts that extends the OpenAI provider with two key behaviors:

  • Tool calls: Uses tool_choice: "any" to reliably trigger tool/MCP calls, then automatically switches to "auto" once tool results are present so Mistral returns a text response instead of looping indefinitely.
  • Embeddings: Routes mistral-embed through the OpenAI-compatible embeddings endpoint — no extra configuration needed.

Use provider = "mistral" to enable these behaviors.

local mistral_key = "your-mistral-api-key-here"

config.set {
  ai = {
    providers = {
      mistral = {
        provider = "mistral",  -- Use "mistral" for correct tool_choice behavior
        apiKey = mistral_key,
        baseUrl = "https://api.mistral.ai/v1",
        preferredModels = {"mistral-large-latest", "mistral-medium"}
      }
    },
    -- Optional: auto-select a default model on startup
    defaultTextModel = "mistral:mistral-large-latest"
  }
}

With this configuration:

  • Run "AI: Select Text Model" to see all available Mistral models
  • "AI: Refresh Model List" updates the cached model list
  • preferredModels appear first in the picker (marked with ★)

Legacy Configuration

Deprecated

The textModels array configuration is deprecated. Please migrate to the providers config above.

config.set {
  ai = {
    keys = {
      MISTRAL_API_KEY = "your-mistral-api-key-here"
    },
    textModels = {
      {
        name = "mistral-medium",
        modelName = "mistral-medium",
        provider = "mistral",  -- Use "mistral", not "openai", to get correct tool_choice behavior
        baseUrl = "https://api.mistral.ai/v1",
        secretName = "MISTRAL_API_KEY"
      }
    }
  }
}

Embedding Configuration

Mistral embeddings use the mistral-embed model, which is OpenAI-compatible. Set provider = "mistral" and specify the embedding model:

config.set {
  ai = {
    providers = {
      mistral = {
        provider = "mistral",
        apiKey = mistral_key,
        baseUrl = "https://api.mistral.ai/v1",
      }
    },
    defaultTextModel = "mistral:mistral-large-latest",
    defaultEmbeddingModel = "mistral:mistral-embed"
  }
}

Provider Options

Option Description
provider Use "mistral" (recommended) or "openai". Using "mistral" enables correct tool_choice behavior and embedding support.
apiKey Your Mistral API key
baseUrl Must be "https://api.mistral.ai/v1"
preferredModels Array of model names to show first in the picker

See Mistral AI Documentation for available models.