{"record":{"id":"92df7ced0192f71f","repo":"microsoft/autogen","slug":"missing-mistral-api-key-environment-variable","errorCode":null,"errorMessage":"Missing MISTRAL_API_KEY environment variable","messagePattern":"Missing MISTRAL_API_KEY environment variable","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"dotnet/samples/AgentChat/AutoGen.Basic.Sample/CodeSnippet/MistralAICodeSnippet.cs","lineNumber":29,"sourceCode":"namespace AutoGen.Basic.Sample.CodeSnippet;\n\n#region weather_function\npublic partial class MistralAgentFunction\n{\n    [Function]\n    public async Task<string> GetWeather(string location)\n    {\n        return \"The weather in \" + location + \" is sunny.\";\n    }\n}\n#endregion weather_function\n\ninternal class MistralAICodeSnippet\n{\n    public async Task CreateMistralAIClientAsync()\n    {\n        #region create_mistral_agent\n        var apiKey = Environment.GetEnvironmentVariable(\"MISTRAL_API_KEY\") ?? throw new Exception(\"Missing MISTRAL_API_KEY environment variable\");\n        var client = new MistralClient(apiKey: apiKey);\n        var agent = new MistralClientAgent(\n            client: client,\n            name: \"MistralAI\",\n            model: MistralAIModelID.OPEN_MISTRAL_7B)\n            .RegisterMessageConnector(); // support more AutoGen built-in message types.\n\n        await agent.SendAsync(\"Hello, how are you?\");\n        #endregion create_mistral_agent\n\n        #region streaming_chat\n        var reply = agent.GenerateStreamingReplyAsync(\n            messages: [new TextMessage(Role.User, \"Hello, how are you?\")]\n        );\n\n        await foreach (var message in reply)\n        {\n            if (message is TextMessageUpdate textMessageUpdate && textMessageUpdate.Content is string content)","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/samples/AgentChat/AutoGen.Basic.Sample/CodeSnippet/MistralAICodeSnippet.cs#L11-L47","documentation":"Guard in MistralAICodeSnippet.CreateMistralAIClientAsync: MISTRAL_API_KEY is null, so the snippet throws before constructing MistralClient. Required for the basic Mistral agent example (OPEN_MISTRAL_7B).","triggerScenarios":"Running the Mistral sample without MISTRAL_API_KEY in the environment.","commonSituations":"Developer configured OpenAI/Anthropic keys but not Mistral; key from console.mistral.ai not exported; CI secret missing.","solutions":["export MISTRAL_API_KEY=<key from console.mistral.ai> before dotnet run.","Add it to launchSettings.json or the CI secret store under the exact name MISTRAL_API_KEY.","Confirm the account has access to the OPEN_MISTRAL_7B model used in the snippet.","Restart the terminal/IDE after setting the variable."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(\"MISTRAL_API_KEY\")))\n{\n    Console.Error.WriteLine(\"Missing MISTRAL_API_KEY environment variable\");\n    return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Export MISTRAL_API_KEY (from console.mistral.ai) before running Mistral samples.","Add the variable to CI secrets and launchSettings.json.","Use one RequireEnv helper for all provider keys."],"tags":["environment","api-key","dotnet","sample","mistral"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}