{"record":{"id":"3fccedfe914e2324","repo":"microsoft/semantic-kernel","slug":"unexpected-response-from-url","errorCode":null,"errorMessage":"Unexpected response from {url}","messagePattern":"Unexpected response from (.+?)","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.OpenAI/Services/OpenAIFileService.cs","lineNumber":218,"sourceCode":"    {\n        using var request = HttpRequest.CreateDeleteRequest(this.PrepareUrl(url));\n        this.AddRequestHeaders(request);\n        using var _ = await this._httpClient.SendWithSuccessCheckAsync(request, cancellationToken).ConfigureAwait(false);\n    }\n\n    private async Task<TModel> ExecuteGetRequestAsync<TModel>(string url, CancellationToken cancellationToken)\n    {\n        using var request = HttpRequest.CreateGetRequest(this.PrepareUrl(url));\n        this.AddRequestHeaders(request);\n        using var response = await this._httpClient.SendWithSuccessCheckAsync(request, cancellationToken).ConfigureAwait(false);\n\n        var body = await response.Content.ReadAsStringWithExceptionMappingAsync(cancellationToken).ConfigureAwait(false);\n\n        var model = JsonSerializer.Deserialize<TModel>(body);\n\n        return\n            model ??\n            throw new KernelException($\"Unexpected response from {url}\")\n            {\n                Data = { { \"ResponseData\", body } },\n            };\n    }\n\n    private async Task<(Stream Stream, string? MimeType)> StreamGetRequestAsync(string url, CancellationToken cancellationToken)\n    {\n        using var request = HttpRequest.CreateGetRequest(this.PrepareUrl(url));\n        this.AddRequestHeaders(request);\n        var response = await this._httpClient.SendWithSuccessCheckAsync(request, cancellationToken).ConfigureAwait(false);\n        try\n        {\n            return\n                (new HttpResponseStream(\n                    await response.Content.ReadAsStreamAndTranslateExceptionAsync(cancellationToken).ConfigureAwait(false),\n                    response),\n                    response.Content.Headers.ContentType?.MediaType);\n        }","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.OpenAI/Services/OpenAIFileService.cs#L200-L236","documentation":"The OpenAIFileService sends an HTTP GET to the files endpoint. After SendWithSuccessCheckAsync passes (HTTP 2xx), the response body is deserialized to TModel. If deserialization yields null (empty body or JSON 'null'), KernelException is thrown with the raw body preserved in the exception's Data dictionary under 'ResponseData'. This is distinct from an HTTP error — the request succeeded but the body was unusable.","triggerScenarios":"Calling a file-service GET operation (e.g. GetFileAsync, list files) where the server returns 200 with an empty body, a JSON literal 'null', or a body whose shape doesn't match TModel and deserializes to null.","commonSituations":"Azure OpenAI api-version mismatch causing a different response envelope. A reverse proxy returning a 200 status page (HTML) for a route that doesn't exist. Pointing the file service at a base URL for a different API tier that returns empty responses. The file ID not existing on a server that returns 200+null instead of 404.","solutions":["Verify the endpoint base URL and (for Azure) the api-version query parameter are correct for the files API.","Inspect the exception's Data['ResponseData'] to see the raw body — this reveals whether it's empty, HTML, or malformed JSON.","Confirm the API key and organization headers are valid; some proxies return 200 with an error body.","Check that the file ID or resource path actually exists on the target deployment."],"exampleFix":"// before — wrong base URL or stale api-version\nvar fileService = new OpenAIFileService(\"https://my-resource.openai.azure.com/\", apiKey, apiVersion: \"2023-05-15\");\n\n// after — correct files endpoint and current api-version\nvar fileService = new OpenAIFileService(\"https://my-resource.openai.azure.com/openai/files\", apiKey, apiVersion: \"2024-05-01\");","handlingStrategy":"retry","validationCode":"// Pre-call: verify the endpoint and api-version are configured\nif (string.IsNullOrWhiteSpace(endpointUrl))\n    throw new InvalidOperationException(\"File service endpoint URL is required.\");\nif (isAzure && string.IsNullOrWhiteSpace(apiVersion))\n    throw new InvalidOperationException(\"Azure OpenAI requires an api-version.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var file = await fileService.GetFileAsync(fileId, ct);\n}\ncatch (KernelException ex) when (ex.Message.Contains(\"Unexpected response\"))\n{\n    var rawBody = ex.Data.Contains(\"ResponseData\") ? ex.Data[\"ResponseData\"]?.ToString() : \"<none>\";\n    logger.LogError(\"File GET returned unparseable body: {Body}\", rawBody);\n    throw;\n}","preventionTips":["Always inspect ex.Data['ResponseData'] — it contains the raw body that failed to deserialize.","Pin the Azure api-version to one tested with your connector version.","Use integration tests against the real endpoint to catch envelope-shape changes early."],"tags":["file-service","http","deserialization","azure","response-validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}