Replace Qwen provider with LiteLLM and OpenRouter aggregators

Adding one bespoke provider package per vendor doesn't scale. LiteLLM
proxy and OpenRouter both speak the OpenAI chat-completions wire
format and each front dozens-to-hundreds of underlying models, so
supporting them once gets that whole catalog instead of one more
one-off integration — providers/qwen turns out to have been exactly
that pattern hand-rolled a second time (its own copy of the
OpenAI-compatible translation, just pointed at DashScope's base URL).

providers/litellm and providers/openrouter are both thin constructors
over the OpenAI provider's existing NewOpenAIProviderWithKind(apiKey,
baseURL, "openai-compatible") — no new request/stream-translation code.
OpenRouter defaults to its public endpoint when baseURL is empty;
LiteLLM has none (self-hosted), so callers must supply one.

Context-window detection (tokens.ContextWindow) already keys off the
model ID's family rather than the provider prefix, specifically so a
model exposed under a custom/proxy provider name still gets the right
window — so litellm/openrouter models need zero changes there.
This commit is contained in:
sausheong committed 2026-09-06 16:13:30 +08:00
1 parent 0ba1b4dbcc
commit f624e4c7bd
11 files changed
+143 -431

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
// Package openrouter provides an llm.LLMProvider for OpenRouter, an
// aggregator that fronts hundreds of underlying models behind one
// OpenAI-compatible endpoint. Like providers/litellm, this adds no new
// request/stream-translation code of its own — it's a thin constructor
// around harness's existing OpenAI-compatible support.
package openrouter
import "github.com/sausheong/harness/providers/openai"
// DefaultBaseURL is OpenRouter's public API endpoint, used when
// NewOpenRouterProvider is called with an empty baseURL.
const DefaultBaseURL = "https://openrouter.ai/api/v1"
// NewOpenRouterProvider returns an OpenAI-compatible provider pointed at
// baseURL, or DefaultBaseURL when baseURL is empty. kind="openai-compatible"
// suppresses reasoning_effort, since OpenRouter's underlying models don't
// uniformly support it.
func NewOpenRouterProvider(apiKey, baseURL string) *openai.OpenAIProvider {
if baseURL == "" {
baseURL = DefaultBaseURL
}
return openai.NewOpenAIProviderWithKind(apiKey, baseURL, "openai-compatible")
}