Skip to main content
Glama

configure_openrouter_token

Set up your OpenRouter API key to enable image generation and editing capabilities using the Gemini 2.5 Flash Image model.

Instructions

Configure your OpenRouter API token for image generation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apiKeyYesYour OpenRouter API key from https://openrouter.ai/settings/keys

Implementation Reference

  • The primary handler function that extracts the API key from the tool request, validates it using ConfigSchema, sets up the OpenAI client configured for OpenRouter, updates the config source, saves the configuration to a file, and returns a success response with text content.
    private async configureOpenRouterToken(request: CallToolRequest): Promise<CallToolResult> { const { apiKey } = request.params.arguments as { apiKey: string }; try { ConfigSchema.parse({ openrouterApiKey: apiKey }); this.config = { openrouterApiKey: apiKey }; this.openai = new OpenAI({ apiKey, baseURL: "https://openrouter.ai/api/v1", }); this.configSource = 'config_file'; // Manual configuration via tool await this.saveConfig(); return { content: [ { type: "text", text: "✅ OpenRouter API token configured successfully! You can now use OpenRouter image generation features.", }, ], }; } catch (error) { if (error instanceof z.ZodError) { throw new McpError(ErrorCode.InvalidParams, `Invalid API key: ${error.errors[0]?.message}`); } throw error; } }
  • src/index.ts:64-77 (registration)
    Tool registration in the listTools response, defining the name, description, and input schema requiring an 'apiKey' string.
    { name: "configure_openrouter_token", description: "Configure your OpenRouter API token for image generation", inputSchema: { type: "object", properties: { apiKey: { type: "string", description: "Your OpenRouter API key from https://openrouter.ai/settings/keys", }, }, required: ["apiKey"], }, },
  • Zod schema for validating the OpenRouter API key, used internally in the handler for additional validation.
    const ConfigSchema = z.object({ openrouterApiKey: z.string().min(1, "OpenRouter API key is required"), });
  • src/index.ts:178-180 (registration)
    Switch case in the CallToolRequest handler that dispatches to the configureOpenRouterToken method.
    case "configure_openrouter_token": return await this.configureOpenRouterToken(request);

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/WeiYu021/openrouter-image-MCP'

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