microsoft/semantic-kernel · error · KernelException
Neither of the media types of {operationId} is supported.
Error message
Neither of the media types of {operationId} is supported. What it means
Thrown by the Semantic Kernel OpenAPI document parser when an operation's requestBody only declares media types the parser does not handle. GetMediaType() iterates s_supportedMediaTypes, which is hard-coded to exactly 'application/json' and 'text/plain'; if no request-body content key matches (ignoring trailing parameters after ';'), it returns null and CreateRestApiOperationPayload raises KernelException. This is a parser coverage limit, not a malformed-spec error.
Source
Thrown at dotnet/src/Functions/Functions.OpenApi/OpenApi/OpenApiDocumentParser.cs:473
}
return result;
}
/// <summary>
/// Creates REST API payload.
/// </summary>
/// <param name="operationId">The operation id.</param>
/// <param name="requestBody">The OpenAPI request body.</param>
/// <returns>The REST API payload.</returns>
private static RestApiPayload? CreateRestApiOperationPayload(string operationId, OpenApiRequestBody requestBody)
{
if (requestBody?.Content is null)
{
return null;
}
var mediaType = GetMediaType(requestBody.Content) ?? throw new KernelException($"Neither of the media types of {operationId} is supported.");
var mediaTypeMetadata = requestBody.Content[mediaType];
var payloadProperties = GetPayloadProperties(operationId, mediaTypeMetadata.Schema);
return new RestApiPayload(mediaType, payloadProperties, requestBody.Description, mediaTypeMetadata?.Schema?.ToJsonSchema());
}
/// <summary>
/// Returns the first supported media type. If none of the media types are supported, an exception is thrown.
/// </summary>
/// <remarks>
/// Handles the case when the media type contains additional parameters e.g. application/json; x-api-version=2.0.
/// </remarks>
/// <param name="content">The OpenAPI request body content.</param>
/// <returns>The first support ed media type.</returns>
/// <exception cref="KernelException"></exception>
private static string? GetMediaType(IDictionary<string, OpenApiMediaType> content)
{View on GitHub (pinned to c028a0c7dc)
Solutions
- Edit the OpenAPI spec to add an 'application/json' (or 'text/plain') entry under requestBody.content for the failing operationId, mirroring the existing schema.
- If the operation genuinely only supports a non-JSON type (e.g. file upload), exclude that operation via OpenApiFunctionExecutionParameters.OperationsToExclude so the parser never builds its payload.
- Fork/extend the parser: s_supportedMediaTypes is a private static list, so a local subclass of the document parser is required to register additional types (no public API exists).
- Confirm the failing operationId from the exception message and inspect requestBody.content keys in the source spec to confirm none match json/plain.
Example fix
// before (spec excerpt) - only XML declared
// requestBody:
// content:
// application/xml:
// schema: { $ref: '#/components/schemas/Pet' }
// after - add an application/json entry
// requestBody:
// content:
// application/json:
// schema: { $ref: '#/components/schemas/Pet' }
// application/xml:
// schema: { $ref: '#/components/schemas/Pet' } Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight: confirm each operation has a supported media type before importing.
// supported = application/json | text/plain (case-insensitive, ignores ';...' params)
static bool HasSupportedRequestBodyMediaType(OpenApiDocument doc)
{
var supported = new[] { "application/json", "text/plain" };
bool ok = true;
foreach (var (path, item) in doc.Paths)
foreach (var op in item.Operations.Values.Where(o => o.RequestBody is not null))
{
var keys = op.RequestBody.Content.Keys
.Select(k => k.Split(';')[0].ToLowerInvariant()).ToList();
if (!keys.Any(k => supported.Contains(k)))
{
Console.WriteLine($"{op.OperationId}: no supported media type (has {string.Join(",", keys)})");
ok = false;
}
}
return ok;
} Type guard
static bool IsSupportedMediaType(string? contentType) =>
contentType is not null &&
new[] { "application/json", "text/plain" }
.Contains(contentType.Split(';')[0].Trim(), StringComparer.OrdinalIgnoreCase); Try / catch
try
{
var plugin = await kernel.CreatePluginFromOpenApiAsync("api", specStream, execParams);
}
catch (KernelException ex) when (ex.Message.Contains("Neither of the media types"))
{
// log the operationId from the message, fix the spec's requestBody.content, retry
logger.LogWarning("OpenAPI import failed on unsupported media type: {Msg}", ex.Message);
} Prevention
- Author specs so every writable operation advertises application/json.
- Run a lint step (spectral/shinsou) that flags request bodies lacking application/json or text/plain before import.
- Exclude operations that legitimately only support non-JSON media types via OperationsToExclude.
When it happens
Trigger: Calling KernelPluginFactory.CreateFromOpenApiAsync (or OpenApiKernelPluginFactory) against an OpenAPI spec whose POST/PUT/PATCH operation declares a requestBody.content with only unsupported media types, e.g. 'application/xml', 'application/octet-stream', 'multipart/form-data', 'application/x-www-form-urlencoded', or 'application/problem+json' without a base 'application/json' entry.
Common situations: Importing a spec that only advertises XML (older SOAP-style REST or Java/Spring defaults), specs that use multipart/form-data for file uploads, specs that list vendor media types like 'application/vnd.api+json', or a spec authored with content-type keys whose primary segment is not exactly 'application/json'/'text/plain'. Also happens after a partial refactor that dropped the JSON content-type.
Related errors
- Max level {PayloadPropertiesHierarchyMaxDepth} of traversing
- The value type '{value.PrimitiveType}' of {entityDescription
- {nameof(executionParameters.OperationSelectionPredicate)} an
- AZURE_OPENAI_ENDPOINT is not set.
- Agent with name {agentId.Type} not found.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/c299ca071579291d.
Report an issue: GitHub.