← Blog

LLM API Content-Type Enforcement at the Authenticated Request Boundary

Parminder Singh
Parminder Singh··6 min read
Summarize with AI

LLM API Content-Type enforcement gives each authenticated model route an explicit media-type contract. This guide maps RFC 9110 semantics to JSON inference requests, file-bearing calls, streaming responses, 415 handling, parser alignment, and identity-aware gateway policy. The goal is a small accepted type set, one parsing decision across every HTTP hop, and an audit record that captures the declared and effective request type.

Platform & Architectureai-securityllm-securitycybersecurityidentity-and-authorizationpolicy-enforcementarchitecture
LLM API Content-Type Enforcement at the Authenticated Request Boundary

An authenticated POST /v1/chat/completions request normally carries JSON. The Content-Type field tells every recipient how to interpret those bytes before a model sees a prompt. RFC 9110 Section 8.3 defines the field as the representation's media type and says that the type determines both the data format and its processing model. For an LLM route, that means application/json should be an enforced contract, not a hopeful convention. I would reject any production design that lets each proxy guess the body type independently.

TL;DR

  • Bind an explicit request media-type allowlist to each authenticated LLM route.
  • Return 415 before model invocation when the declared type, content coding, or body format falls outside that contract.
  • Keep the gateway, application, and model adapter on one parsing decision; never repair an ambiguous type differently at each hop.
  • Record identity, route, declared type, effective type, policy version, and decision for every governed request.

Content-Type defines the parser contract

The header Content-Type: application/json says more than "these bytes look like JSON." Under RFC 9110 Section 8.3.1, a media type defines a data format and a processing model. The distinction matters on an authenticated model route because the parser creates the object that authorization and prompt policy will inspect.

A route contract should name accepted media types exactly. A chat or embeddings endpoint might accept only application/json. A file-upload route might accept multipart/form-data with a required boundary parameter. An event-stream response uses text/event-stream, but that response type does not automatically authorize the same type in a request. Parameters belong in the contract too. Type and subtype matching is case-insensitive, while parameter significance depends on the media-type definition.

Put the contract beside the route and method policy. The whiteboard should show a small box labeled POST + application/json directly after authentication, before the larger box representing body parsing and prompt inspection. That physical ordering is the implementation requirement.

Missing and conflicting declarations need one outcome

RFC 9110 allows a recipient to assume application/octet-stream or inspect the data when Content-Type is absent. That flexibility supports general HTTP interoperability. It is a poor default for a narrowly defined LLM API. A JSON-only inference route should require the header and reject an absent declaration under its API contract.

MIME sniffing creates a second interpretation path. RFC 9110 warns that sniffing can draw incorrect conclusions and expose a recipient to security risks. The standard also notes that duplicate Content-Type fields can produce different error handling across implementations. An authenticated call should therefore receive one deterministic result for a missing, malformed, or duplicated singleton field. The safest implementation rejects the request before forwarding.

Do not let the edge accept text/plain because the bytes happen to parse as JSON while the application later treats the same request as ordinary JSON. Do not let one component select the last duplicate value and another select the first. The OWASP API Security mapping for LLM endpoints explains why inconsistent parsing belongs in the API security review, alongside model-specific controls.

Route policy should use an exact media-type allowlist

Start with an inventory of authenticated user and agent routes. For each method and path, define the accepted request media type, permitted parameters, allowed content coding, maximum body size, and response formats. A narrow set reduces parser ambiguity. */* is useful in negotiation, but it is an evasive request-body policy for a JSON inference endpoint.

Evaluate the raw field before expensive body work. Then parse with the same media-type decision that the downstream adapter will honor. A useful decision sequence is:

  • Validate authentication and bind the caller's user, workload, or agent identity.
  • Match the normalized method and exact route.
  • Parse the singleton Content-Type field without repairing duplicates.
  • Compare the type and permitted parameters with the route allowlist.
  • Check Content-Encoding, framing, and body-size policy.
  • Parse the body once, apply schema and prompt policy, then forward the governed representation.

This sequence stays inside the authenticated HTTP boundary. It covers requests deliberately routed through the enforcement point. Local model calls and direct provider traffic need controls on their own paths.

415 separates media-type rejection from schema rejection

RFC 9110 Section 15.5.16 defines 415 Unsupported Media Type for content in a format that the target resource's method does not support. The problem can arise from Content-Type, Content-Encoding, or direct inspection. The response can include Accept to indicate acceptable request media types or Accept-Encoding for accepted content codings.

Use 415 when the route refuses the representation format. Reserve 400 for malformed HTTP or a malformed request that your API contract assigns there. Use 422 only after the server understands the content type and syntax but cannot process the instructions. That split produces operationally useful evidence. A 415 spike points to client contract drift or probing. A 422 spike points to a body that passed the media-type and syntax gates.

Keep rejection bodies small and consistent. Return a request identifier and the supported type, while withholding parser traces and model-adapter details. The model should receive zero tokens for a request rejected at this stage. The LLM security testing guide provides the regression pattern for boundary fixtures and expected decisions.

Intermediaries must agree before forwarding

An LLM call may traverse a load balancer, an API gateway, an identity-aware policy point, an application service, and a provider adapter. Every hop that parses the body can create a disagreement. RFC 9110 calls out security and interoperability problems when recipients handle duplicate Content-Type values differently. The safest route gives one component authority to validate the representation and passes a normalized internal representation downstream.

Preserve the original declaration in the audit record even if the gateway normalizes casing or parameter presentation. Record any effective type separately. That leaves a reviewer able to distinguish what the authenticated caller sent from what the enforcement point accepted.

Test the entire chain with absent fields, duplicate fields, mixed-case types, unsupported charset parameters, wrong boundaries, unsupported content codings, JSON under text/plain, and non-JSON bytes under application/json. Put two terminal windows side by side during review. The left window should show the request headers; the right should show a 415 event with no provider request ID. That visual proves the rejection happened before model invocation.

Audit evidence should capture the contract decision

A useful protocol record includes the authenticated subject, agent or workload identity, timestamp, HTTP method, normalized route, declared type, effective type, content coding, policy version, decision, status code, and correlation ID. Record a body digest only when the organization's evidence policy permits it. Raw prompts can contain regulated data and should not be copied into an error log by default.

Treat each route contract as a versioned policy artifact. A deployment that adds multipart/form-data to a file route should produce a policy change that reviewers can correlate with later requests. The post-authentication gap applies here: a valid credential identifies the caller, while the per-request decision determines which representation that caller may send to this route.

Include positive and negative fixtures in release tests. A valid JSON request should reach the model adapter. An authenticated request using an unapproved type should end at the policy point with 415. A duplicate field should produce the same decision at every ingress replica. Those are concrete acceptance conditions, not a generic "strict mode" checkbox.

DeepInspect

DeepInspect operates on authenticated HTTP traffic deliberately routed between users or agents and LLM endpoints. It can bind a media-type rule to the supplied identity context, HTTP method, route, and model destination, then reject an unapproved representation before forwarding request content. That decision can sit beside prompt classification, model authorization, body-size limits, and response policy.

Each decision can produce an independent audit record with the caller context, route, declared type, policy version, and outcome. The application remains responsible for supplying trustworthy identity context and defining its accepted API contract. Direct calls that bypass the routed enforcement point remain outside this control.

Book a demo today.