Skip to content

openai-completions silently ignores compat.openRouterRouting if baseUrl is not openrouter.ai #5347

@ruro

Description

@ruro

What happened?

The documentation states that

For providers with partial OpenAI compatibility, use the compat field.
<snip>

Field Description
openRouterRouting OpenRouter provider routing preferences.
This object is sent as-is in the provider field of the OpenRouter API request.

However, in reality the provider field is only sent if baseUrl contains "openrouter.ai":

if (model.baseUrl.includes("openrouter.ai") && model.compat?.openRouterRouting) {

There are cases, when baseUrl could be different from "openrouter.ai", but sending the provider field should still be sent:

  1. Some LLM providers support many options from the OpenRouter API extensions (including the provider object), not just the ai-sdk/openai-compatible subset.

  2. It's possible that baseUrl points to a proxy / gateway of some kind that eventually forwards the requests to openrouter.ai. In that case, checking model.baseUrl.includes("openrouter.ai") doesn't make sense.

Steps to reproduce

  1. Run a local HTTP server that simply logs all HTTP requests before forwarding them to openrouter.ai.

  2. Use the following models.json:

    {
        "providers": {
            "local-openrouter-proxy": {
                "baseUrl": "http://127.0.0.1:8000/api/v1",
                "api": "openai-completions",
                "apiKey": "whatever",
                "models": [
                    {
                        "id": "deepseek/deepseek-v4-pro",
                        "compat": {"openRouterRouting": {"only": ["DeepSeek"], "allow_fallbacks": false}}
                    }
                ]
            }
        }
    }
  3. Observe the fact that pi silently ignores the openRouterRouting key (no provider object is inserted into the requests).

Expected behavior

The openRouterRouting key should always insert a provider object into the request, no matter what baseUrl is.

I am temporarily working around this issue with this extension:

import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";

export default function (pi: ExtensionAPI) {
    pi.on("before_provider_request", (event, ctx) => {
        const provider = ctx.model?.compat?.openRouterRouting;
        if (provider !== undefined) {
            return { ...event.payload, provider };
        }
    });
}

But ideally, I think, this should be fixed in pi itself.

Version

0.76.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinginprogressIssue is being worked on

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions