Allow selection of inference provider when using OpenRouter #724

Open
opened 2026-02-16 17:28:02 -05:00 by yindo · 9 comments
Owner

Originally created by @makefinks on GitHub (Jul 15, 2025).

Originally assigned to: @thdxr on GitHub.

I'm not aware of existing configuration options to configure a specific provider when using OpenRouter.

I think implementing a provider selector (similar to the model selector) would be a good QoL improvement (especially now to avoid low throughput kimi k2 providers)

The provider selector could be opened with a shortcut when an OpenRouter model is currently selected.

I don't know how much implementation effort this would result in, but I think it is manageable and doable through existing OpenRouter API endpoints:

https://openrouter.ai/docs/features/provider-routing
https://openrouter.ai/docs/api-reference/list-available-providers

Originally created by @makefinks on GitHub (Jul 15, 2025). Originally assigned to: @thdxr on GitHub. I'm not aware of existing configuration options to configure a specific provider when using OpenRouter. I think implementing a provider selector (similar to the model selector) would be a good QoL improvement (especially now to avoid low throughput kimi k2 providers) The provider selector could be opened with a shortcut when an OpenRouter model is currently selected. I don't know how much implementation effort this would result in, but I think it is manageable and doable through existing OpenRouter API endpoints: https://openrouter.ai/docs/features/provider-routing https://openrouter.ai/docs/api-reference/list-available-providers
Author
Owner

@OneAbodFTW commented on GitHub (Jul 15, 2025):

I could work on this

@OneAbodFTW commented on GitHub (Jul 15, 2025): I could work on this
Author
Owner

@nathabonfim59 commented on GitHub (Jul 16, 2025):

I was able to make it work, thanks to this issue:

In order, you can put whatever provider is available in the model page. You can use options from provider options as well.

{
    "$schema": "https://opencode.ai/config.json",
    "provider": {
        "openrouter": {
            "options": {
                "name": "OpenRouter"
            },
            "models": {
                "moonshotai/kimi-k2": {
                    "name": "KIMI K2",
                    "options": {
                        "OpenRouter": {
                            "provider": {
                                "order": [
                                    "together/fp8",
                                    "baseten/fp4",
                                    "groq"
                                ],
                                "allow_fallbacks": false
                            }
                        }
                    }
                }
            }
        }
    }
}

@nathabonfim59 commented on GitHub (Jul 16, 2025): I was able to make it work, thanks to [this issue](https://github.com/sst/opencode/issues/971): In order, you can put whatever provider is available in the model page. You can use options from [provider options](https://openrouter.ai/docs/features/provider-routing) as well. ```json { "$schema": "https://opencode.ai/config.json", "provider": { "openrouter": { "options": { "name": "OpenRouter" }, "models": { "moonshotai/kimi-k2": { "name": "KIMI K2", "options": { "OpenRouter": { "provider": { "order": [ "together/fp8", "baseten/fp4", "groq" ], "allow_fallbacks": false } } } } } } } } ```
Author
Owner

@Flexinos commented on GitHub (Jul 20, 2025):

I was able to make it work, thanks to this issue:

In order, you can put whatever provider is available in the model page. You can use options from provider options as well.

{
"$schema": "https://opencode.ai/config.json",
"provider": {
"openrouter": {
"options": {
"name": "OpenRouter"
},
"models": {
"moonshotai/kimi-k2": {
"name": "KIMI K2",
"options": {
"OpenRouter": {
"provider": {
"order": [
"together/fp8",
"baseten/fp4",
"groq"
],
"allow_fallbacks": false
}
}
}
}
}
}
}
}

If i only leave "groq" as an option I get:
AI_APICallError: No endpoints found for moonshotat/kimi-k2

Which doesn't really make sense. In the OpenRouter activity logs I can see that the request arrived, but ended with reason "stop"

@Flexinos commented on GitHub (Jul 20, 2025): > I was able to make it work, thanks to [this issue](https://github.com/sst/opencode/issues/971): > > In order, you can put whatever provider is available in the model page. You can use options from [provider options](https://openrouter.ai/docs/features/provider-routing) as well. > > { > "$schema": "https://opencode.ai/config.json", > "provider": { > "openrouter": { > "options": { > "name": "OpenRouter" > }, > "models": { > "moonshotai/kimi-k2": { > "name": "KIMI K2", > "options": { > "OpenRouter": { > "provider": { > "order": [ > "together/fp8", > "baseten/fp4", > "groq" > ], > "allow_fallbacks": false > } > } > } > } > } > } > } > } If i only leave "groq" as an option I get: AI_APICallError: No endpoints found for moonshotat/kimi-k2 Which doesn't really make sense. In the OpenRouter activity logs I can see that the request arrived, but ended with reason "stop"
Author
Owner

@ivanbokii commented on GitHub (Jul 30, 2025):

Not sure what I'm doing wrong, but I can see that OpenRouter delegates execution to various providers despite explicitly instructed to use cerebras:

"openrouter": {
      "options": {
        "name": "OpenRouter"
      },
      "models": {
        "qwen/qwen3-235b-a22b-2507": {
          "name": "Custom-Q3-235b-cerebras",
          "options": {
            "OpenRouter": {
              "provider": {
                "order": [
                  "cerebras"
                ],
                "allow_fallbacks": false
              }
            }
          }
        }
      }

I suspect that params weren't actually passed to OpenRouter.

@ivanbokii commented on GitHub (Jul 30, 2025): Not sure what I'm doing wrong, but I can see that OpenRouter delegates execution to various providers despite explicitly instructed to use cerebras: ```json "openrouter": { "options": { "name": "OpenRouter" }, "models": { "qwen/qwen3-235b-a22b-2507": { "name": "Custom-Q3-235b-cerebras", "options": { "OpenRouter": { "provider": { "order": [ "cerebras" ], "allow_fallbacks": false } } } } } ``` I suspect that params weren't actually passed to OpenRouter.
Author
Owner

@grota commented on GitHub (Aug 1, 2025):

can confirm that with this config (limiting kimi-k2 to only groq) it does not work, while changing only groq -> baseten makes it work 🤷🏼‍♂️ :

{
  "$schema": "https://opencode.ai/config.json",
  "theme": "system",
  "model": "openrouter/moonshotai/kimi-k2",
  "autoshare": false,
  "autoupdate": false,
  "provider": {
    "openrouter": {
      "models": {
        "moonshotai/kimi-k2": {
          "options": {
            "provider": {
              "order": ["groq"],
              "allow_fallbacks": false
            }
          }
        }
      }
    }
  }
}

Here's the (trimmed and beautified) log:

ERROR 2025-08-01T16:16:13 +2ms service=session session=ses_799949420ffe4tW09KIBYWH16D error={
  "name": "AI_APICallError",
  "url": "https://openrouter.ai/api/v1/chat/completions",
  "requestBodyValues": {
    "model": "moonshotai/kimi-k2",
    "max_tokens": 32000,
    "temperature": 0,
    "provider": {
      "order": [
        "groq"
      ],
      "allow_fallbacks": false
    },
    "messages": [
      {
        "role": "system",
        "content": "You are opencode, an interactive CLI tool that ..."
      },
      {
        "role": "system",
        "content": "Here is some useful information about the environment you are running in: ..."
      },
      {
        "role": "user",
        "content": "hello"
      }
    ],
    "tools": [...],
    "tool_choice": "auto",
    "stream": true
  },
  "statusCode": 404,
  "responseHeaders": {
    "access-control-allow-origin": "*",
    "cf-ray": "9686a3812c9dc902-MAD",
    "connection": "keep-alive",
    "content-encoding": "gzip",
    "content-type": "application/json",
    "date": "Fri, 01 Aug 2025 16:16:13 GMT",
    "permissions-policy": "payment=(self \"https://checkout.stripe.com\" \"https://connect-js.stripe.com\" \"https://js.stripe.com\" \"https://*.js.stripe.com\" \"https://hooks.stripe.com\")",
    "referrer-policy": "no-referrer, strict-origin-when-cross-origin",
    "server": "cloudflare",
    "transfer-encoding": "chunked",
    "vary": "Accept-Encoding",
    "x-content-type-options": "nosniff"
  },
  "responseBody": "{\"error\":{\"message\":\"No endpoints found for moonshotai/kimi-k2.\",\"code\":404},\"user_id\":\"user_2t4PFDTP6kRNNXK1o4sIcg4b8Ib\"}",
  "isRetryable": false,
  "data": {
    "error": {
      "message": "No endpoints found for moonshotai/kimi-k2.",
      "code": 404
    }
  }
}
@grota commented on GitHub (Aug 1, 2025): can confirm that with this config (limiting kimi-k2 to only groq) it does not work, while changing only `groq -> baseten` makes it work 🤷🏼‍♂️ : ``` { "$schema": "https://opencode.ai/config.json", "theme": "system", "model": "openrouter/moonshotai/kimi-k2", "autoshare": false, "autoupdate": false, "provider": { "openrouter": { "models": { "moonshotai/kimi-k2": { "options": { "provider": { "order": ["groq"], "allow_fallbacks": false } } } } } } } ``` Here's the (trimmed and beautified) log: ``` ERROR 2025-08-01T16:16:13 +2ms service=session session=ses_799949420ffe4tW09KIBYWH16D error={ "name": "AI_APICallError", "url": "https://openrouter.ai/api/v1/chat/completions", "requestBodyValues": { "model": "moonshotai/kimi-k2", "max_tokens": 32000, "temperature": 0, "provider": { "order": [ "groq" ], "allow_fallbacks": false }, "messages": [ { "role": "system", "content": "You are opencode, an interactive CLI tool that ..." }, { "role": "system", "content": "Here is some useful information about the environment you are running in: ..." }, { "role": "user", "content": "hello" } ], "tools": [...], "tool_choice": "auto", "stream": true }, "statusCode": 404, "responseHeaders": { "access-control-allow-origin": "*", "cf-ray": "9686a3812c9dc902-MAD", "connection": "keep-alive", "content-encoding": "gzip", "content-type": "application/json", "date": "Fri, 01 Aug 2025 16:16:13 GMT", "permissions-policy": "payment=(self \"https://checkout.stripe.com\" \"https://connect-js.stripe.com\" \"https://js.stripe.com\" \"https://*.js.stripe.com\" \"https://hooks.stripe.com\")", "referrer-policy": "no-referrer, strict-origin-when-cross-origin", "server": "cloudflare", "transfer-encoding": "chunked", "vary": "Accept-Encoding", "x-content-type-options": "nosniff" }, "responseBody": "{\"error\":{\"message\":\"No endpoints found for moonshotai/kimi-k2.\",\"code\":404},\"user_id\":\"user_2t4PFDTP6kRNNXK1o4sIcg4b8Ib\"}", "isRetryable": false, "data": { "error": { "message": "No endpoints found for moonshotai/kimi-k2.", "code": 404 } } } ```
Author
Owner

@Arbyy commented on GitHub (Aug 2, 2025):

I've gotten it working for kimi k2 with groq:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "openrouter": {
        "moonshotai/kimi-k2": {
          "options": {
            "provider": {
              "only": ["groq"]
            },
            "max_tokens": 16384
          }
        }
      }
    }
  }
}

I found using only yielded better error messages (docs: https://openrouter.ai/docs/features/provider-routing#allowing-only-specific-providers), and it said "No allowed providers are available for the selected model". I then noticed in the error log given above that the max tokens were specified in the request, I checked models.dev and kimi k2 on openrouter has an output limit of 32,768 but groq only has 16384, so on a whim I changed it and it now works.

Additionally, I used the only param to try and force cerebras with Qwen3 Coder, but I got an error message about how it doesn't support tool calls (which tracks because the OR listing for cerebras Qwen3 Coder does not list tools as a support parameter).

@Arbyy commented on GitHub (Aug 2, 2025): I've gotten it working for kimi k2 with groq: ```json { "$schema": "https://opencode.ai/config.json", "provider": { "openrouter": { "moonshotai/kimi-k2": { "options": { "provider": { "only": ["groq"] }, "max_tokens": 16384 } } } } } } ``` I found using `only` yielded better error messages (docs: https://openrouter.ai/docs/features/provider-routing#allowing-only-specific-providers), and it said "No allowed providers are available for the selected model". I then noticed in the error log given above that the max tokens were specified in the request, I checked models.dev and kimi k2 on openrouter has an output limit of `32,768` but groq only has `16384`, so on a whim I changed it and it now works. Additionally, I used the `only` param to try and force cerebras with Qwen3 Coder, but I got an error message about how it doesn't support tool calls (which tracks because the OR listing for cerebras Qwen3 Coder does not list tools as a support parameter).
Author
Owner

@khalido commented on GitHub (Aug 14, 2025):

In case this helps anyone - I found

  1. using :nitro shortcut in front of the model name doesn't work
  2. The max_tokens has to be <= to the max output tokens for that provider/model else it would refuse to run.

The below config worked for me, which I verified by looking at openrouter activity to see it actually used these providers.

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "openrouter": {
      "models": {
        "qwen/qwen3-coder": {
          "name": "fast qwen3-coder",
          "options": {
            "provider": {
              "only": ["cerebras"]
            },
            "max_tokens": 32000
          }
        },
        "moonshotai/kimi-k2": {
          "name": "fast kimi k2",
          "options": {
            "provider": {
              "only": ["groq"]
            },
            "max_tokens": 16000
          }
        }
      }
    }
  }
}

Note: cerebras is not a reliable provider on openrouter - I found the speed greatly varies. groq is more consistently fast.

Looking at https://models.dev/?search=kimi-k2 - it lists providers, but when using a meta provider like openrouter there is no way to define the actual provider there.

@khalido commented on GitHub (Aug 14, 2025): In case this helps anyone - I found 1. using [:nitro shortcut](https://openrouter.ai/docs/features/provider-routing#nitro-shortcut) in front of the model name doesn't work 2. The max_tokens has to be <= to the max output tokens for that provider/model else it would refuse to run. The below config worked for me, which I verified by looking at openrouter activity to see it actually used these providers. ```json { "$schema": "https://opencode.ai/config.json", "provider": { "openrouter": { "models": { "qwen/qwen3-coder": { "name": "fast qwen3-coder", "options": { "provider": { "only": ["cerebras"] }, "max_tokens": 32000 } }, "moonshotai/kimi-k2": { "name": "fast kimi k2", "options": { "provider": { "only": ["groq"] }, "max_tokens": 16000 } } } } } } ``` Note: [cerebras](https://openrouter.ai/provider/cerebras) is not a reliable provider on openrouter - I found the speed greatly varies. [groq](https://openrouter.ai/provider/groq) is more consistently fast. Looking at https://models.dev/?search=kimi-k2 - it lists providers, but when using a meta provider like openrouter there is no way to define the actual provider there.
Author
Owner

@OneAbodFTW commented on GitHub (Oct 30, 2025):

Thanks to @Arbyy at least it showed me an error message, instead of just nothing.

If someone still faces the same issue of empty responses even with Arbby config, try to use the full model's id like this "moonshotai/kimi-k2-0905" instead.

@OneAbodFTW commented on GitHub (Oct 30, 2025): Thanks to @Arbyy at least it showed me an error message, instead of just nothing. If someone still faces the same issue of empty responses even with Arbby config, try to use the full model's id like this "moonshotai/kimi-k2-0905" instead.
Author
Owner

@niebloomj commented on GitHub (Feb 15, 2026):

Is this issue related to why I don't see openrouter/auto in the list of models?

@niebloomj commented on GitHub (Feb 15, 2026): Is this issue related to why I don't see openrouter/auto in the list of models?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#724