{"record":{"id":"dd29926b7e373462","repo":"microsoft/semantic-kernel","slug":"invalid-openai-client-type-connection-type-was","errorCode":null,"errorMessage":"Invalid OpenAI client type '{connection.Type}' was specified.","messagePattern":"Invalid OpenAI client type '(.+?)' was specified\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/OpenAI/Extensions/AgentDefinitionExtensions.cs","lineNumber":158,"sourceCode":"            if (connection.Type.Equals(OpenAI, StringComparison.OrdinalIgnoreCase))\n            {\n                return OpenAIAssistantAgent.CreateOpenAIClient(connection.GetApiKeyCredential(), connection.TryGetEndpoint(), httpClient);\n            }\n            else if (connection.Type.Equals(AzureOpenAI, StringComparison.OrdinalIgnoreCase))\n            {\n                var endpoint = connection.TryGetEndpoint();\n                Verify.NotNull(endpoint, \"Endpoint must be specified when using Azure OpenAI.\");\n\n                if (connection.ExtensionData.TryGetValue(ApiKey, out var apiKey) && apiKey is not null)\n                {\n                    return OpenAIAssistantAgent.CreateAzureOpenAIClient(connection.GetApiKeyCredential(), endpoint, httpClient);\n                }\n\n                var tokenCredential = kernel.Services.GetRequiredService<TokenCredential>();\n                return OpenAIAssistantAgent.CreateAzureOpenAIClient(tokenCredential, endpoint, httpClient);\n            }\n\n            throw new InvalidOperationException($\"Invalid OpenAI client type '{connection.Type}' was specified.\");\n        }\n\n        // Use the client registered on the kernel\n        var client = kernel.GetAllServices<OpenAIClient>().FirstOrDefault();\n        return (OpenAIClient?)client ?? throw new InvalidOperationException(\"OpenAI client not found.\");\n    }\n\n    #region private\n    private const string Temperature = \"temperature\";\n    private const string TopP = \"top_p\";\n\n    private static float? GetTemperature(this AgentDefinition agentDefinition)\n    {\n        Verify.NotNull(agentDefinition);\n\n        if (agentDefinition?.Model?.Options?.TryGetValue(Temperature, out var temperature) ?? false)\n        {\n            return (float?)temperature;","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/OpenAI/Extensions/AgentDefinitionExtensions.cs#L140-L176","documentation":"Thrown by AgentDefinitionExtensions.GetOpenAIClient when the agent definition carries a ModelConnection whose Type is non-null but matches neither the recognized 'openai' nor 'azure_openai' (AzureOpenAI) constants. Only those two connection kinds can be turned into an OpenAIClient, so anything else is rejected.","triggerScenarios":"Calling GetOpenAIClient (directly or via agent invocation from a YAML/JSON AgentDefinition) where Model.Connection.Type is a typo like 'azure', 'open_ai', 'ollama', 'anthropic', or any provider the converter does not construct.","commonSituations":"Misspelled connection type in the agent-definition file; switching providers without updating the type field; leftover type value after renaming; using a self-hosted/local endpoint while the type still names a cloud provider.","solutions":["Set Model.Connection.Type to exactly 'azure_openai' for Azure or 'openai' for the public service (comparison is case-insensitive).","If you do not need a per-agent connection, remove the Model.Connection block so the kernel-resolved OpenAIClient is used instead.","Validate the agent-definition file against the documented schema before passing it to the agent factory.","Log connection.Type at startup to catch typos early in configuration loading."],"exampleFix":"// before\nmodel:\n  connection:\n    type: azure\n// after\nmodel:\n  connection:\n    type: azure_openai","handlingStrategy":"validation","validationCode":"var type = agentDefinition?.Model?.Connection?.Type;\nvar valid = new[] { \"openai\", \"azure_openai\" };\nif (type is not null && !valid.Contains(type, StringComparer.OrdinalIgnoreCase))\n    throw new ArgumentException($\"Unsupported connection type '{type}'. Valid: {string.Join(\", \", valid)}\");","typeGuard":"static bool IsValidConnectionType(string? type) =>\n    type is null || type.Equals(\"openai\", StringComparison.OrdinalIgnoreCase)\n                 || type.Equals(\"azure_openai\", StringComparison.OrdinalIgnoreCase);","tryCatchPattern":"try { var client = agentDefinition.GetOpenAIClient(kernel); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Invalid OpenAI client type\")) {\n    // surface configuration error to the user with valid types\n}","preventionTips":["Validate agent-definition files against a schema at load time.","Centralize connection-type string constants and reference them everywhere.","Add a startup self-check that logs every connection type in use."],"tags":["configuration","openai","agent-definition","invalid-argument"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}