Artificial intelligence (AI) was a top investing theme in 2023. Many stocks involved with it were hot buys last year. And companies were eager to tell investors and customers how they were incorporating AI into their businesses so that they wouldn't miss out on the hype.

Three AI stocks that did particularly well last year were Nvidia (NVDA 6.18%), C3.ai (AI 3.02%), and Tesla (TSLA -1.11%), all doubling in value in 2023. But the big questions are whether they can do it again, and is it too late to invest in these businesses?

1. Nvidia

Chipmaker Nvidia scored returns of 239% for its shareholders last year, and it joined the $1 trillion club as one of the most valuable companies in the world. Between its data center products and its AI chips, it has multiple ways to benefit from more companies seeking to offer AI products and services.

For the nine-month period ending Oct. 29, the company generated $38.8 billion in sales, an increase of 86% compared to the same period in the previous year. Investors come to expect that kind of growth from up-and-coming mid-cap stocks, not an already-large tech giant like Nvidia.

That's what made the company's performance last year so impressive: the sheer growth that Nvidia's business was able to generate. But what I love best about the business is how profitable it is. On all that revenue, it had a profit of $17.5 billion, for a net margin of 45%.

AI is just picking up speed, and as more companies get onto the cloud and invest in better infrastructure, Nvidia is going to be in prime position to benefit from that. And if it can maintain its incredibly high margins, the sky could be the limit for the stock.

While I don't expect a repeat performance in 2024, Nvidia still looks like an exceptional investment to put into your portfolio for the long haul.

2. C3.ai

The second-best-performing stock on this list last year was C3.ai. At 157%, it had a mammoth gain, and there were many points during the year when it was doing even better than Nvidia.

But I can't help but wonder if part of the reason was simply its ticker symbol: AI. The company does provide AI solutions in many industries, and it all sounds promising, but the results simply weren't there for C3.ai.

In recent quarters, revenue has looked fairly flat; for the period ending Oct. 31, it totaled $73.2 million, which wasn't much of an improvement from the $72.4 million it reported a period earlier. And the company's losses actually increased, with C3.ai incurring a loss of $69.8 million last quarter versus $64.4 million in the previous period.

C3.ai did well last year, but now that the hype has come and gone, I expect the stock to give back some gains in 2024. It was already starting to slide by the summer of 2023 as investors were realizing the company's numbers weren't aligning with all the excitement surrounding the stock. And if the company can't convince investors it can do better, it could be one of the most disappointing AI stocks of 2024.

3. Tesla

Tesla doesn't make AI chips, but it does make electric vehicles (EVs) that it hopes will someday be fully autonomous. It's also in the robot-making business, unveiling its latest humanoid robot last month, the Optimus Gen 2.

Today, however, EVs are still the company's bread and butter. While Tesla is now consistently profitable, it is competing with many other EV makers, and it has been cutting prices to stay competitive, and that has been hurting its margins. Its operating profit for the third quarter (which ended on Sept. 30) was just 7.6% of revenue -- down from 17.2% a year ago.

The economy will have a lot to do with how the stock performs in 2024. If there is a slowdown this year -- which appears likely, and it's just a matter of how hard or soft the landing will be -- it could be more difficult for the business to improve upon its margins, and that might limit the stock's upside.

Shares of Tesla rose by 102% last year, but I wouldn't expect the stock to do nearly as well this year. For growth-oriented investors, it can still be a good long-term investment, but its gains this year could prove to be underwhelming.