Improve API key length check