All files / src/providers/openrouter index.ts

91.66% Statements 11/12
66.66% Branches 4/6
100% Functions 2/2
90.9% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37            63x             7x   5x 7x 7x 7x   7x           7x     5x           63x  
import { config as globalConfig } from "../../config.js";
import { providerRegistry } from "../registry.js";
import { OpenRouterProvider } from "./OpenRouterProvider.js";
 
export * from "./OpenRouterProvider.js";
 
let registered = false;
 
/**
 * Idempotent registration of the OpenRouter provider.
 * Automatically called when using createLLM({ provider: 'openrouter' })
 */
export function registerOpenRouterProvider() {
  if (registered) return;
 
  providerRegistry.register("openrouter", (config) => {
    const cfg = config || globalConfig;
    const apiKey = cfg.openrouterApiKey;
    const baseUrl = cfg.openrouterApiBase;
 
    Iif (!apiKey) {
      throw new Error(
        "openrouterApiKey is not set in config or OPENROUTER_API_KEY environment variable"
      );
    }
 
    return new OpenRouterProvider({ apiKey, baseUrl });
  });
 
  registered = true;
}
 
/**
 * Alias for registerOpenRouterProvider for internal use.
 */
export const ensureOpenRouterRegistered = registerOpenRouterProvider;