﻿# How OpenRouter normalizes provider responses

Design an OpenRouter response adapter that handles text, tool requests, reasoning items and usage without mixing Responses and Chat Completions fields.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/learn-openrouter-response-contract/
Language: en

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

- [OpenRouter API Reference - Complete Documentation](https://openrouter.ai/docs/api-reference/overview).

- [Provider Routing - Smart Multi-Provider Request Management](https://openrouter.ai/docs/guides/routing/provider-selection).

- [Tool & Function Calling - Use Tools with OpenRouter](https://openrouter.ai/docs/guides/features/tool-calling).

Related engineering guides: [OpenRouter usage: reconciling tokens and request cost](/journal/openrouter-usage-accounting/); [Tool calling through OpenRouter: the model proposes, your app executes](/journal/openrouter-tool-calling/).
