LLM ROUTING

How OpenRouter normalizes provider responses

In this article
THE QUICK TAKE

A response adapter should preserve typed meaning and completion state before projecting a model result into the simpler data a product displays.

An API response can contain more than an answer paragraph. OpenRouter normalizes provider output, but its documented response families expose different structures for messages, function calls and usage. A client adapter should make those distinctions explicit so new capabilities do not disappear inside a helper that only extracts the first text field.

Identify the endpoint contract first

For Responses, generated content lives in an output array with typed items. For Chat Completions, choices contains message objects or streaming deltas. A hypothetical research assistant should use the parser associated with the endpoint it called. Guessing the family from whichever field happens to exist can conceal an integration mistake and cause different paths to discard meaningful output silently.

Preserve non-text results

A Responses function-call item is not an output-text part. In Chat Completions, an assistant message can carry tool calls instead of an ordinary final answer. Preserve the proposed function name, arguments and correlation identifier for the application’s tool workflow. A display component may choose to show a short status, but its simplified view must not replace the structured record needed to execute and return a tool result.

Keep usage fields in their family

Responses documents input and output token fields, while Chat Completions uses prompt and completion terminology. An internal application metric can map them deliberately, retaining optional detail fields when relevant. Do not add unrelated counters together or assume that every backend supplies identical detail. A normalized product display should explain its own metric rather than imply that a renamed field changes what the provider measured.

Do not finalize from an intermediate update

Streaming output arrives through events or deltas whose purpose is incremental assembly. A text fragment is not necessarily a completed answer or valid tool argument object. Associate updates with their item or choice and wait for the relevant completion signal. The adapter should distinguish an interrupted result from a fully completed one, allowing the interface to display partial work without treating it as an authoritative final artifact.

Test the adapter’s meaningful branches

Use fixtures for text-only output, a tool request, an error and an interrupted stream under the chosen API family. If the product supports both families, keep separate fixtures for their actual shapes. Domain validation remains another layer: a correctly parsed answer can still be wrong. The adapter’s job is to preserve the response’s meaning faithfully enough that the application can make that next decision.

Documentation and further study

Related engineering guides: OpenRouter usage: reconciling tokens and request cost; Tool calling through OpenRouter: the model proposes, your app executes.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles