microsoft/semantic-kernel · error · ArgumentException

Response is null

Error message

Response is null

What it means

Thrown by GetEmbeddingForSingleTextAsync (single-text embedding path, e.g. Titan) when InvokeModelAsync returned a response that is null or whose Body stream is null. The earlier try/catch only catches thrown exceptions, so a non-throwing but empty InvokeModelResponse reaches this ArgumentException.

Source

Thrown at dotnet/src/Connectors/Connectors.Amazon/Bedrock/Core/Clients/BedrockTextEmbeddingGenerationClient.cs:103

        try
        {
            var requestBody = splitVectorService!.GetInvokeModelRequestBody(this._modelId, text);
            using var requestBodyStream = new MemoryStream(JsonSerializer.SerializeToUtf8Bytes(requestBody));
            invokeRequest.Body = requestBodyStream;

            response = await this._bedrockRuntime.InvokeModelAsync(invokeRequest, cancellationToken).ConfigureAwait(false);
        }
        catch (Exception ex)
        {
            this._logger.LogError(ex, "Can't invoke with '{ModelId}'. Reason: {Error}", this._modelId, ex.Message);

            throw;
        }

        if ((response == null) || (response.Body == null))
        {
            throw new ArgumentException("Response is null");
        }

        return splitVectorService.GetInvokeResponseBody(response);
    }

    private async Task<IList<ReadOnlyMemory<float>>> GenerateBatchEmbeddingsAsync(
        IList<string> texts,
        CancellationToken cancellationToken = default
    )
    {
        var batchVectorService = this._ioVectorGenerationService as IBedrockCommonBatchTextEmbeddingGenerationService;
        var invokeRequest = new InvokeModelRequest
        {
            ModelId = this._modelId,
            Accept = "application/json",
            ContentType = "application/json",
        };

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Confirm the modelId is a real Bedrock embedding model and is enabled in the current region.
  2. Retry once on this ArgumentException as it can be transient.
  3. Check IAM/region/model-access (model invocation access must be granted in the Bedrock console).
  4. Wrap GenerateEmbeddingsAsync in try/catch (ArgumentException) and log this._modelId context.

Example fix

// before
var vec = await embeddings.GenerateEmbeddingsAsync(new[] { "text" });

// after
try
{
    var vec = await embeddings.GenerateEmbeddingsAsync(new[] { "text" });
}
catch (ArgumentException ex) when (ex.Message == "Response is null")
{
    throw new InvalidOperationException($"Bedrock returned an empty body for embedding model '{modelId}'.", ex);
}
Defensive patterns

Strategy: try-catch

Try / catch

try { await embeddings.GenerateEmbeddingsAsync(texts, ct); }
catch (ArgumentException ex) when (ex.Message == "Response is null")
{ throw new InvalidOperationException($"Bedrock returned an empty body for embedding model '{modelId}'. Verify model access in region.", ex); }

Prevention

When it happens

Trigger: Per-text embedding call where the Bedrock InvokeModel response came back non-null on the call but with a null Body, or the call returned null without throwing (rare AWS SDK path). Happens with a model id that Bedrock accepts but returns no body for, or a transient SDK/transport anomaly that yields an empty response object.

Common situations: Wrong/typo modelId that is not actually an embedding model but passes validation. Network/SDK edge case. Mismatched Accept/ContentType for a given model. Pointing the embedding service at a region where the model is unavailable.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/582458dbd4f87f83. Report an issue: GitHub.