Skip to main content
Glama
openrouter.js1.17 kB
/** * openrouter.js * AI provider implementation for OpenRouter models using Vercel AI SDK. */ import { createOpenRouter } from '@openrouter/ai-sdk-provider'; import { BaseAIProvider } from './base-provider.js'; export class OpenRouterAIProvider extends BaseAIProvider { constructor() { super(); this.name = 'OpenRouter'; } /** * Returns the environment variable name required for this provider's API key. * @returns {string} The environment variable name for the OpenRouter API key */ getRequiredApiKeyName() { return 'OPENROUTER_API_KEY'; } /** * Creates and returns an OpenRouter client instance. * @param {object} params - Parameters for client initialization * @param {string} params.apiKey - OpenRouter API key * @param {string} [params.baseURL] - Optional custom API endpoint * @returns {Function} OpenRouter client function * @throws {Error} If API key is missing or initialization fails */ getClient(params) { try { const { apiKey, baseURL } = params; return createOpenRouter({ apiKey, ...(baseURL && { baseURL }) }); } catch (error) { this.handleError('client initialization', error); } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/eyaltoledano/claude-task-master'

If you have feedback or need assistance with the MCP directory API, please join our Discord server