How to scale AI cost-effectively with serverless functions