{"record":{"id":"7d3bef588e7ef010","repo":"microsoft/semantic-kernel","slug":"the-thread-could-not-be-created-due-to-an-error-re","errorCode":null,"errorMessage":"The thread could not be created due to an error response from the service.","messagePattern":"The thread could not be created due to an error response from the service\\.","errorType":"exception","errorClass":"AgentThreadOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/AzureAI/AzureAIAgentThread.cs","lineNumber":90,"sourceCode":"    }\n\n    /// <inheritdoc />\n    protected override async Task<string?> CreateInternalAsync(CancellationToken cancellationToken)\n    {\n        const string ErrorMessage = \"The thread could not be created due to an error response from the service.\";\n\n        try\n        {\n            var agentThreadResponse = await this._client.Threads.CreateThreadAsync(\n                this._messages,\n                this._toolResources,\n                this._metadata,\n                cancellationToken: cancellationToken).ConfigureAwait(false);\n            return agentThreadResponse.Value.Id;\n        }\n        catch (RequestFailedException ex)\n        {\n            throw new AgentThreadOperationException(ErrorMessage, ex);\n        }\n        catch (AggregateException ex)\n        {\n            throw new AgentThreadOperationException(ErrorMessage, ex);\n        }\n    }\n\n    /// <inheritdoc />\n    protected override async Task DeleteInternalAsync(CancellationToken cancellationToken)\n    {\n        const string ErrorMessage = \"The thread could not be deleted due to an error response from the service.\";\n\n        try\n        {\n            await this._client.Threads.DeleteThreadAsync(this.Id, cancellationToken).ConfigureAwait(false);\n        }\n        catch (RequestFailedException ex) when (ex.Status == 404)\n        {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/AzureAI/AzureAIAgentThread.cs#L72-L108","documentation":"Thrown by AzureAIAgentThread.CreateInternalAsync when the Azure AI Agents service returns a RequestFailedException during thread creation (CreateThreadAsync). The original Azure SDK exception is wrapped in an AgentThreadOperationException (which inherits from KernelException) with a standard message. The inner exception contains the HTTP status code, error details, and request ID from the service.","triggerScenarios":"CreateThreadAsync on the PersistentAgentsClient fails with a RequestFailedException — causes include authentication failures (401/403), invalid endpoint configuration, quota/rate-limit exceeded (429), service errors (5xx), or malformed tool resources. The catch block for RequestFailedException fires for all non-404 service errors during thread creation.","commonSituations":"Expired or invalid API keys / Azure AD tokens. Wrong Azure AI endpoint. Exceeded thread creation quotas. Network connectivity issues to Azure. Malformed ToolResources or ThreadMessageOptions passed to the AzureAIAgentThread constructor. Azure service transient outages.","solutions":["Inspect ex.InnerException (the RequestFailedException) for the HTTP status code and service error message.","Verify the PersistentAgentsClient is configured with a valid endpoint and credentials.","For 429 (rate limit), implement exponential backoff retry around CreateAsync.","For 401/403, refresh credentials or check API key/Azure AD token validity.","Validate that ToolResources and messages passed to the thread constructor are well-formed."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    await thread.CreateAsync(ct);\n}\ncatch (AgentThreadOperationException ex) when (ex.InnerException is RequestFailedException rfe)\n{\n    _logger.LogError(\"Thread creation failed: {Status} {Error}\", rfe.Status, rfe.Message);\n    if (rfe.Status == 429) { /* retry with backoff */ }\n    else throw;\n}","preventionTips":["Validate endpoint and credentials before creating threads.","Monitor for 429 responses and implement exponential backoff.","Log the RequestFailedException status code and RequestId for Azure support escalation."],"tags":["azureai-thread","network","service-error","agentthreadoperationexception"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}