Whether you're a casual investor or trade professionally, chances are you've heard about the current boom in artificial intelligence (AI). After last year's economic downturn caused many tech stocks to fall out of favor, recent advances in AI have bolstered numerous companies across the industry and kicked off a recovery in the market.

Tech behemoths Amazon (AMZN 0.80%) and Microsoft (MSFT -0.39%), for instance, suffered double-digit stock declines in 2022 yet have seen their shares rise 51% and 38% since Jan. 1, primarily driven by the companies' prospects in AI.

As the biggest and second-biggest cloud companies in the world, respectively, Amazon and Microsoft will likely play a crucial role in delivering AI services to businesses around the globe. Amazon is home to Amazon Web Services (AWS), which boasts a leading cloud market share and brought in $80 billion in revenue last year. Meanwhile, Microsoft's Azure is the second-largest cloud platform and was close behind AWS in 2022, earning $75 billion.

These companies are closely matched in the cloud industry, making them fierce competitors in AI. Let's take a closer look at whether Amazon or Microsoft is the better AI stock. 

Amazon

Amazon started the year at a disadvantage, with macroeconomic headwinds in 2022 leading to substantial declines in its e-commerce segments and pullback from cloud clients hurt by rising interest rates. However, the company's business proved its resilience, reporting revenue growth of 9% in its fiscal year and having the resources to heavily invest the quickly expanding AI market

The retail giant has spent the first six months of 2023 pivoting different parts of its business to AI as it works to keep its lucrative lead in cloud computing and outperform competitors like Microsoft and Alphabet. Amazon has so far taken steps to become the go-to for companies seeking generative AI tools that serve different purposes to OpenAI's ChatGPT.

For instance, the company recently added the service Amazon Bedrock to AWS. The new tool allows companies to create their own chatbots and image-generation services. Additionally, the company launched CodeWhisperer, a service that helps developers by generating codes to make software production more efficient. 

Moreover, Amazon is setting itself apart from the competition by expanding into the hardware side of AI. The company is developing AI-specific chips, which it says will offer the best price to performance in the industry. If the company's chips truly provide competitive pricing, it could strengthen its position in AI by producing software and hardware. 

Microsoft

The launch of ChatGPT last November spotlighted the advanced technology of its developer OpenAI. However, it also bolstered Microsoft's position in AI, with its role as the start-up's biggest investor. The partnership led Microsoft to secure exclusive licenses on several of OpenAI's artificial intelligence models and bring AI upgrades to several of its homegrown platforms. Word, Excel, Bing, and Azure are all offering different AI services as the company seeks to become one of the biggest names in the industry. 

Like Amazon, Microsoft is getting into the AI chip game. However, instead of producing chips itself, it is heavily investing in Advanced Micro Devices' AI chip expansion, providing financial and engineering resources. Microsoft aims to reduce the cost of AI hardware by creating an alternative to Nvidia, which currently holds an 80% to 95% market share in the sector's chips.

Microsoft's foresight to invest in OpenAI in 2019 has potentially been one of the best decisions in its nearly 50-year history. It has given the company a leading role in a booming market and the technology to expand further. In fact, Morgan Stanley analyst Keith Weiss believes Microsoft is best-positioned to profit from AI growth and has given the company a price target of $415, which would push its market cap above $3 trillion.

Considering that growth is only about 25% above its current position, it's not out of the realm of possibility the company's stock will hit that price over the next year. 

Is Amazon or Microsoft the better stock to invest in AI?

Amazon and Microsoft are pretty evenly matched in the AI market, with both likely to profit significantly from the industry's growth. However, last year's economic challenges hit Amazon's business harder, making its stock more expensive than Microsoft's. 

AMZN PE Ratio (Forward) Chart

Data by YCharts

The chart above shows that Microsoft's forward price-to-earnings (P/E) ratio of 30 is substantially lower than Amazon's, indicating Microsoft's stock is trading at a far better value. 

Additionally, Microsoft's stock has risen 225% over the last five years, while Amazon's has increased by 46%. As a result, Microsoft seems to be the more reliable stock and a better way to back the quickly expanding AI market.