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
| Name | Required | Description | Default |
|---|---|---|---|
| apiKey | Yes | Your OpenRouter API key from https://openrouter.ai/settings/keys |
Implementation Reference
- src/index.ts:208-237 (handler)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"], }, },
- src/index.ts:24-26 (schema)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);