Module 5 of 12 · 55 min

Model Serving and API Compatibility Contracts

Expose a bounded model endpoint with explicit health, identity, request, response, streaming, error, authentication, and compatibility contracts.

Core concept

By the end

You will be able to

  • Separate the model runtime, inference server, gateway, application adapter, and public endpoint trust boundaries.
  • Define liveness, readiness, model identity, inference, streaming, cancellation, timeout, error, and overload contracts.
  • Treat OpenAI-compatible and other compatibility claims as tested subsets rather than universal equivalence.
  • Publish a versioned conformance suite and migration boundary that preserves application behavior across runtimes.
01

Separate runtime, server, gateway, and application contracts

The model runtime loads and executes the artifact. An inference server turns runtime operations into a network protocol. A gateway can enforce identity, authorization, limits, routing, policy, audit, and stable external names. An application adapter maps product-owned requests and outcomes to the selected serving protocol. Keep these layers explicit so a runtime replacement does not silently rewrite policy or learner-facing behavior.

Bind the served model name to the immutable model and runtime bundle behind it. A friendly alias can support controlled replacement, but responses, telemetry, evaluation, and rollback evidence must retain the exact underlying identity.

02

Define liveness, readiness, and model identity separately

Liveness asks whether the server process can respond and should not require every downstream dependency to be healthy. Readiness asks whether this instance should receive inference traffic. Model readiness confirms that the intended model and version are loaded and able to serve. Model metadata should identify the served contract without exposing secrets, internal paths, or unnecessary infrastructure details.

KServe's Open Inference Protocol V2 defines distinct server liveness, server readiness, model readiness, model metadata, and inference endpoints. Whether using that protocol or another, test transition behavior during startup, load, unload, pressure, failed dependencies, update, and rollback. A process that returns HTTP 200 while the wrong model is loaded is not ready.

03

Own the inference and failure contract

Version the allowed request fields, roles or input parts, modalities, encoding, context and output limits, sampling controls, stop rules, tools if any, response schema, model identity, usage accounting, finish reasons, safety or policy outcomes, and extension fields. Reject unsupported or ambiguous inputs instead of silently ignoring them.

Define authentication and authorization outside model prompts. Specify request identifiers, idempotency expectations, maximum body size, timeouts, cancellation, streaming event order, disconnect behavior, queue and rate limits, overload responses, retryability, error codes, observability identifiers, and redaction. Bound retries so one overloaded request does not multiply load.

04

Treat compatibility as a tested subset

An OpenAI-compatible server may implement selected paths and fields while differing in model discovery, roles, tools, structured output, streaming chunks, token accounting, errors, limits, extensions, or unsupported parameters. vLLM documents an OpenAI-compatible server, but application compatibility still depends on the exact version, endpoint, model, configuration, and features used.

Write a conformance matrix for the application-owned subset. Include positive, boundary, invalid, unauthorized, overloaded, timeout, cancellation, streaming, and restart cases. Record required, transformed, ignored, emulated, rejected, and unavailable behavior. Never infer full protocol or behavioral equivalence from one successful chat request.

05

Preserve a portable adapter and reversible cutover

Keep user outcomes, application schemas, authorization policy, evaluation cases, trace fields, postconditions, error categories, and recovery rules above the runtime adapter. Put protocol-specific field names, streaming events, tool formats, and server extensions behind the adapter. Avoid a lowest-common-denominator contract that hides capabilities or safety differences.

For a runtime change, run the same conformance and evaluation suites against baseline and candidate, compare performance and failure behavior, canary a bounded route, preserve exact telemetry, and retain the last verified adapter and serving bundle. Roll back on critical contract, quality, security, latency, capacity, or observability regression.

Practice activity

Design a portable serving conformance suite

  1. Define synthetic liveness, readiness, model-readiness, identity, inference, streaming, cancellation, timeout, invalid-input, unauthorized, rate-limit, and overload contracts.
  2. Choose a small application-owned request and response schema and map it to two hypothetical runtime adapters.
  3. Create a field matrix labeling each behavior required, transformed, ignored, emulated, rejected, or unavailable.
  4. Write deterministic cases for normal, boundary, failure, restart, and recovery behavior with expected status, body, events, and telemetry.
  5. Design a baseline-candidate cutover and rollback decision that fails closed on critical contract or safety regressions.

What to produce

  • A versioned endpoint and error contract with separate health, readiness, identity, and inference semantics.
  • A two-adapter compatibility matrix and deterministic conformance fixture set.
  • A cutover record with comparison thresholds, canary scope, exact model identities, stop conditions, and rollback evidence.

Reflect before continuing

Which behavior in your application would break even if both servers accept the same request path?

Evidence

Sources and verification

Knowledge check

Make it stick.

Pass at 80%

Choose the strongest answer for each question. Your attempts become part of your device-local transcript.

01Which layer should translate a stable application schema to a runtime-specific protocol?
02What is the difference between liveness and readiness?
03What does an OpenAI-compatible label safely establish?
04How should unsupported request fields be handled?
05Which case belongs in a conformance suite?
06What supports a safe runtime cutover?