import { anthropicMessagesApi } from "../api/anthropic-messages.lazy.ts"; import { openAICompletionsApi } from "../api/openai-completions.lazy.ts"; import { envApiKeyAuth, lazyOAuth } from "../auth/helpers.ts"; import { loadOpenRouterOAuth } from "../auth/oauth/load.ts"; import { createProvider, type Provider } from "../models.ts"; import { OPENROUTER_MODELS } from "./openrouter.models.ts"; export function openrouterProvider(): Provider<"anthropic-messages" | "openai-completions"> { return createProvider({ id: "openrouter", name: "OpenRouter", baseUrl: "https://openrouter.ai/api/v1", auth: { apiKey: envApiKeyAuth("OpenRouter API key", ["OPENROUTER_API_KEY"]), oauth: lazyOAuth({ name: "OpenRouter OAuth", loginLabel: "Sign in with OpenRouter", load: loadOpenRouterOAuth, }), }, models: Object.values(OPENROUTER_MODELS), api: { "anthropic-messages": anthropicMessagesApi(), "openai-completions": openAICompletionsApi(), }, }); }