microsoft/semantic-kernel · error · AgentThreadOperationException
The thread could not be created due to an error response fro
Error message
The thread could not be created due to an error response from the service.
What it means
OpenAIAssistantAgentThread.CreateInternalAsync wraps the service CreateThreadAsync call. If it throws ClientResultException (an HTTP/service error from the OpenAI backend), it is rewrapped as AgentThreadOperationException with a fixed message, preserving the original as the inner exception.
Source
Thrown at dotnet/src/Agents/OpenAI/OpenAIAssistantAgentThread.cs:121
/// <inheritdoc />
protected override async Task<string?> CreateInternalAsync(CancellationToken cancellationToken)
{
const string ErrorMessage = "The thread could not be created due to an error response from the service.";
try
{
if (this._useThreadConstructorExtension)
{
return await this._client.CreateThreadAsync(this._messages, this._codeInterpreterFileIds, this._vectorStoreId, this._metadata, cancellationToken: cancellationToken).ConfigureAwait(false);
}
var assistantThreadResponse = await this._client.CreateThreadAsync(this._options, cancellationToken: cancellationToken).ConfigureAwait(false);
return assistantThreadResponse.Value.Id;
}
catch (ClientResultException ex)
{
throw new AgentThreadOperationException(ErrorMessage, ex);
}
catch (AggregateException ex)
{
throw new AgentThreadOperationException(ErrorMessage, ex);
}
}
/// <inheritdoc />
protected override async Task DeleteInternalAsync(CancellationToken cancellationToken)
{
const string ErrorMessage = "The thread could not be deleted due to an error response from the service.";
try
{
await this._client.DeleteThreadAsync(this.Id, cancellationToken).ConfigureAwait(false);
}
catch (ClientResultException ex) when (ex.Status == 404)
{View on GitHub (pinned to c028a0c7dc)
Solutions
- Catch AgentThreadOperationException and inspect ex.InnerException (ClientResultException) for Status and raw message.
- Verify API key/endpoint and the thread options/metadata being sent.
- Retry with backoff for 429/5xx statuses.
- Ensure the thread options (messages, tool resources) conform to the API schema.
Example fix
// before
await thread.CreateAsync();
// after
try { await thread.CreateAsync(); }
catch (AgentThreadOperationException ex) when (ex.InnerException is ClientResultException cre) {
logger.LogError(cre, "Thread create failed (HTTP {Status})", cre.Status);
} Defensive patterns
Strategy: try-catch
Try / catch
try { await thread.CreateAsync(); }
catch (AgentThreadOperationException ex) when (ex.InnerException is ClientResultException cre) {
logger.LogError(cre, "Create thread failed (HTTP {Status})", cre.Status);
if (cre.Status == 429 || cre.Status >= 500) await RetryAsync(() => thread.CreateAsync());
} Prevention
- Verify credentials and endpoint before creating threads.
- Validate thread options/metadata against the API schema.
- Retry 429/5xx with exponential backoff.
When it happens
Trigger: The OpenAI service rejects thread creation: authentication failure, invalid thread options, rate limiting, or a server error.
Common situations: Bad/expired API key; wrong endpoint; malformed metadata/options; quota exhausted; transient 5xx.
Related errors
- The thread could not be deleted due to an error response fro
- The message could not be added to the thread due to an error
- The message could not be added to the thread due to an error
- The thread could not be created due to an error response fro
- The thread could not be deleted due to an error response fro
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/5206f2c593124f5a.
Report an issue: GitHub.