How to see which provider served a free LLM API request
For OpenRouter, add X-OpenRouter-Metadata: enabled to the Chat Completions request and inspect openrouter_metadata.endpoints.available. Record the provider whose entry has selected: true. Keep that provider separate from the requested alias and the response's model field. This is OpenRouter-specific metadata; another OpenAI-compatible API may expose different fields or no provider information at all.
Keep the four values separate
An OpenAI-compatible response can name a model without naming the company that hosted it. A free-model router may also send the same alias to different providers on different requests. If you are checking data handling, incident ownership, or whether a fallback changed the route, capture the route result for the individual request instead of inferring it from your configuration.
| Value | What it tells you | What it does not prove |
|---|---|---|
Request model |
The alias or model ID your client asked the gateway to use. | Which provider eventually received the request. |
Response model |
The model ID reported in the returned Chat Completions object. OpenAI documents this as the model used for that response. | The provider organization that hosted the model. A model author and its serving provider can be different. |
openrouter_metadata.requested |
The request target reported by OpenRouter's opt-in routing metadata. | That every gateway has the same field or semantics. |
openrouter_metadata.endpoints.available[] |
The endpoint choices reported for this response, including a provider name and a selected flag in the documented example. |
A universal proof format outside OpenRouter. |
The distinction matters when you use an alias such as openrouter/free. OpenRouter's API reference documents model on the response and separately documents optional openrouter_metadata, enabled with a request header. The metadata can show the selected endpoint and provider; the response model alone is not a provider name. See the OpenRouter Chat Completions reference and the OpenAI Chat Completions response schema.
Request routing metadata without logging the prompt
Here is a minimal Node.js example using the built-in fetch. Set OPENROUTER_API_KEY in your server environment. The request sends one short message if you run it; it is an example, not a live test performed for this guide.
function selectedProvider(payload) {
const endpoints = payload.openrouter_metadata?.endpoints?.available;
if (!Array.isArray(endpoints)) return null;
const selected = endpoints.filter(
(entry) => entry?.selected === true &&
typeof entry.provider === "string" && entry.provider.trim() !== ""
);
return selected.length === 1 ? selected[0].provider : null;
}
const response = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`,
"Content-Type": "application/json",
"X-OpenRouter-Metadata": "enabled",
},
body: JSON.stringify({
model: "openrouter/free",
messages: [{ role: "user", content: "Reply with one short word." }],
}),
});
const payload = await response.json();
if (!response.ok) {
throw new Error(`Chat Completions returned HTTP ${response.status}`);
}
console.log({
requestedRoute: payload.openrouter_metadata?.requested ?? null,
reportedModel: payload.model ?? null,
selectedProvider: selectedProvider(payload) ?? "unknown",
completionId: payload.id ?? null,
});
Keep the API key server-side. Save only the fields you need for diagnosis: timestamp, requested route, reported model, selected provider (or unknown), status, and completion ID. Avoid logging the prompt, authorization header, or full request body just to learn which endpoint was selected.
Treat missing or ambiguous metadata as unknown
Do not fall back to guessing from payload.model. The parser above returns null if metadata is absent, if no provider is marked selected, if multiple entries are marked selected, or if the selected entry has no provider name. That is deliberate: these cases need a provider-specific trace or a console request record.
This is more than a theoretical distinction. One public Claude Code Router report described a response model that did not match the expected fallback model. Its author could not tell from local logs whether the fallback had run or whether the gateway had rewritten the response field. Treat that as one unresolved report, not a claim that all gateways return incorrect model IDs. It is a reason to keep the route result and the response model as separate evidence.
Offline fixture: test the decision before a real request
The following example is synthetic. It does not represent an OpenRouter response or a provider call. It checks that a unique selected endpoint is recorded, while missing and ambiguous selection stays unknown.
| Synthetic input | Expected result | Why |
|---|---|---|
One entry has provider: "ExampleHost" and selected: true; a second entry is unselected. |
ExampleHost |
Exactly one provider is marked as serving this response. |
openrouter_metadata is absent, but model contains example/model. |
unknown |
A model ID does not identify its host. |
| No endpoint is selected, or two entries are selected. | unknown |
The route record is incomplete or ambiguous. |
| A selected entry has an empty provider name. | unknown |
Do not convert missing metadata into an attribution claim. |
Run a parser fixture like this against saved, synthetic JSON before adding route fields to production logs. It tests your handling of metadata; it does not test OpenRouter, prove an actual fallback, or measure model quality. No key or real request is needed for the fixture.
When the provider field is unavailable
The X-OpenRouter-Metadata header is not part of the general OpenAI-compatible contract. It applies to OpenRouter's documented endpoint. For another gateway, check that gateway's current response or observability documentation for a per-request provider field. If the response exposes only a model ID, record the provider as unknown and correlate a documented request ID with the provider-side request log. Do not invent a header name or treat an intended route as proof of the route that handled the call.
If a fixed provider is required, choose an endpoint or routing policy that documents how provider selection works, then verify one response using that service's own telemetry. A fixed model slug may still be hosted by more than one provider. Automatic routing and a fixed provider are different requirements; decide which one your application needs before relying on either.
Frequently asked questions
Does the response model field identify the provider?
No. It identifies a model as reported by the API response. A model can be served by a provider other than its author. Use route metadata when the gateway documents it.
Is X-OpenRouter-Metadata portable to any free LLM API?
No. It is an OpenRouter-specific opt-in. Other APIs may have their own response fields, request IDs, or dashboards; some may not expose provider attribution.
Does a different response model prove fallback happened?
No. A mismatch is a diagnostic clue, not proof of the route. Check the selected endpoint metadata or correlate a provider-side request record.
Does this describe ChinaGenAI's free route?
No. ChinaGenAI's automatic route and OpenRouter's metadata are separate systems. The OpenRouter header should only be sent to the OpenRouter endpoint, and its provider names do not describe ChinaGenAI's upstream selection.
Sources checked 2026-11-10
- OpenRouter Chat Completions reference — opt-in
X-OpenRouter-Metadataheader and response routing metadata. - OpenRouter generation metadata reference — per-generation model, provider and router metadata when a generation ID is available.
- OpenAI Chat Completions API reference — response
modelfield. - Claude Code Router issue #1861 — one unresolved report of a response model/fallback mismatch; cause not established.
This guide was checked against documentation and synthetic local fixtures. No API key, provider account, model request, or live fallback was used.