Wall Street expects strong earnings to drive the stock market higher. The S&P 500 carries a consensus price target of 5,038, implying a 14% upside over the next year. That bottom-up forecast combines the median price target on every stock in the index, blending more than 11,000 individual ratings, according to FactSet.

Any upward momentum in the market could be especially pronounced in artificial intelligence (AI) stocks given the enthusiasm inspired by the technology. But investors need to pick and choose carefully. For instance, Amazon (AMZN 3.43%) and Palantir Technologies (PLTR 3.73%) are recognized leaders in certain portions of the AI value chain, but Wall Street views the companies very differently.

Amazon has a median 12-month price target of $175 per share, implying a 22% upside from its current price. But Palantir has a median 12-month price target of $16 per share, implying a 19% downside from its current price.

Read on to learn more about these AI growth stocks and discover why one is a buy and the other is best avoided right now.

A stock to buy: Amazon

Amazon has been developing its artificial intelligence (AI) capabilities for over two decades, and its strong presence in three large and growing markets -- e-commerce, digital advertising, and cloud computing -- creates a plethora of monetization opportunities. For that reason, analysts at Morgan Stanley see Amazon as one of a handful of companies best positioned to benefit from AI-driven transformation.

E-commerce: Amazon operates the most-visited online marketplace in the world, and it is expected to account for nearly 39% of online retail sales in North America and Western Europe this year. The company uses AI to help shoppers find products on its marketplace, but it also uses AI behind the scenes to improve inventory management and optimize robotic picking routes in fulfillment centers.

Digital advertising: Amazon accounts for three-quarters of all retail ad spend in the U.S., and it recently took the title of third-largest ad tech company in the world from Alibaba. Amazon recently debuted an AI-enabled image generation tool that simplifies the creation of marketing content. More broadly, success in retail means the company is uniquely positioned to provide marketers with shopper data to inform AI models and target ad content.

Cloud computing: Amazon Web Services (AWS) dominates the market for cloud infrastructure and platform services, and was recently recognized as a leader in cloud AI developer services. The company is leaning into that advantage with two new products: Bedrock helps businesses build generative AI applications, and CodeWhisperer is an AI-enabled coding companion that accelerates software development.

Going forward, online retail sales are projected to increase at 9% annually through 2028, while the ad tech and cloud computing markets are forecasted to expand at 14% annually through 2030. Those tailwinds should translate into low-double-digit revenue growth for Amazon over the next five-plus years.

In that context, its current valuation of 2.7 times sales looks reasonable, especially when the five-year average is 3.4 times sales. That's why this AI stock is worth buying.

A stock to avoid: Palantir Technologies

Palantir helps clients make sense of complex data with two primary software platforms: Gotham was initially designed for government agencies, and Foundry was made for commercial businesses, though there is some overlap now. Both platforms are essentially operating systems that integrate, analyze, visualize, and connect data to workflows via applications that inform decision making.

Palantir supports the development and optimization of simple analytical models, as well as more sophisticated AI models. Earlier this year, Dresner Advisory Services recognized the company as a leader in ModelOps, a discipline concerned with managing the AI model lifecycle. Dresner also recognized Palantir as a leader among AI, data science, and machine learning platform vendors.

Palantir delivered a solid financial report in the third quarter, topping consensus estimates. Its customer count climbed 34% to 453, revenue increased 17% to $558 million, and the company generated GAAP net income of $72 million, up from a loss of $124 million in the prior year. Investors have good reason to expect similar momentum in the future.

The big data software market is forecasted to compound at 12% annually to reach $333 billion by 2027, but Palantir should outpace the broader industry given its strong presence among ModelOps and AI platform vendors. Indeed, Morgan Stanley expects revenue growth of 20% annually over the next five years.

Even so, I am skeptical as to whether Palantir can deliver market-beating returns from its current valuation. The stock trades at 20.6 times sales, a substantial premium to the two-year average of 13.4 times sales, and the company earns revenue in a highly concentrated fashion (due to its low customer count), which could become a problem if customers start leaving. To that end, I plan to avoid Palantir stock for now.

However, investors should keep this company on their watchlists. Wall Street may be bearish on the whole, but some strategists are quite bullish. For instance, Dan Ives of Wedbush Securities recently called Palantir "the gold standard in AI." With praise like that, Palantir warrants further consideration.