← Blog

LLM Response Accept Negotiation for Authenticated API Clients

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

LLM response Accept negotiation turns response format into an explicit contract between an authenticated user or agent and an LLM endpoint. This guide covers media ranges, quality weights, streaming types, 406 handling, gateway validation, downgrade prevention, and audit evidence. It keeps JSON, event-stream, and other approved representations tied to route policy instead of client-library guesswork.

Platform & Architectureai-securityllm-securitycybersecurityidentity-and-authorizationpolicy-enforcementarchitecture
LLM Response Accept Negotiation for Authenticated API Clients

An authenticated LLM client can ask for a JSON response, a server-sent event stream, or any representation the endpoint defines. The HTTP mechanism is Accept. RFC 9110 Section 12.5.1 lets a user agent state preferred response media types with exact types, ranges, parameters, and quality weights. That field deserves policy treatment on an LLM route because the selected representation determines which parser receives model output. I consider silent fallback to an unspecified response type a protocol bug with security consequences.

TL;DR

  • Define approved response media types for every authenticated LLM route and client class.
  • Parse Accept media ranges and quality weights according to RFC 9110; avoid homegrown substring matching.
  • Return 406 when the endpoint refuses to send any representation acceptable to the caller.
  • Validate the actual response Content-Type, including streaming responses, before releasing model output.
  • Log the request preference, selected type, policy version, and final decision.

Accept is a response-format contract

Accept describes the media types a user agent can receive. RFC 9110 allows an exact type such as application/json, a subtype range such as text/*, or the broad */*. An optional q parameter gives a relative preference, and the most specific matching range takes precedence. These rules are precise enough to test mechanically.

For an LLM endpoint, representation choice often changes transport behavior. A non-streaming inference call commonly returns application/json. A server-sent event stream commonly uses text/event-stream. A provider may define a vendor media type for structured events. The endpoint contract must identify the set it can generate and the client must identify the set it can safely parse.

Place the negotiated type in the request context before model invocation. On a sequence diagram, draw Accept entering a small selector box, then carry the selected media type as a labeled arrow through the model adapter and response policy. The same value should reach the response serializer. That visible thread prevents negotiation from becoming an ingress-only check.

Media ranges and quality weights require real parsing

A policy that searches the header string for application/json will mishandle precedence and weights. application/json;q=0 explicitly makes JSON unacceptable. text/*;q=0.5, text/event-stream;q=1 prefers the event stream. A broad */* permits every available representation unless route policy narrows what the server may choose.

Use an RFC-aware parser and preserve the original field for evidence. Normalize type and subtype comparisons without erasing media-type parameters. Reject malformed syntax consistently. Start with the route's available representations, narrow them by the authenticated client's policy, and select among those accepted by the request field.

Identity belongs in that intersection. A browser-facing user client may be authorized for JSON only. A service agent that supports a governed event parser may receive text/event-stream. The post-authentication gap appears when a valid token grants every response mode without a per-request policy decision.

Do not use negotiation to smuggle policy through a media-type name. Authorization remains an explicit decision based on identity, route, model, and data context. Accept contributes a protocol signal; it never proves authority by itself.

Streaming creates a second validation point

A streaming LLM response arrives incrementally, but its media type is selected before the first model event reaches the caller. Validate the upstream response headers before releasing any bytes. If the adapter expected text/event-stream and receives application/json, hold the body until the status and type are interpreted. Providers often return JSON error objects on a route that normally streams, and forwarding those bytes into an event parser produces ambiguous failure behavior.

The policy also needs a rule for transformations. A gateway may collect a provider stream and emit one JSON object, or convert provider-specific events into a stable event schema. Record that transformation and set the outbound Content-Type to the representation actually sent. RFC 9110 defines Content-Type as the representation metadata, so copying the upstream type after changing the body is wrong.

The AI API security vendor guide describes the value of an inline policy point. For negotiation, inline placement lets the control validate upstream headers before a response reaches an authenticated user or agent.

406 should be deliberate and informative

RFC 9110 Section 15.5.7 defines 406 Not Acceptable for a target resource that lacks a current representation acceptable under proactive negotiation fields when the server refuses to supply a default. The server should provide available representation characteristics so the user agent can choose an alternative.

An LLM route should choose its fallback behavior explicitly. If the API contract says omitted Accept implies application/json, document and test that default. If the caller explicitly excludes every supported type, return 406. Do not override q=0 because a client library usually wants JSON. That turns an explicit safety boundary into guesswork.

Keep the 406 body in a stable error media type defined by the API contract. This point needs care: a client that rejected the normal success types still needs a parseable error. Many APIs standardize errors as JSON regardless of the success representation. State that behavior in the contract rather than discovering it during an incident.

A useful response includes a correlation ID and the supported success types. It should omit provider topology, internal serializer names, and prompt content.

Response policy follows the selected representation

Model output inspection must understand the representation it receives. JSON policy can target named fields. Event-stream policy must parse event boundaries and apply controls before each governed chunk is released. A binary or multipart format requires its own parser and size policy. One generic text scanner cannot safely stand in for all of them.

Bind output schemas to the selected type and route. Validate the upstream Content-Type, parse the representation, inspect the governed fields, and serialize the approved outbound type. On any mismatch, fail closed with the route's defined gateway error. The LLM security testing guide is a useful place to attach fixtures for JSON, event streams, unsupported types, and midstream failures.

Test negotiation across the full HTTP chain. Include exact and parameterized media types alongside wildcards. Add equal weights, zero weights, duplicate field lines, absent Accept, provider JSON errors on streaming calls, and an unapproved response Content-Type. A packet capture should show the response headers stopping at the gateway while the downstream client receives the governed error. The model output bytes should never appear on the client side of that capture.

Audit records need requested and selected types

Record the authenticated subject, agent or workload identity, route, method, original Accept value, parsed acceptable ranges, selected outbound type, upstream type, transformation identifier, policy version, status, and decision. For a stream, include whether release began and where a terminal policy event occurred. Avoid copying response content into protocol error logs.

This record distinguishes client incompatibility from upstream drift. A 406 with no selected type means the intersection was empty. A gateway rejection with an unexpected upstream type means the provider or adapter violated the selected contract. A transformed response should show both types and the named transformation.

Treat changes to supported representations as versioned API changes. Adding a new vendor media type expands the parser and serializer surface. Removing text/event-stream affects clients that selected it with the highest weight. Review both through the same release process used for route and model authorization changes. The OWASP API Security mapping for LLM endpoints supports this inventory-first treatment of API behavior.

DeepInspect

DeepInspect operates on authenticated HTTP requests and responses intentionally routed through its enforcement point. It can evaluate the caller identity, route, Accept preferences, selected model, and approved response types before forwarding the request. On the return path, it can compare the upstream Content-Type with the selected contract and apply representation-aware response policy before release.

A per-decision record can preserve the requested ranges, selected type, upstream type, policy version, and outcome. The calling application still owns correct client capability declarations and any local parser after the response leaves the governed boundary. Direct provider calls that bypass the route need separate enforcement.

Book a demo today.