{"record":{"id":"cec7c1c216962458","repo":"microsoft/autogen","slug":"azure-openai-api-key-is-not-set","errorCode":null,"errorMessage":"AZURE_OPENAI_API_KEY is not set","messagePattern":"AZURE_OPENAI_API_KEY is not set","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/AgentChat/AutoGen.Basic.Sample/CodeSnippet/FunctionCallCodeSnippet.cs","lineNumber":120,"sourceCode":"    {\n        IAgent agent = default;\n        #region register_function_call_middleware\n        var function = new TypeSafeFunctionCall();\n        var functionCallMiddleware = new FunctionCallMiddleware(\n            functions: new[] { function.WeatherReportFunctionContract },\n            functionMap: new Dictionary<string, Func<string, Task<string>>>\n            {\n                { function.WeatherReportFunctionContract.Name, function.WeatherReportWrapper },\n            });\n\n        agent = agent!.RegisterMiddleware(functionCallMiddleware);\n        var reply = await agent.SendAsync(\"What's the weather in Seattle today? today is 2024-01-01\");\n        #endregion register_function_call_middleware\n    }\n\n    public async Task TwoAgentWeatherChatTestAsync()\n    {\n        var key = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_API_KEY\") ?? throw new ArgumentException(\"AZURE_OPENAI_API_KEY is not set\");\n        var endpoint = Environment.GetEnvironmentVariable(\"AZURE_OPENAI_ENDPOINT\") ?? throw new ArgumentException(\"AZURE_OPENAI_ENDPOINT is not set\");\n        var deploymentName = \"gpt-35-turbo-16k\";\n        var config = new AzureOpenAIConfig(endpoint, deploymentName, key);\n        #region two_agent_weather_chat\n        var function = new TypeSafeFunctionCall();\n        var assistant = new AssistantAgent(\n            \"assistant\",\n            llmConfig: new ConversableAgentConfig\n            {\n                ConfigList = new[] { config },\n                FunctionContracts = new[]\n                {\n                    function.WeatherReportFunctionContract,\n                },\n            });\n\n        var user = new UserProxyAgent(\n            name: \"user\",","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/samples/AgentChat/AutoGen.Basic.Sample/CodeSnippet/FunctionCallCodeSnippet.cs#L102-L138","documentation":"ArgumentException thrown in FunctionCallCodeSnippet.TwoAgentWeatherChatTestAsync when AZURE_OPENAI_API_KEY is null. This sample uses Azure OpenAI, which requires both an endpoint and a key; the key is checked first (an identical check for AZURE_OPENAI_ENDPOINT follows on the next line).","triggerScenarios":"Running the two-agent weather chat sample without AZURE_OPENAI_API_KEY set; note the Azure key is NOT the same as OPENAI_API_KEY — having only the OpenAI key set still triggers it.","commonSituations":"Developer set OPENAI_API_KEY but this snippet needs Azure credentials; Azure key stored in appsettings/user-secrets instead of environment; CI secret named differently (e.g. AZURE_OPENAI_KEY).","solutions":["Set AZURE_OPENAI_API_KEY (from Azure Portal > your Azure OpenAI resource > Keys and Endpoint).","Also set AZURE_OPENAI_ENDPOINT (https://<resource>.openai.azure.com/) — the very next line throws without it.","Verify the deployment name gpt-35-turbo-16k exists on that resource, since AzureOpenAIConfig needs a valid deployment.","Confirm the variable names exactly match, including the AZURE_ prefix."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"string[] required = [\"AZURE_OPENAI_API_KEY\", \"AZURE_OPENAI_ENDPOINT\"];\nvar missing = required.Where(v => string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(v))).ToArray();\nif (missing.Length > 0) throw new ArgumentException($\"Missing: {string.Join(\", \", missing)}\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember Azure samples need AZURE_* variables, not OPENAI_API_KEY.","Set both the key and endpoint together — both are checked.","Confirm the deployment name exists on the Azure resource before running."],"tags":["environment","api-key","dotnet","sample","azure-openai"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}