-
Notifications
You must be signed in to change notification settings - Fork 5k
Description
Library name and version
Azure.AI.Inference 1.0.0-beta.4
Describe the bug
I have code to guard no break when updating model version, while my code is working well with gpt-4o with Azure Inference SDK, just changing the deployment model to version gpt-4.1, it will throw error:
System.Text.Json.JsonReaderException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.
Stack Trace:
ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan1 bytes) Utf8JsonReader.Read() JsonDocument.Parse(ReadOnlySpan
1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack)
JsonDocument.Parse(ReadOnlyMemory1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedArrayPoolBytes, PooledByteBufferWriter extraPooledByteBufferWriter) ChatCompletions.FromResponse(Response response) <CompleteAsync>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- ExceptionDispatchInfo.Throw() TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) TaskAwaiter
1.GetResult()
d__3.MoveNext() line 33
--- End of stack trace from previous location where exception was thrown ---
ExceptionDispatchInfo.Throw()
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Here is the code:
`
[TestClass]
public class TestAzureAIInferenceWithSDK
{
Uri endpointUri = new Uri("https://.services.ai.azure.com/models");
string apiKey = "*****";
string deploymentName = "gpt-4.1"; // "gpt-4o";
[TestMethod]
public async Task SimpleTextPromptTest()
{
ChatCompletionsClient chatCompletionsClient = new ChatCompletionsClient(endpointUri, new AzureKeyCredential(apiKey));
var requestOptions = new ChatCompletionsOptions()
{
Messages =
{
new ChatRequestSystemMessage("You are a helpful assistant"),
new ChatRequestUserMessage("What is the result of 1+1"),
},
Model = deploymentName,
MaxTokens = 800
};
var txtResult = await chatCompletionsClient.CompleteAsync(requestOptions);
var rawResponse = txtResult.GetRawResponse();
Assert.IsNotNull(rawResponse);
Assert.AreEqual(200, rawResponse.Status);
Assert.IsNotNull(txtResult.Value);
Assert.IsNotNull(txtResult.Value.Content);
}
}
`
Expected behavior
chatCompletionsClient.CompleteAsync function should work for this simple prompt for gpt-4.1 model
("What is the result of 1+1"),
Actual behavior
System.Text.Json.JsonReaderException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.
Reproduction Steps
- Deploy a gpt-4.1 model (version 2025-04-14) in Azure AI foundry:

- Create a C# console or unit test project, write sample code to ask ("What is the result of 1+1"),
`
// Replace endpointUri,apiKey and deploymentName
[TestMethod]
public async Task SimpleTextPromptTest()
{
ChatCompletionsClient chatCompletionsClient = new ChatCompletionsClient(endpointUri, new AzureKeyCredential(apiKey));
var requestOptions = new ChatCompletionsOptions()
{
Messages =
{
new ChatRequestSystemMessage("You are a helpful assistant"),
new ChatRequestUserMessage("What is the result of 1+1"),
},
Model = deploymentName,
MaxTokens = 800
};
var txtResult = await chatCompletionsClient.CompleteAsync(requestOptions);
var rawResponse = txtResult.GetRawResponse();
Assert.IsNotNull(rawResponse);
Assert.AreEqual(200, rawResponse.Status);
Assert.IsNotNull(txtResult.Value);
Assert.IsNotNull(txtResult.Value.Content);
}
`
Environment
Windows 11
Microsoft Visual Studio Enterprise 2022 (2) (64-bit) Version 17.13.6
.NETFramework 4.8 and .NET 8 also tried