rotate_api_key
Generate a new API key and invalidate the old one to enhance security. Triggers a withdrawal cooldown period: 60 minutes for operators, 30 minutes for agents.
Instructions
Generate a new API key, invalidating the old one. For operators: triggers 60-min withdrawal cooldown. For agents: 30-min cooldown.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agent_id | No | Agent ID (operators only). Omit to rotate operator key. |
Implementation Reference
- src/lightning-faucet.ts:832-857 (handler)The implementation of the rotateApiKey method in the LightningFaucetClient class.
* Rotate API key (operator or agent) */ async rotateApiKey(agentId?: number): Promise<{ apiKey: string; message: string; cooldownUntil?: string; rawResponse: ApiResponse; }> { const action = agentId ? 'regenerate_agent_key' : 'regenerate_operator_key'; const data: Record<string, unknown> = {}; if (agentId) data.agent_id = agentId; const result = await this.request<ApiResponse & { api_key?: string; new_api_key?: string; message?: string; cooldown_until?: string; }>(action, data); return { apiKey: result.api_key || result.new_api_key || '', message: result.message || 'API key rotated', cooldownUntil: result.cooldown_until, rawResponse: result, }; } - src/index.ts:201-203 (registration)Zod schema definition for rotate_api_key tool arguments.
const RotateApiKeySchema = z.object({ agent_id: z.number().int().positive().optional().describe('Agent ID (operators only). If omitted, rotates operator key.'), }); - src/index.ts:1332-1350 (handler)Request handler for the rotate_api_key tool.
case 'rotate_api_key': { const parsed = RotateApiKeySchema.parse(args); const result = await session.requireClient().rotateApiKey(parsed.agent_id); // Auto-switch to the new key session.setClient(new LightningFaucetClient(result.apiKey)); return { content: [ { type: 'text', text: JSON.stringify({ success: true, message: result.message || 'API key rotated. New key is now active.', new_api_key: result.apiKey, cooldown_until: result.cooldownUntil, }, null, 2), }, ], }; }