The artificial intelligence (AI) market has turned many heads in recent months after the launch of OpenAI's ChatGPT last November. The advanced chatbot's ability to produce human-like dialogue captivated tech enthusiasts and prompted countless companies to pivot their businesses to AI development. 

Companies like Nvidia (NVDA -1.54%) and Microsoft (MSFT -3.21%) have enjoyed monster stock growth this year thanks to their prospects in AI. These tech giants are attractive investments as they were both early to the AI party, with one responsible for the hardware running ChatGPT and the other being the biggest investor in OpenAI. 

As a result, it's not a bad idea to consider investing in Nvidia and Microsoft before their stocks fly any higher. However, if you only have room for one more stock in your portfolio, you'll need to know the better buy. So, let's take a closer look at both companies. 

Nvidia: A favorite among AI investors

Nvidia shares skyrocketed 189% since Jan. 1, with Wall Street impressed by the company's ability to outperform competitors like Advanced Micro Devices and Intel in AI chips. The company is undoubtedly a favorite among investors, with the chart below showing that Nvidia's stock has delivered more than double the year-to-date growth of almost any AI stock

NVDA Chart

Data by YCharts

One of Nvidia's biggest selling points is its role as the primary supplier of graphics processing units (GPUs) to ChatGPT. According to data from TrendForce, ChatGPT utilized about 20,000 GPUs in 2020, with that figure projected to hit 30,000 as the platform commercially expands. Meanwhile, Nvidia is already profiting from the platform's growth, reporting a 41% year-over-year rise in revenue in its AI-focused data center segment in fiscal 2022.

Nvidia's data center segment is now the highest-earning part of its business as it delves deeper into the high-growth industry. As the market expands, Nvidia's ability to supply its chips to any company strengthens its outlook. If the amount of chips required by ChatGPT is anything to go by, Nvidia could have an immensely lucrative future as more companies join the sector.

Microsoft: The king of software

While Nvidia is leading the way in hardware, Microsoft is making promising inroads in AI software. The company had the impressive foresight to invest $1 billion in OpenAI in 2019, which led it to procure exclusive licenses on multiple AI models.

The partnership allows Microsoft to integrate OpenAI's technology across its services, including its Office productivity software and cloud platform, Azure. 

As the adoption of AI soars among consumers and businesses, Microsoft is well positioned to become the go-to in AI services. The company's potent brands like Windows, Office, and Azure mean most consumers already utilize Microsoft products in their workflow. Consequently, it won't be a stretch for many of these users to adopt the company's growing AI offerings. 

Moreover, Microsoft's Azure holds the second-largest market share in cloud computing at 23%, only after Amazon Web Services' (AWS) 32%. With the power of OpenAI behind it, Microsoft is currently ahead of AWS in AI cloud services. If the company can keep its lead, it could eventually overtake the competition in the lucrative industry. 

Is Nvidia or Microsoft the better buy?

Nvidia and Microsoft have promising outlooks in different aspects of AI, making them both compelling options to invest in a market projected to expand at a compound annual growth rate of 37% through 2030. To determine the better buy, it's smart to look at which is trading at a better value and which has delivered better profits over the last few years. 

Price-to-earnings (P/E) ratio is a helpful metric to determine value. Microsoft's P/E of 36 is vastly lower than Nvidia's 220, suggesting that the Windows company is by far the better value.

MSFT Operating Income (Annual) Chart

Data by YCharts

Additionally, the chart above illustrates how Microsoft's annual profits have seen nearly triple the growth of Nvidia's over the last five years. The figures indicate that Microsoft is a more reliable buy, with its more established businesses offering consistent financial growth. In addition to being a cheaper stock, Microsoft is the better buy right now and an excellent way to invest in AI.