update_api_key
Modify an existing API key's name, description, scopes, credit limit, rate limit, defaults, or expiration. Changes apply immediately without revoking the key.
Instructions
Update an API key's name, description, scopes, defaults, or limits, unlike delete_api_key which revokes it or create_api_key which issues a new one. Changes take effect immediately for downstream callers, type and sub-type stay fixed after creation, and the call returns success without rotating the secret.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The UUID of the API key to update | |
| name | No | New display name for the key | |
| description | No | New description for the key | |
| scopes | No | New permission scopes for the key | |
| credit_limit | No | New credit limit for usage | |
| alert_threshold | No | New alert threshold percentage (0-100) | |
| rate_limit_rpm | No | New rate limit in requests per minute | |
| default_config_id | No | New default configuration ID | |
| default_metadata | No | New default metadata key-value pairs | |
| alert_emails | No | New email addresses for alerts | |
| expires_at | No | New expiration date in ISO 8601 format, or null to remove expiration |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | Whether the tool call succeeded and returned structured data | |
| data | No | Structured success payload when ok is true | |
| error | No | Structured error payload when ok is false |
Implementation Reference
- src/tools/keys.tools.ts:598-641 (handler)Tool handler for 'update_api_key' — MCP tool registration and callback that accepts params, calls the service layer, and returns success response.
// Phase 2: Update API key tool server.tool( "update_api_key", "Update an API key's name, description, scopes, defaults, or limits, unlike delete_api_key which revokes it or create_api_key which issues a new one. Changes take effect immediately for downstream callers, type and sub-type stay fixed after creation, and the call returns success without rotating the secret.", KEYS_TOOL_SCHEMAS.updateApiKey, async (params) => { const result = await service.keys.updateApiKey(params.id, { name: params.name, description: params.description, scopes: params.scopes, usage_limits: buildUsageLimits({ credit_limit: params.credit_limit, alert_threshold: params.alert_threshold, }), rate_limits: buildRateLimitsRpm(params.rate_limit_rpm), defaults: params.default_config_id !== undefined || params.default_metadata !== undefined ? { config_id: params.default_config_id, metadata: params.default_metadata, } : undefined, alert_emails: params.alert_emails, expires_at: params.expires_at, }); return { content: [ { type: "text", text: JSON.stringify( { message: `Successfully updated API key "${params.id}"`, success: result.success, }, null, 2, ), }, ], }; }, ); - src/tools/keys.tools.ts:164-207 (schema)Input schema (Zod) for the update_api_key tool — defines all optional fields: id, name, description, scopes, credit_limit, alert_threshold, rate_limit_rpm, default_config_id, default_metadata, alert_emails, expires_at.
updateApiKey: { id: z.string().uuid().describe("The UUID of the API key to update"), name: z.string().optional().describe("New display name for the key"), description: z.string().optional().describe("New description for the key"), scopes: z .array(z.string()) .optional() .describe("New permission scopes for the key"), credit_limit: z.coerce .number() .positive() .optional() .describe("New credit limit for usage"), alert_threshold: z.coerce .number() .min(0) .max(100) .optional() .describe("New alert threshold percentage (0-100)"), rate_limit_rpm: z.coerce .number() .positive() .optional() .describe("New rate limit in requests per minute"), default_config_id: z .string() .optional() .describe("New default configuration ID"), default_metadata: z .record(z.string(), z.string()) .optional() .describe("New default metadata key-value pairs"), alert_emails: z .array(z.string()) .optional() .describe("New email addresses for alerts"), expires_at: z .string() .nullable() .optional() .describe( "New expiration date in ISO 8601 format, or null to remove expiration", ), }, - src/tools/keys.tools.ts:598-641 (registration)Registration of the 'update_api_key' tool via server.tool() — the same block that registers the handler also registers the tool name and schema.
// Phase 2: Update API key tool server.tool( "update_api_key", "Update an API key's name, description, scopes, defaults, or limits, unlike delete_api_key which revokes it or create_api_key which issues a new one. Changes take effect immediately for downstream callers, type and sub-type stay fixed after creation, and the call returns success without rotating the secret.", KEYS_TOOL_SCHEMAS.updateApiKey, async (params) => { const result = await service.keys.updateApiKey(params.id, { name: params.name, description: params.description, scopes: params.scopes, usage_limits: buildUsageLimits({ credit_limit: params.credit_limit, alert_threshold: params.alert_threshold, }), rate_limits: buildRateLimitsRpm(params.rate_limit_rpm), defaults: params.default_config_id !== undefined || params.default_metadata !== undefined ? { config_id: params.default_config_id, metadata: params.default_metadata, } : undefined, alert_emails: params.alert_emails, expires_at: params.expires_at, }); return { content: [ { type: "text", text: JSON.stringify( { message: `Successfully updated API key "${params.id}"`, success: result.success, }, null, 2, ), }, ], }; }, ); - src/services/keys.service.ts:138-147 (schema)TypeScript interface UpdateApiKeyRequest — defines the structured data passed to the service's updateApiKey method.
export interface UpdateApiKeyRequest { name?: string; description?: string; rate_limits?: ApiKeyRateLimit[]; usage_limits?: Partial<ApiKeyUsageLimits>; scopes?: string[]; defaults?: ApiKeyDefaults; alert_emails?: string[]; expires_at?: string | null; } - src/services/keys.service.ts:207-213 (handler)Service-layer method KeysService.updateApiKey — executes PUT /api-keys/{id} with the update data and returns { success: true }.
async updateApiKey( id: string, data: UpdateApiKeyRequest, ): Promise<{ success: boolean }> { await this.put(`/api-keys/${this.encodePathSegment(id)}`, data); return { success: true }; }